When a procedure is defined in terms of itself or of its type.
How do I use this section?
All About Recursion: A Deep Dive Recursion, a powerful and often mystifying concept, holds a special place in the heart of programming. Let's embark on a journey to demystify recursion, understand its relationship with iteration, and visualize how it works. Recursion: What Is It? Recursion is a technique where a function calls itself...
Iteration and recursion are both techniques that you can use for implementing solutions in a programming language. I look at both of them as a way of thinking about a problem and solving it. The most important thing to keep in mind before we start discussing them is: **For any problem that can be solved via iteration, there is a corresponding...
Objective: In this lesson, we'll cover this concept, and focus on these outcomes: You'll learn what the subsets pattern is. We'll show you how to use this concept in programming interviews. You'll see how to utilize this concept in challenges. In this tutorial, we...
Recursive Backtracking For Combinatorial, Path Finding, and Sudoku Solver Backtracking Made Simple Backtracking is a very important concept in computer science and is used in many applications. Generally, we use it when all possible solutions of a problem need to be explored. It is also often employed to identify solutions that satisfy...
Given an integer num, write a method to determine if it is a power of 3. The method will be called as follows: `js console.log(powerOfThree(9)); // true console.log(powerO...
Write a recursive algorithm that swaps every two nodes in a linked list. This is often called a pairwise swap. For example: `js /* original list 1 -> 2 -> 3 -> 4 after...
Implement a function that returns the Fibonnaci number for a given integer input. In a Fibonacci sequence, each number is the sum of the two preceding ones. The simplest is the series: 1, 1, 2, 3, 5, 8, etc. This is because: fibonacci(0) = 0 fibonacci(1) = 1 fibonacci(2) = 1 fibonacci(3) = 1 + 1 = 2 fibonacci(4) = 1 + 2...
Given an unsorted array of integers, can you write a method maxProductOfThree(unsorted: array) to find the largest product from three of the numbers? For example, given the following array: [-1, 9, 22, 3, -15, -7] The largest product of three numbers is 2310. This results from -15 * -7 * 22. <img src="https://storage.goo...
We have a string str like the following: `js const str = "bubble"; ` Find a way to convert it to a palindrome by inserting characters in front of it. Recall that a palindrome is defined as "a word, phrase, or sequence that reads the same backward as forward". <img src="https://storage.googleapis.com/algodailyrand...
Write an algorithm to merge two sorted linked lists and return it as a new sorted list. The new list should be constructed by joining the nodes of the input lists. You may a...
Today, we're going to do some math! There is only one prerequisite for answering this question, and it is knowing the definitions of binary and decimal. According to How to Convert Decimal to Binary and Binary to Decimal, binary is a numeric system that only uses two digits — 0 and...
Merging Two Binary Trees The Problem Statement You are presented with two binary trees. Your task is to merge these trees into a single, new binary tree. Merging Binary Trees The Overlap Rule Here's the c...
You're sent a linked list of numbers, but it's been received in the opposite order to what you need. This has happened multiple times now, so you decide to write an algorithm to reverse the lists as they come in. The list you've received is as follows: 7 -> 2 -> 21 -> 6 -> 42 -> 10 Write an algorithm for a method `rever...
The Longest Increasing Subsequence (LIS) is a subsequence within an array of numbers with an increasing order. The numbers within the subsequence have to be unique and in an ascending manner. It's important to note that the items of the sequence do not have to be in consecutive locations within the array. Can you write an effi...
A perfect square is a number made by squaring a whole number. Some examples include 1, 4, 9, or 16, and so on -- because they are the squared results of 1, 2, 3, 4, etc. For example: ` 1^2 = 1 2^2 = 4 3^2 = 9 4^2 = 16 ... ` However, 15 is not a perfect square, because the square root of 15 is...
Imagine the implementation for the paintbucket feature in Microsoft Paint, or how certain image filters work. You click on a specific pixel on a screen, and every similar-colored neighboring pixel would change to your selected color. Let's implement a simpler version of that feature. <img src="https://storage.googleapis.com/algo...
N-Queen Problem: The Chessboard Conundrum Imagine stepping into an interview room, and the interviewer asks you to solve the N-Queen problem. It's a modern take on the classic 8-Queen Puzzle, where you place queens on a chessboard in such a way that none can attack another. He...
This challenge is all about a well-known problem in programming. You might have come across it in a job interview as part of a test, or even as part of a competition or exam. The problem is called Combination Sum and there are some variations in how it is presented, but this is the most common one: Given an array of distinct inte...