Problem 452159 · easy · Level 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

  • The recursion depth stays under about 3000.

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…