Practice problems
Problem โ examples โ hints โ write your solution โ run โ test โ explanation. Pseudocode for thinking, JavaScript and Python for interviews. Pick a course, a topic and a level โ and go!
Easy๐งฉ
Add two numbers
TAKE two numbers A and B, add them and DISPLAY the sum.
#Variables
Easy๐งฉ
Age calculator
TAKE the BIRTH_YEAR and the CURRENT_YEAR and DISPLAY how old the person will be this year.
#Variables
Easy๐งฉ
Area of a rectangle
TAKE the WIDTH and HEIGHT of a rectangle and DISPLAY its area.
#Variables
Easy๐งฉ
ATM withdrawal
TAKE the BALANCE and the AMOUNT to withdraw.
#Computational thinking
Medium๐งฉ
Average of a list
Given SET SCORES = [70, 85, 90, 55], DISPLAY the average score.
#Lists
Expert๐งฉ
Balanced brackets
TAKE a TEXT made of ( and ) characters.
#Data structures
Easy๐งฉ
Bill calculator
TAKE the PRICE of an item and the QUANTITY bought.
#Variables
Mediumโก๐
Binary Tree Level Order
Return the values of a binary tree level by level, as a list of lists. (Tests give the…
#Trees
Hard๐งฉ
Bubble sort
Sort SET NUMS = [5, 1, 4, 2, 8] into ascending order using bubble sort (don't use SORT!),…
#Sorting
Easyโก๐
Climbing Stairs
You can climb 1 or 2 steps at a time. In how many distinct ways can you reach…
#Dynamic programming
Mediumโก๐
Coin Change
Return the fewest coins needed to make amount, or -1 if impossible. You have unlimited coins of each…
#Dynamic programming
Easyโก๐
Contains Duplicate
Return true if any value appears at least twice in the array, otherwise false.
#Hashing
Easy๐งฉ
Count from 1 to N
TAKE N and DISPLAY every number from 1 to N, one per line.
#Loops
Medium๐งฉ
Count the digits
TAKE a positive whole number N and DISPLAY how many digits it has.
#Loops
Medium๐งฉ
Count the vowels
TAKE a WORD and DISPLAY how many vowels (a, e, i, o, u) it contains.
#Strings
Easy๐งฉ
Even or odd
TAKE a whole number N and DISPLAY "Even" or "Odd".
#Conditions
Medium๐งฉ
Factorial
TAKE N and DISPLAY N! (1 ร 2 ร โฆ ร N).
#Loops
Medium๐งฉ
Fix the countdown
This program should count down from N to 1, but it never stops! Find the bug and fix…
#Debugging
Easy๐งฉ
Grade calculator
TAKE MARKS (0โ100).
#Conditions
Mediumโก๐
Group Anagrams
Group words that are anagrams of each other. Return the groups sorted: words inside each group alphabetically, and…
#Hashing
Easyโก๐
Invert a Binary Tree
Mirror a binary tree (swap every nodeโs left and right children) and return its root. The tests print…
#Trees
Medium๐งฉ
Largest of three numbers
TAKE three numbers A, B and C and DISPLAY the largest.
#Conditions
Hard๐งฉ
Leap year
TAKE a YEAR.
#Conditions
Easy๐งฉ
Linear search
Given SET LIST = [4, 8, 15, 16, 23, 42], TAKE a TARGET and DISPLAY its index, or…
#Searching
Mediumโก๐
Longest Substring Without Repeats
Return the length of the longest substring that has no repeated characters.
#Sliding window
Easy๐งฉ
Making tea
Write the steps to make a cup of tea as pseudocode, using DISPLAY for each step.
#Computational thinking
Mediumโก๐
Maximum Subarray
Return the largest sum of any non-empty contiguous subarray.
#Dynamic programming
Easy๐งฉ
Maximum with a function
Write FUNCTION MAX2(A, B) that RETURNs the larger value.
#Functions
Easyโก๐
Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list and return its head. (Tests pass arrays; ListNode is…
#Linked lists
Mediumโก๐
Min Stack
Design a stack that supports push(x), pop(), top() and getMin() โ all in O(1). The tests run a…
#Stacks & queues
Easy๐งฉ
Multiplication table
TAKE N and DISPLAY its table from 1 to 5 in the form N x I = ANSWER.
#Loops
Mediumโก๐
Number of Islands
The grid holds "1" (land) and "0" (water). Count the islands (land connected up/down/left/right).
#Graphs
Easy๐งฉ
Positive, negative or zero
TAKE a number N and DISPLAY "Positive", "Negative" or "Zero".
#Conditions
Mediumโก๐
Product of Array Except Self
Return an array where each position holds the product of every other number โ without using division.
#Arrays
Hard๐งฉ
Recursive sum
Write a recursive FUNCTION SUM_TO(N) that returns 1 + 2 + โฆ + N.
#Recursion
Hard๐งฉ
Reverse a number
TAKE a positive whole number N and DISPLAY its digits reversed (1234 โ 4321).
#Loops
Mediumโก๐
Rotting Oranges
In the grid, 0 is empty, 1 a fresh orange and 2 a rotten one. Each minute, rotten…
#Graphs
Mediumโก๐
Search in Rotated Sorted Array
A sorted array of distinct numbers was rotated (e.g. [0,1,2,4,5,6,7] โ [4,5,6,7,0,1,2]). Return the index of the target…
#Binary search
Easy๐งฉ
Sum of 1 to N
TAKE N and DISPLAY the sum 1 + 2 + โฆ + N.
#Loops
Medium๐งฉ
Swap two values
TAKE A and B, swap their values, then DISPLAY A and B.
#Variables
Easyโก๐
Two Sum II (Sorted Input)
The array is sorted in increasing order. Return the 1-based positions [i, j] of the two numbers that…
#Two pointers
Easyโก๐
Valid Anagram
Given two strings, return true if the second is an anagram of the first (same letters, same counts).
#Hashing
Easyโก๐
Valid Palindrome
Ignoring case and every character that isnโt a letter or digit, return true if the string reads the…
#Two pointers
Mediumโก๐
Word Break
Return true if the string can be split into a sequence of words from the dictionary (words may…
#Dynamic programming
๐
No problems match โ try another filter.