/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static List
<Boolean
> camelMatch
(String[] queries,
String pattern
) { List<Boolean> result = new ArrayList<>();
char[] patternArr = pattern.toCharArray();
// Start for each string in the query array
for (String query
: queries
) {
// Match it with the pattern
boolean isMatch = match(query.toCharArray(), patternArr);
// Pass the result
result.add(isMatch);
}
return result;
}
private static boolean match(char[] queryArr, char[] patternArr) {
int j = 0; // pattern pointer
// i is the query pointer
for (int i = 0; i < queryArr.length; i++) {
// If char[i] == char[j], we need to advance both the pointers.
if (j < patternArr.length && queryArr[i] == patternArr[j]) {
j++;
} else if (queryArr[i] >= 'A' && queryArr[i] <= 'Z') {
// If the query character is a uppercase letter, then return false.
return false;
}
}
// Just verify that pattern pointer reaches its length limit
return j == patternArr.length;
}
{
String[] queries
= {"StudyAlgorithms",
"StudyAlgorithmsTest",
"StanAlluring",
"SimulationAlteration",
"StopStayAlive"};
List<Boolean> results = camelMatch(queries, pattern);
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgTGlzdDxCb29sZWFuPiBjYW1lbE1hdGNoKFN0cmluZ1tdIHF1ZXJpZXMsIFN0cmluZyBwYXR0ZXJuKSB7CiAgICAgICAgTGlzdDxCb29sZWFuPiByZXN1bHQgPSBuZXcgQXJyYXlMaXN0PD4oKTsKICAgIAogICAgICAgIGNoYXJbXSBwYXR0ZXJuQXJyID0gcGF0dGVybi50b0NoYXJBcnJheSgpO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