Code RoomRepeated sort in validation loop
MediumPrep Room Coding #1720

Repeated sort in validation loop

Code reviewCode quality & reviewMid–Senior~20 min

Review this Java validation routine.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1public boolean allValid(List<String> tokens, Set<String> dictionary) {
2 for (int i = 0; i < tokens.size(); i++) {
3 String normalized = tokens.get(i).trim().toLowerCase();
4 List<String> dict = new ArrayList<>(dictionary); // copy for binarySearch
5 Collections.sort(dict);
6 if (Collections.binarySearch(dict, normalized) < 0) {
7 return false;
8 }
9 }
10 return true;
11}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.