All practice tasks

Coding (Algo)

Unread Thread Badges

Hash map · Easy

A mobile inbox receives messages from multiple threads. Read messages must not contribute to badges, but every unread message counts.

Return unread counts for threads with at least one unread message in ascending ASCII order.

Input

Call

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

Input object

{ messages:{thread:string,read:boolean}[] }

What each field means

  • messages — records with a thread ID and a boolean read flag.

Output

Return value and rules

  • Return {thread, unread} counts for messages whose read is false.
  • Omit threads with no unread messages.
  • Sort thread IDs by ASCII order ascending.

Constraints

  • 0 <= messages.length <= 100000; thread IDs contain 1–40 lowercase ASCII letters.

Examples

Example 1

{
  "messages": [
    {
      "thread": "b",
      "read": false
    },
    {
      "thread": "a",
      "read": true
    },
    {
      "thread": "b",
      "read": false
    }
  ]
}

Returns

[
  {
    "thread": "b",
    "unread": 2
  }
]

Example 2

{
  "messages": []
}

Returns

[]

Required complexity

O(n + t log t) time and O(t) space

What this task practices

Unread Thread Badges 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.