FastPrepCharacter Counts with Retried Remote Workers
Problems/Character Counts with Retried Remote Workers

Character Counts with Retried Remote Workers

Coalition logoCoalition● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The linked interview solution shows counting characters in turns across workers, where building a worker and getting a result can fail. Our version uses fixed failure schedules and a log of what happened, instead of random failures, so tests can be repeated. The photo in the report says r:2 for Hello there, but our answer is r:1. Building workers early is not required. Our version is about 75% the same as the reported question.

Implement a manager that counts characters using workers whose construction or result retrieval may fail. You are given text, a positive workerCount, and one faultScripts[i] string for each worker.

Worker i owns the characters at indices i, i + workerCount, i + 2 * workerCount, .... Preserve character case and spaces. Process workers in increasing index order, completing one worker before starting the next. Empty chunks still use a worker.

Deterministic failure schedules

For this exercise, a supplied script replaces random failures. Its characters describe consecutive attempts, starting at attempt 0. Each script consists of zero or more C or R characters followed by exactly one final S.

  • C: construction fails. Do not call the result method on this attempt.
  • R: construction succeeds, then result retrieval fails.
  • S: construction and result retrieval both succeed; the result contains the character counts for that worker's chunk.

After either failure, retry the same chunk by constructing a fresh worker. Aggregate only its one successful result, exactly once. Do not create any workers in advance and do not perform real network calls or random sampling.

Return value

Return a string matrix recording the simulated calls and counts. All indices and counts are decimal strings.

  1. For every attempt append ["construct", workerIndex, attemptIndex, "fail" or "ok"].
  2. If construction succeeds, append ["result", workerIndex, attemptIndex, "fail" or "ok"].
  3. Immediately after a successful result, append one ["worker-count", workerIndex, character, count] row for every character with a positive count in that chunk, ordered by ascending ASCII code. Then move to the next worker.
  4. After all workers finish, append one ["count", character, count] row for every positive total count, also in ascending ASCII order.

A character field is the one-character string itself, including " " for a space. Zero counts produce no rows. The audit rows make retry behavior observable; there is no scheduling or optimization objective.

Interpretation

For example, Hello there contains one r, so the total count for r is "1". Workers are constructed inside the retry loop, not eagerly.

Function

countWithRetries(text: String, workerCount: int, faultScripts: String[]) → String[][]

Examples

Example 1

text = "ab"workerCount = 2faultScripts = ["CS","RS"]return = [["construct","0","0","fail"],["construct","0","1","ok"],["result","0","1","ok"],["worker-count","0","a","1"],["construct","1","0","ok"],["result","1","0","fail"],["construct","1","1","ok"],["result","1","1","ok"],["worker-count","1","b","1"],["count","a","1"],["count","b","1"]]

Worker 0 retries construction without making a result call; worker 1 retries after a failed result. Each successful worker contributes its one-character chunk exactly once.

Example 2

text = "aba"workerCount = 2faultScripts = ["S","S"]return = [["construct","0","0","ok"],["result","0","0","ok"],["worker-count","0","a","2"],["construct","1","0","ok"],["result","1","0","ok"],["worker-count","1","b","1"],["count","a","2"],["count","b","1"]]

Round-robin chunks are aa and b, so the two worker-count groups differ. Final counts are a:2 and b:1.

Example 3

text = ""workerCount = 1faultScripts = ["RCS"]return = [["construct","0","0","ok"],["result","0","0","fail"],["construct","0","1","fail"],["construct","0","2","ok"],["result","0","2","ok"]]

Even an empty chunk follows its failure script. There are no worker-count or final count rows.

Constraints

  • 0 <= text.length <= 10000.
  • text contains only English letters and ASCII spaces.
  • 1 <= workerCount <= 100.
  • faultScripts.length == workerCount.
  • Each script matches zero or more C/R characters followed by one S; the total script length is at most 1000.

More Coalition interview questions

  • Evaluate Reverse Polish NotationPHONE SCREEN · Seen Mar 2023
  • Time Based Key-Value StoreOA · Seen Jul 2024

Similar questions at other companies

  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Fixed-Order Task Run Time With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Risk-Priority Detection StoreCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Environment Variable Store and SubstitutionAmazon · PHONE SCREEN
See Coalition hiring insights
Saved
class Solution {
    public String[][] countWithRetries(String text, int workerCount, String[] faultScripts) {
        // write your code here
    }
}
Checking account…