Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "ABCABCABC" is read and each letter is replaced by its position in the alphabet (A=1, B=2, C=3). What is the sum of the first 5 resulting numbers?
- A. 9
- B. 18
- C. 12
- D. 6
Correct answer: A. 9
The first five letters A, B, C, A, B map to 1 + 2 + 3 + 1 + 2 = 9. All nine letters sum to 18, the first six to 12, and the first three to 6.
More Coding Interview Problems questions
- Problem: From the list [12, 18, 24, 30, 36], what is the number of distinct prime divisors of the product of all five numbers?
- Problem: The array [7, 1, 5, 3, 6, 4] is processed to find the maximum profit from one buy and one later sell (0 if none). What is the…
- Problem: A grid of 3×3 cells is numbered 1 to 9 row by row. Starting at 1 (top-left), the robot moves right or down. The number of paths…
- Problem: A list of intervals is [1,5], [2,3], [4,8], [7,9], [10,11]. Merge all overlapping intervals (touching at an endpoint counts as…
- Problem: The string "aabbbcccc" is encoded by writing each letter followed by its count, e.g. "a2b3c4". What is the length of the encoded…
- Problem: What is the number of inversions in the array [2, 5, 1, 4, 3]?