Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: What does this snippet print? s = "abcdefgh" print(s[::-3], s[5:1:-2])

  1. A. beh fd
  2. B. heb fd
  3. C. heb df
  4. D. hec fd

Correct answer: B. heb fd

Negative steps start from the end and move backward; the stop index is exclusive. Starting the reversed slice at index 1 or excluding the stop boundary changes the output.

More Coding Interview Problems questions

Exams that ask this topic