package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/camelcase-matching/
 */
public class Problem1023 {
    public List<Boolean> camelMatch(String[] queries, String pattern) {
        List<Boolean> answer = new ArrayList<>();
        for (String query : queries) {
            int i = 0;
            int j = 0;
            boolean found = true;
            if (pattern.charAt(i) != query.charAt(j)) {
                found = false;
            } else {
                while (i < pattern.length() && j < query.length()) {
                    if (Character.isLowerCase(pattern.charAt(i))) {
                        if (pattern.charAt(i) != query.charAt(j)) {
                            found = false;
                            break;
                        }
                    } else { // Character.isUpperCase(pattern.charAt(i))
                        while (j < query.length() && Character.isLowerCase(query.charAt(j))) {
                            j++;
                        }
                        if (j >= query.length() || pattern.charAt(i) != query.charAt(j)) {
                            found = false;
                            break;
                        }
                    }
                    i++;
                    j++;
                }
            }
            while (j < query.length()) {
                if (Character.isUpperCase(query.charAt(j))) {
                    found = false;
                    break;
                }
                j++;
            }
            answer.add(i < pattern.length() ? false : found);
        }
        return answer;
    }

    public static void main(String[] args) {
        Problem1023 prob = new Problem1023();
//        System.out.println(prob.camelMatch(new String[]{"FooBarTest"}, "FB")); // [false]
//        System.out.println(prob.camelMatch(new String[]{"FooBarTest"}, "FBTT")); // [false]
//        System.out.println(prob.camelMatch(new String[]{"FooBarT"}, "FBTT")); // [false]
//        System.out.println(prob.camelMatch(new String[]{"FooBarTTa"}, "FBTTa")); // [true]
//        System.out.println(prob.camelMatch(new String[]{"FBT"}, "FBT")); // [true]
//        System.out.println(prob.camelMatch(new String[]{"FooBarTest"}, "FBT")); // [true]
//        System.out.println(prob.camelMatch(new String[]{
//            "FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, "FB")); // [true,false,true,true,false]
//        System.out.println(prob.camelMatch(new String[]{
//            "FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, "FoBa")); // [true,false,true,false,false]
//        System.out.println(prob.camelMatch(new String[]{
//            "FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, "FoBaT")); // [false,true,false,false,false]
//        System.out.println(prob.camelMatch(new String[]{
//            "CompetitiveProgramming", "CounterPick", "ControlPanel"}, "CooP")); // [false,false,true]
        System.out.println(prob.camelMatch(new String[]{"ControlPanel"}, "CooP")); // [true]
        System.out.println(prob.camelMatch(new String[]{"ConxonpPanel"}, "ConpP")); // [true]
        System.out.println(prob.camelMatch(new String[]{"ControlPanel"}, "CtnP")); // [false]
    }
}

@@ -397,120 +397,8 @@
 ue;%0A
-            if (pattern.charAt(i) != query.charAt(j)) %7B%0A                found = false;%0A            %7D else %7B%0A    
     
@@ -450,36 +450,32 @@
 ery.length()) %7B%0A
-    
                 
@@ -542,24 +542,45 @@
         
-    if (
+while (j %3C query.length() && 
 pattern.
@@ -635,33 +635,19 @@
         
-    found = false
+j++
 ;%0A      
@@ -664,53 +664,10 @@
     
-        break;%0A                        %7D%0A    
+%7D%0A
     
@@ -731,20 +731,16 @@
 rAt(i))%0A
-    
         
@@ -842,37 +842,29 @@
             
-   
- 
 j++;%0A
-    
             
@@ -873,32 +873,42 @@
       %7D%0A        
+        %7D%0A
                 
@@ -990,32 +990,24 @@
             
-        
 found = fals
@@ -1033,53 +1033,15 @@
     
-        break;%0A                        %7D%0A    
+break;%0A
     
@@ -1070,20 +1070,16 @@
         
-    
 i++;%0A   
@@ -1095,34 +1095,12 @@
     
-    j++;%0A                %7D
+j++;
 %0A   
@@ -1432,1650 +1432,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1023 prob = new Problem1023();%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FooBarTest%22%7D, %22FB%22)); // %5Bfalse%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FooBarTest%22%7D, %22FBTT%22)); // %5Bfalse%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FooBarT%22%7D, %22FBTT%22)); // %5Bfalse%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FooBarTTa%22%7D, %22FBTTa%22)); // %5Btrue%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FBT%22%7D, %22FBT%22)); // %5Btrue%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%22FooBarTest%22%7D, %22FBT%22)); // %5Btrue%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%0A//            %22FooBar%22, %22FooBarTest%22, %22FootBall%22, %22FrameBuffer%22, %22ForceFeedBack%22%7D, %22FB%22)); // %5Btrue,false,true,true,false%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%0A//            %22FooBar%22, %22FooBarTest%22, %22FootBall%22, %22FrameBuffer%22, %22ForceFeedBack%22%7D, %22FoBa%22)); // %5Btrue,false,true,false,false%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%0A//            %22FooBar%22, %22FooBarTest%22, %22FootBall%22, %22FrameBuffer%22, %22ForceFeedBack%22%7D, %22FoBaT%22)); // %5Bfalse,true,false,false,false%5D%0A//        System.out.println(prob.camelMatch(new String%5B%5D%7B%0A//            %22CompetitiveProgramming%22, %22CounterPick%22, %22ControlPanel%22%7D, %22CooP%22)); // %5Bfalse,false,true%5D%0A        System.out.println(prob.camelMatch(new String%5B%5D%7B%22ControlPanel%22%7D, %22CooP%22)); // %5Btrue%5D%0A        System.out.println(prob.camelMatch(new String%5B%5D%7B%22ConxonpPanel%22%7D, %22ConpP%22)); // %5Btrue%5D%0A        System.out.println(prob.camelMatch(new String%5B%5D%7B%22ControlPanel%22%7D, %22CtnP%22)); // %5Bfalse%5D%0A    %7D
 %0A%7D%0A

Solve problem 1023