Skip to content
  • Courses
  • Resources
  • Blog
  • About
Menu
  • Courses
  • Resources
  • Blog
  • About
STUDENT LOGIN
  • Courses
  • Resources
  • Blog
  • About
  • Student Login
Menu
  • Courses
  • Resources
  • Blog
  • About
  • Student Login

12 Common Recursion Interview Questions (with Video Solutions)

  • October 3, 2019

Recursion Interview Questions

Coding interview questions requiring recursion may be some of the hardest questions out there. But they are also some of the most important.

Interviewers love to ask recursion interview questions because they truly push interviewees to the limit, and allow interviewers to differentiate between those candidates who are just good and those who are exceptional.

Not only that, but recursive techniques tend to bleed into almost every other category of question.

Strings? Edit Distance or Longest Common Substring.

Trees and Graphs? Depth First Search.

Dynamic Programming? Recursion is the first step of the FAST Method.

Suffice to say, it is absolutely essential that you be prepared to solve recursion interview questions in your interview. It is almost guaranteed that you will see at least one or two recursive problems at any given onsite interview.

In this post, I will walk you through 12 of the most common recursion interview questions that you might see in your coding interview. If you understand these problems and the underlying strategies, you will be well on your way to nailing any recursive problem.

As you go through each of these problems, I would highly encourage you to attempt the problem on your own before watching the solution. Ideally, you should simply be using the solutions as a reference.

Protip: If you’re still new to recursion, check out our Ultimate Guide to Recursion first

 

Check out the problems:

1. Making Change

Given an input amount of change x, write a function to determine the minimum number of coins required to make that amount of change.

eg. (using American coins)

1
2
3
4
change(1) = 1
change(3) = 3
change(7) = 3
change(32) = 4

 

2. Binary Search Tree Verification

Given a binary tree, write a function to test if the tree is a binary search tree.

eg.

Valid:

Random Binary Tree

Invalid:

Binary Tree Validation invalid

3. Find All Permutations of an Input

Write a function that returns all permutations of a given list.

eg.

1
2
3
4
5
6
7
permutations({1, 2, 3})
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]

 

4. Balanced Binary Tree

Given a binary tree, write a function to determine whether the tree is balanced.

eg.

All subtrees are balanced
Balanced Binary Tree graph

5. Print a Linked List in Reverse Order

Given a linked list, write a function that prints the nodes of the list in reverse order.

eg.

1
2
3
4
printReversedList(1 -> 2 -> 3)
3
2
1

 

6. Longest Consecutive Branch in a Tree

Given a tree, write a function to find the length of the longest branch of nodes in increasing consecutive order.

eg.

longest branch tree

 

7. Tree to Doubly Linked List

Given a tree, write a function to convert it into a circular doubly linked list from left to right by only modifying the existing pointers.

eg.

Lowest Common Ancestor tree

<- 4 <-> 2 <-> 5 <-> 1 <-> 6 <-> 3 <-> 7 ->

 

8. Nth Fibonacci Number

Given an integer n, write a function to compute the nth Fibonacci number.

eg.

1
2
3
fibonacci(1) = 1
fibonacci(5) = 5
fibonacci(10) = 55

 

9. Reverse a Stack

Given a stack, reverse the items without creating any additional data structures.

eg.

reverse(1->2->3) = 3->2->1

 

10. Compute the Sum

Given two integers, write a function to sum the numbers without using any arithmetic operators.

 

11. Find the Lowest Common Ancestor

Given two nodes in a binary tree, write a function to find the lowest common ancestor.

eg.

Lowest Common Ancestor tree

1
2
lcs(4, 3) = 1
lcs(6, 7) = 3

 

12. Select a Random Binary Tree Node

Implement a binary tree with a method getRandomNode() that returns a random node.

eg.

Random Binary Tree

1
2
3
getRandomNode() = 5
getRandomNode() = 8
getRandomNode() = 1

 

 

Have you seen any of these problems in an interview before? Comment below and let me know!

DON'T DO ANOTHER CODING INTERVIEW...

...until you've mastered these 50 questions!

GET YOUR FREE GUIDE

RECOMMENDED ARTICLES

data structures

Article

The Definitive Guide to Data Structures for Coding Interviews

Data structures are critical to coding interview success. In this post, I'll show you exactly which data structures you need to know to nail your interviews.

Article

Acing the Google Interview: The Ultimate Guide

Acing the Google interview. Every engineer's dream. But the Google interview is really hard. In this post, you'll learn exactly how to prepare effectively.
stuck on coding interview

Article

10 ways to get unstuck and never fail another coding interview

It happens time and again. People fail coding interviews because they don’t know what to do when stuck on a problem. Developing a clear plan of attack helps you to succeed at any whiteboard coding interview.
Envelope Twitter Facebook Linkedin Youtube

© Byte by Byte 2016-2022

Privacy Policy

Terms and Conditions

Earnings Disclaimer

What if coding interviews were easy?

Sounds impossible right? It’s not!

Let me show you the RIGHT way to study for interviews so you can ace your Google Interview without breaking a sweat.

Download my FREE guide to the 50 most common coding interview questions asked at companies like Google, Facebooks, and Amazon.

Download my FREE guide to the 50 most common coding interview questions asked at companies like Google, Facebooks, and Amazon.

Get fully prepared for your Coding Interview and save 20% with Exponent. Learn More  →