Problem 452159 · easy · Phase 04 Non-Linear Data Structures

Mirror Writing

recursion · strings · base case

A calligraphy shop sells "mirror" prints: a word written back to front. Write mirror(s) that returns the string s reversed, using recursion (no loops, no slicing tricks such as s[::-1], and no reversed).

Examples

Input:  s = "stream"
Output: "maerts"

Input:  s = ""
Output: ""

Constraints

  • 0 <= len(s) <= 2000, so the recursion depth stays under ~3000.
  • Only plain ASCII characters.

Goals

  • Identify the base case of a recursive string function
  • Shrink the input by one character on every recursive call
  • Combine the recursive result with the removed character
Starting Python…