Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: The words of "the sky is blue" are put in reverse order and joined by single spaces to form a new string. How many characters long is the new string?
- A. 12
- B. 4
- C. 15
- D. 16
Correct answer: C. 15
"blue is sky the" keeps 12 letters plus 3 spaces, 15 characters. Counting only letters gives 12, 4 is the word count, and adding a space after every word gives 16.
More Coding Interview Problems questions
- 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…
- 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)?