# Why 43 is right answer for n=4?

• I wrote small brut force program to print all possible records and got 39 only:

``````    private static final char[] CHARS = {'A', 'L', 'P'};

public static void main(String[] args) {
final Collection<String> result = new ArrayList<>();
for (int i = 0; i < CHARS.length; i++) {
for (int j = 0; j < CHARS.length; j++) {
for (int k = 0; k < CHARS.length; k++) {
for (int l = 0; l < CHARS.length; l++) {
final String w = "" + CHARS[i] + CHARS[j] + CHARS[k] + CHARS[l];
if (isValid(w)) {
}
}
}
}
}
System.out.println(result.size());
result.forEach(System.out::println);
}

private static boolean isValid(String w) {
int a = 0;
int l = 0;
for (int i = 0; i < w.length(); i++) {
switch (w.charAt(i)) {
case 'L':
l++;
break;
case 'A':
a++;
break;
}
}
return a <= 1 && l <= 2;
}
``````

What am I missing?

Here is all values:
39
ALLP
ALPL
ALPP
APLL
APLP
APPL
APPP
LALP
LAPL
LAPP
LLAP
LLPA
LLPP
LPAL
LPAP
LPLA
LPLP
LPPA
LPPL
LPPP
PALL
PALP
PAPL
PAPP
PLAL
PLAP
PLLA
PLLP
PLPA
PLPL
PLPP
PPAL
PPAP
PPLA
PPLL
PPLP
PPPA
PPPL
PPPP

• You're missing for example `LLPL`.

• LLPL

Ahh, Thanks! I should read task more carefully. Two continuous 'L's. It would be good to add couple examples to task description of which record is awardable and which one doesn't.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.