2
public List<List<Integer>> largeGroupPositions(String s) {3
List<List<Integer>> res = new ArrayList<>();4
List<Integer> tmp = new ArrayList<>();7
for (int i = 0; i < s.length() - 1; i++) {8
// Increment the count until the next element is the same as the previous element. Ex: "aaa"9
if (s.charAt(i) == s.charAt(i + 1)) {12
// Add the first and last indices of the substring to the list when the next element is13
// different from the previous element. Ex: "aaab"14
else if (s.charAt(i) != s.charAt(i + 1) && count >= 3) {15
// gives the starting index of substring16
tmp.add(i - count + 1);17
// gives the last index of substring21
tmp = new ArrayList<>();27
// Check for a large group at the end of the string. Ex: "abbb".29
tmp.add(s.length() - count);30
tmp.add(s.length() - 1);