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?

  1. A. g
  2. B. a
  3. C. d
  4. 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

Exams that ask this topic