Generate the nth term of the count-and-say sequence.

Input: n=1 → Output: "1" Input: n=4 → Output: "1211". 1 → 11 → 21 → 1211

Build each term by reading off consecutive groups of same digits from previous term.

public String countAndSay(int n) { String s = "1"; for (int i = 1; i < n; i++) { StringBuilder sb = new StringBuilder(); int j = 0; while (j < s.length()) { char c = s.charAt(j); int count = 0; while (j < s.length() && s.charAt(j) == c) { j++; count++; } sb.append(count).append(c); } s = sb.toString(); } return s; }