Code RoomTruncated string breaks on emoji
HardPrep Room Coding #1693

Truncated string breaks on emoji

Code reviewAlgorithms & data structuresSenior–Staff~25 min

Review this Java method that truncates a string to at most `maxChars` characters for a UI label.

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 25 min
Mark a line and say what kind of problem it is.0 findings
1String truncate(String s, int maxChars) {
2 if (s.length() <= maxChars) {
3 return s;
4 }
5 return s.substring(0, maxChars) + "\u2026";
6}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.