09 Sept 2026•Go / Python / TypeScript•Easy

Positions of Large Groups

Return the start and end indices of every repeated-character group of length at least three.

Advance an end pointer over each maximal run, record qualifying bounds, and continue from the next character.

complexity

O(n) time and O(1) auxiliary space excluding output.

solution files

  • Go positions-of-large-groups/solution.go
  • Python positions-of-large-groups/solution.py
  • TypeScript positions-of-large-groups/solution.ts

Solution files

Go•positions-of-large-groups/solution.go
package main

func largeGroupPositions(s string) [][]int {
	result := [][]int{}
	for start := 0; start < len(s); {
		end := start + 1
		for end < len(s) && s[end] == s[start] {
			end++
		}
		if end-start >= 3 {
			result = append(result, []int{start, end - 1})
		}
		start = end
	}
	return result
}
Python•positions-of-large-groups/solution.py
class Solution:
    def largeGroupPositions(self, s: str) -> list[list[int]]:
        result: list[list[int]] = []
        start = class="syntax-number">0
        while start < len(s):
            end = start + class="syntax-number">1
            while end < len(s) and s[end] == s[start]: end += class="syntax-number">1
            if end - start >= class="syntax-number">3: result.append([start, end - class="syntax-number">1])
            start = end
        return result
TypeScript•positions-of-large-groups/solution.ts
function largeGroupPositions(s: string): number[][] {
  const result: number[][] = [];
  let start = class="syntax-number">0;
  while (start < s.length) { let end = start + class="syntax-number">1; while (end < s.length && s[end] === s[start]) end += class="syntax-number">1; if (end - start >= class="syntax-number">3) result.push([start, end - class="syntax-number">1]); start = end; }
  return result;
}