โœ๏ธ

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