Data Structures & AlgorithmsHard
When repeatedly deleting adjacent pairs of different letters, why does the final length have fixed parity?
- A. Each deletion removes exactly two characters, so the length changes by two and its parity never changes.
- B. Each deletion removes exactly one character, so parity alternates.
- C. The final length always equals the original length.
- D. Parity is determined by the first letter only.
Correct answer: A. Each deletion removes exactly two characters, so the length changes by two and its parity never changes.
Removing two characters at a time preserves the length modulo two, so the final length has the same parity as the start. This gives a quick sanity check on any reduction answer.
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
- In the 'shortest block to sort so the whole array becomes sorted' problem, why does the block start at the first mismatch with the sorted…
- For an anagram search with a fixed window of length 3, why is a count comparison cheap per step?
- For the 'ramp width' problem (max j − i with A[i] ≤ A[j]), why are only prefix minima and suffix maxima worth considering?
- Why does pairing the heaviest remaining person with the lightest one (when they fit together) minimise boats when each boat carries at…
- The minimum number of consecutive deletions to make an array non-decreasing is found by which structure?
- Why is k ≥ n a necessary condition for the residues of n values modulo k to be distinct?