Interview conceptCoding & Algorithms

String Parsing, Decoding And CLI Text Processing

Asked of: Software Engineer

Last updated

What's being tested

These problems test deterministic string parsing, careful boundary handling, and translating textual rules into simple state machines or lookup structures. You should demonstrate linear-time scans, explicit validation order, appropriate use of maps/stacks/recursion, and awareness of malformed input, case normalization, and combinatorial output size.

Patterns & templates

  • Bijective base-26 conversion — repeatedly decrement before dividing by 26; 1→A, 26→Z, 27→AA; O(log₍₂₆₎ n) time and output space.
  • Flat-tree decoding — maintain a current node, consume each child index, emit at leaves, then reset to root; validate indices and incomplete final paths.
  • Tokenization and validation — split once, verify token count and numeric fields, normalize case, then mutate state only after the entire command is valid.
  • Sorted temporal scan — parse records into typed fields, use a moving time window or neighboring comparisons, and preserve required output order; avoid unnecessary O(n²) pair checks.
  • Backtracking for wildcards — append each possible replacement, recurse, then undo; O(2^k · L) output-sensitive time for k wildcards and length L.
  • Hash maps for ledger state — map normalized account names to balances; use wide integer types, reject overdrafts, and keep transfers atomic.
  • Explicit edge-case contracts — define behavior for empty strings, zero values, duplicate records, negative numbers, trailing spaces, invalid indices, and wildcard-free inputs.

Common pitfalls

Pitfall: Treating spreadsheet labels as ordinary zero-based base 26 makes multiples of 26 produce incorrect Z boundaries.

Pitfall: Updating balances while parsing a partially validated transaction can leave state corrupted when a later token or account check fails.

Pitfall: Assuming sorted input eliminates all transaction comparisons; a time-window rule may still require tracking every relevant prior city or record.

Practice these

The practice cards below cover the canonical variants — solve all of them and time yourself.

Practice questions

Related concepts