All practice tasks

Coding (Algo)

Compress Consecutive Status Characters

Stream processing · Easy

A text diagnostic stores consecutive repeats as character-count pairs. It preserves the exact original text order so the text can be reconstructed. Equal characters separated by another character belong to different runs.

Return consecutive character runs as ordered pairs of the character and its run length.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ text: string }

Fields

  • text is an ASCII string. Case, punctuation and spaces are significant; do not normalize or trim it.

Output

Return value

  • Return [[character,count], ...] in original run order. Empty text returns [].
  • Do not merge nonadjacent runs, change case, or discard whitespace.

Constraints

  • 0 <= text.length <= 100000; ASCII only.

Examples

Example 1

{
  "text": "aaBBa"
}

Returns

[
  [
    "a",
    2
  ],
  [
    "B",
    2
  ],
  [
    "a",
    1
  ]
]

Example 2

{
  "text": "  x"
}

Returns

[
  [
    " ",
    2
  ],
  [
    "x",
    1
  ]
]

Required complexity

O(n) time and O(r) output space for r runs

What this task practices

Compress Consecutive Status Characters is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.