Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A binary string "1100101011" is to be changed so that it alternates (no two adjacent characters are equal). Each operation flips one bit. What is the minimum number of flips needed, over both possible alternating patterns?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
There are only two alternating targets, and each costs the number of mismatched positions; the answer is the smaller cost. Flipping only to match the first character is a common incomplete approach.
More Coding Interview Problems questions
- Problem: Count the ordered pairs of words (i, j) with i ≠ j in ["abc", "cba", "bca", "abc", "cab", "xyz"] such that the second word is the…
- Problem: For the string "AABABBA" and k = 1, you may replace at most one character with any other letter. What is the length of the…
- Problem: Count the substrings of length 3 in "xyzzaz" that contain three distinct characters.
- Problem: Min-cost climbing: cost = [10, 15, 20, 5, 1]. You may start at index 0 or 1, and from index i you can pay cost[i] to move up 1 or…
- Problem: Count the sequences of steps from {1, 2, 5} that sum to exactly 10 (the order of steps matters).
- Problem: A robot starts at (0, 0) facing north on an unbounded grid. Instructions: 'G' moves one step forward; 'L' turns 90° left; 'R'…