Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 and then the first 4 elements are reversed. What is the element at index 0 of the result?
- A. 1
- B. 4
- C. 3
- D. 7
Correct answer: D. 7
Left rotation by 3 gives [4,5,6,7,8,1,2,3], and reversing the first four puts 7 in front. Rotating right gives 1, skipping the reversal gives 4, and reversing the whole array gives 3.
More Coding Interview Problems questions
- Problem: The string "abcdefgh" is cut into pieces of length 3 from the left (the last piece may be shorter). The pieces are then sorted…
- Problem: Let g(n) be the number of integers in [1, n] whose decimal digit sum is even. What is g(50)?
- Problem: The Euler's totient of 36 is φ(36), the count of integers in [1, 36] coprime to 36. What is φ(36)?
- Problem: A pair of ropes is connected as a chain: lengths 3, 4, 5 are joined in the order listed, each join costs the sum of the two…
- Problem: From the list [5, 3, 3, 7, 12, 9], what is the second-smallest distinct value (duplicates count once)?
- Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?