Dsa
Recursion
Warm-up
The Onion Peeler
You are given a word. Write a recursive function that prints the word, then removes the first and last characters and repeats the process until the string has fewer than 1 character remaining.
Input: A single string S.
Output: The sequence of strings produced by 'peeling' the outer characters, each on a new line.
Example:
Input: CRYSTAL
Output:
CRYSTAL
RYSTA
YST
S
Key concepts
recursionstring-manipulationslicing
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now