All practice tasks

Coding (Algo)

Compress Status Runs

Run length encoding · Easy

A status feed stores many adjacent identical observations. A compact report must preserve changes rather than merge all equal statuses globally.

Run-length encode adjacent equal statuses.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ statuses:string[] }

Input rules

  • Status values are case-sensitive ASCII strings.

What each field means

  • statuses — case-sensitive status strings in observation order.

Output

Return value and rules

  • Return one {status, count} object for each consecutive run of the same status.
  • Preserve run order. Equal statuses separated by another status remain separate runs.
  • Empty input returns [].

Constraints

  • 0 <= statuses.length <= 100000; status length <= 40

Examples

Example 1

{
  "statuses": [
    "up",
    "up",
    "down",
    "up"
  ]
}

Returns

[
  {
    "status": "up",
    "count": 2
  },
  {
    "status": "down",
    "count": 1
  },
  {
    "status": "up",
    "count": 1
  }
]

Example 2

{
  "statuses": []
}

Returns

[]

Required complexity

O(n) time and O(n) output space

What this task practices

Compress Status Runs 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.