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])
- A. 7 bcc
- B. 16 bc1
- C. 6 bcc
- 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).
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is printed? (move zeros to the end keeping order) python a = [0, 1, 0, 3, 12, 0, 5] w = 0 for r in range(len(a)): if a[r] != 0: a[w]…
- What is the time complexity of deleting the last node of a singly linked list of n nodes when only a head pointer is kept?
- A stack is implemented with a singly linked list. Where should push and pop operate to keep both O(1)?
- What is printed? (C strings) c char s[] = "Placement"; printf("%zu %zu", strlen(s), sizeof(s));
- What is printed? (pointer arithmetic on an int array) c int a[] = {10, 20, 30, 40, 50}; int p = a + 1; printf("%d ", (p + 2)); printf("%d…
- What is printed? (2-D array in row-major order) python R, C = 3, 4 base, size = 1000, 4 def addr(i, j, rowmajor=True): return base + size…