Data Structures & AlgorithmsModerateTCS NQT · Infosys
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 alphabetically. What is the first character of the last piece in this sorted order?
- A. g
- B. a
- C. d
- D. h
Correct answer: A. g
Split into chunks of three, sort the resulting strings, and read the last one. Sorting by length or taking the first chunk gives a different letter.
More Coding Interview Problems questions
- 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?
- Problem: The mapping of letters is A=1 through Z=26. What is the sum of the values of the letters in the word "MATH"?