Data Structures & AlgorithmsModerateProduct Company SDE pattern

What is printed? (run-length decode then re-encode)

What is printed? (run-length decode then re-encode)
import re
enc = "a3b1c12"
dec = "".join(ch * int(n) for ch, n in re.findall(r"([a-z])(\d+)", enc))
print(len(dec), dec[3:6])
  1. A. 7 bcc
  2. B. 16 bc1
  3. C. 6 bcc
  4. D. 16 bcc

Correct answer: D. 16 bcc

The pattern pairs each letter with its full (possibly multi-digit) count: a×3, b×1, c×12 → length 16; indices 3..5 are 'b', 'c', 'c'. Reading only one digit per letter would treat '12' as 1 and break the decoding. O(output length).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic