Dynamic Programming

Both a mathematical optimization method and a computer programming method that breaks down complicated problems to sub-problems.

Section Menu

How do I use this section?

1. CHALLENGE

Merge Sorted Linked Lists

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...

2. CHALLENGE

Longest Increasing Subsequence

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...

3. CHALLENGE

Sum of Perfect Squares

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...

4. CHALLENGE

Pick A Sign

We're given an array of positive integers like the following: `js [2, 1, 3, 2] ` Imagine that we're allowed to make each element of the array either a positive or negative number, indicated by a signage -- either a plus (+) or minus (-) sign that appears before it. If we sum up all the signed elements, we will get a tot...

5. CHALLENGE

Classical N-Queen Problem

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...