Data Structures & AlgorithmsModerateTCS NQT · Accenture
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 reverse of the first.
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Test each ordered pair against the reversal condition. Counting unordered pairs halves the number, and ignoring duplicate words changes the count.
More Coding Interview Problems questions
- 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'…
- Problem: Elevator starts at floor 0. Requests arrive in order for floors 3, 1, 4 (the elevator serves each request by going directly to…