Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Positions of large groups and element positions in sorted array



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Finding Large Continuous Groups in a String

Problem Statement

Given a string text consisting of lowercase letters, the characters form consecutive sequences of identical letters.

For instance, in the string text = "aabbccccdde", the sequences are "aa", "bb", "cccc", "dd", and "e".

We define a sequence as large if it contains at least 4 characters. Your task is to find the starting and ending indexes for every large sequence in the string.

The result should list the ranges in ascending order based on their start positions.

Examples

Example 1:
Input: "aabbccccdde"
Output: [[4,7]]
Explanation: The only large sequence is "cccc" starting at index 4 and ending at index 7.

Example 2:
Input: "abcde"
Output: []
Explanation: No sequences have 4 or more characters.

Example 3:
Input: "zzztttttppppqq"
Output: [[0,2],[3,7],[8,11]]
Explanation: Large sequences are "zzz" (indexes 0-2), "ttttt" (3-7), and "pppp" (8-11).
(Note: "zzz" has length 3, which is less than 4, so it should not appear. Adjust example accordingly.)

Constraints

  • 2 ≤ text.length ≤ 1200
  • The string consists only of lowercase English letters.