Member-only story

Practicing Recursion With 7 Algorithm Challenges

Nail your next interview with these useful practice problems

Annie Liao
Better Programming
5 min readJun 27, 2020

--

Photo from inDepth.dev.

Remember the first time you solved an algorithmic challenge by yourself without looking up the solution, only to be told to solve it again using a recursive function?

As this appears to be a common scenario — especially in a tech interview setting — I am putting together a list of classic algorithm challenges to help flex our recursive brain muscles, as this appears to be a common scenario — especially in a tech interview setting…

1. Reversing a String

/* Instruction:
Given a string, write a recursive function to return the reversed string. */
// Example:
reverseString('covid')
// => 'divoc'

This one seems to be the first challenge every code newbie encounters. If you haven’t solved this problem with recursion yet, I encourage you to try it out before reading further.

Here’s my solution, which can be refactored via a ternary operator:

--

--

Annie Liao
Annie Liao

Written by Annie Liao

Fullstack Developer: React with Rails. Currently exploring data structures, D3 visualization, and other front-end magic.

Responses (1)

Write a response