Challenges to Sharpen Your Coding Skills!

Master any coding skill with our curated challenges! From beginner algorithms to expert-level puzzles, navigate easily through topics and difficulties using handy filters. Track your progress, unlock new feats, and join our thriving community - conquer the coding world, one challenge at a time!

1. Arrays

Two Sum
Easy

Given an array of integers and a target sum, find two numbers in the array that add up to the target.

Maximum Subarray Sum
Easy

Given an array of integers, find the contiguous subarray with the maximum sum.

Container With Most Water
Medium

Given an array representing the heights of walls in a container, find the area of the container with the most water trapped between the walls.

Rotate Array
Medium

Given an array and a rotation amount, rotate the array by the specified amount.

Merge Sorted Arrays
Medium

Given two sorted arrays, merge them into a single sorted array.

Find Missing Number
Medium

Given an array of integers containing all numbers from 1 to n except for one missing number, find the missing number.

Product of Array Except Self
Medium

Given an array of integers, find the product of all elements except for the element at the current index.

Pascal's Triangle
Medium

Given a non-negative integer n, generate the nth row of Pascal's Triangle.

Kth Largest Element in an Array
Hard

Given an array of integers and an integer k, find the kth largest element in the array.

Longest Increasing Subsequence
Hard

Given an array of integers, find the length of the longest increasing subsequence (LIS) in the array.

2. Hash Maps

Two Sum
Easy

Given an array of integers and a target sum, find two numbers in the array that add up to the target.

Maximum Subarray Sum
Easy

Given an array of integers, find the contiguous subarray with the maximum sum.

Group Anagrams
Medium

Given an array of strings, group the anagrams together.

LRU Cache
Hard

Design and implement a Least Recently Used (LRU) cache that stores key-value pairs. The cache has a limited capacity, and when it reaches its limit, the least recently used item should be evicted.

Isomorphic Strings
Easy

Given two strings s and t, determine if they are isomorphic.

Word Pattern
Easy

Given a pattern and a string s, find if s follows the same pattern.

Longest Consecutive Sequence
Hard

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

Minimum Window Substring
Hard

Given two strings s and t, return the minimum window in s which will contain all the characters in t.

Valid Sudoku
Medium

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules.

Course Schedule II
Medium

There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example, to take course 0 you have to first take course 1, which is expressed as a pair: [0,1].

3. Linked Lists

Reverse a Linked List
Easy

Reverse a singly linked list.

Detect Cycle in a Linked List
Easy

Given a linked list, determine if it has a cycle.

Merge Two Sorted Linked Lists
Easy

Merge two sorted linked lists into a single sorted list.

Find the Middle Node of a Linked List
Easy

Find the middle node of a linked list.

Delete the Middle Node of a Linked List
Medium

Given only access to a middle node, delete that node from the linked list.

Flatten a Multi-level Linked List
Medium

Flatten a nested linked list with multiple levels into a single-level linked list.

Swap Nodes in Pairs
Medium

Given a linked list, swap every two adjacent nodes and return its head.

Reverse Nodes in k-Group
Hard

Reverse nodes in k-group in a linked list.

LRU Cache
Hard

Design and implement a Least Recently Used (LRU) cache.

Reorder List
Hard

Given a singly linked list, reorder it in-place.

4. Stacks

Valid Parentheses
Easy

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

Evaluate Reverse Polish Notation
Medium

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Next Greater Element I
Easy

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.

Min Stack
Easy

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Trapping Rain Water
Hard

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Daily Temperatures
Medium

Given a list of daily temperatures, where temperatures[i] is the temperature in Fahrenheit for the day i. Return a list of the days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.

Binary Tree Inorder Traversal
Medium

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Evaluate Division
Medium

You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [A_i, B_i] and values[i] represent the equation A_i / B_i = values[i]. Return an array of real numbers representing the values of the equations.

Decode String
Medium

Given an encoded string, return its decoded string.

Maximum Frequency Stack
Hard

Implement FreqStack, a class which simulates the operation of a stack-like data structure.

5. Queues

Implement Queue using Stacks
Easy

Implement a first-in-first-out (FIFO) queue using stacks.

Number of Islands
Medium

Given a 2D grid map of '1's (land) and '0's (water), count the number of islands.

Perfect Squares
Medium

Given a positive integer n, find the least number of perfect square numbers which sum to n.

Sliding Window Maximum
Hard

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right.

Design Circular Queue
Medium

Design your implementation of the circular queue.

Reveal Cards In Increasing Order
Medium

In a deck of cards, every card has a unique integer. You can order the deck in any order.

First Unique Number
Hard

You have a queue of integers, you need to retrieve the first unique integer in the queue.

Task Scheduler
Medium

Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done without the original order of the array.

Maximum Sum Circular Subarray
Medium

Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C.

Design Snake Game
Hard

Design a Snake game that is played on a device with a screen.

Minimum Knight Moves
Hard

In an infinite chessboard with coordinates from -infinity to +infinity, you have a knight at square [0, 0].

6. Recursion

Factorial
Easy

Write a function to compute the factorial of a given non-negative integer n.

Fibonacci Number
Easy

Write a function to find the nth Fibonacci number.

Sum of Digits
Easy

Write a recursive function to find the sum of digits of a given integer.

Power of Two
Easy

Given an integer n, write a function to determine if it is a power of two.

Combination Sum
Medium

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.

Word Search
Medium

Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where 'adjacent' cells are horizontally or vertically neighboring.

Generate Parentheses
Medium

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Decode Ways
Medium

A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> 1, 'B' -> 2, ..., 'Z' -> 26. Given a non-empty string containing only digits, determine the total number of ways to decode it.

Regular Expression Matching
Hard

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*'.

N-Queens II
Hard

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

Wildcard Matching
Hard

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

7. Trees

Maximum Depth of Binary Tree
Easy

Given the root of a binary tree, find its maximum depth.

Symmetric Tree
Easy

Given a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Binary Tree Level Order Traversal
Medium

Given the root of a binary tree, return the level order traversal of its nodes' values.

Construct Binary Tree from Preorder and Inorder Traversal
Medium

Given preorder and inorder traversal of a tree, construct the binary tree.

Binary Tree Inorder Traversal
Medium

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Binary Tree Maximum Path Sum
Hard

Given a non-empty binary tree, find the maximum path sum.

Serialize and Deserialize Binary Tree
Hard

Design an algorithm to serialize and deserialize a binary tree.

Binary Tree Zigzag Level Order Traversal
Medium

Given a binary tree, return the zigzag level order traversal of its nodes' values.

Validate Binary Search Tree
Medium

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

Kth Smallest Element in a BST
Medium

Given the root of a binary search tree (BST) and an integer k, return the kth smallest element in the BST.

8. Binary Trees

Maximum Depth of Binary Tree
Easy

Given the root of a binary tree, find its maximum depth.

Symmetric Tree
Easy

Given a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Binary Tree Level Order Traversal
Medium

Given the root of a binary tree, return the level order traversal of its nodes' values.

Construct Binary Tree from Preorder and Inorder Traversal
Medium

Given preorder and inorder traversal of a tree, construct the binary tree.

Binary Tree Inorder Traversal
Medium

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Binary Tree Maximum Path Sum
Hard

Given a non-empty binary tree, find the maximum path sum.

Serialize and Deserialize Binary Tree
Hard

Design an algorithm to serialize and deserialize a binary tree.

Binary Tree Zigzag Level Order Traversal
Medium

Given a binary tree, return the zigzag level order traversal of its nodes' values.

Validate Binary Search Tree
Medium

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

Kth Smallest Element in a BST
Medium

Given the root of a binary search tree (BST) and an integer k, return the kth smallest element in the BST.

9. Binary Search Trees

Search in a Binary Search Tree
Easy

Given the root node of a binary search tree (BST) and a value, search for the value in the BST.

Insert into a Binary Search Tree
Medium

Insert a value into a binary search tree (BST). Return the root node of the resulting BST after the insertion.

Delete Node in a BST
Medium

Given the root of a binary search tree (BST) and a key, delete the node with the given key from the BST.

Range Sum of BST
Easy

Given the root node of a binary search tree, return the sum of values of all nodes with a value in the range [low, high].

Convert Sorted Array to Binary Search Tree
Easy

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Closest Binary Search Tree Value
Easy

Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target.

Balanced Binary Tree
Easy

Given a binary tree, determine if it is height-balanced.

Lowest Common Ancestor of a Binary Search Tree
Easy

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

Binary Tree Right Side View
Medium

Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

Count Complete Tree Nodes
Medium

Given the root of a complete binary tree, count the number of nodes.

10. Heaps

Top K Frequent Elements
Medium

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Kth Largest Element in a Stream
Easy

Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Merge k Sorted Lists
Hard

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.

Sort Characters By Frequency
Medium

Given a string s, sort it in decreasing order based on the frequency of characters, and return the sorted string.

Find Median from Data Stream
Hard

Design a data structure that supports adding new elements and finding the median of the elements already added. The median should be calculated and returned as follows: If the size of the set is even, return the average of the middle two elements.

Sliding Window Maximum
Hard

You are given an array of integers nums, there is a sliding window of size k which moves from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Find the Most Competitive Subsequence
Medium

Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.

Design Twitter
Hard

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed.

Continuous Median
Hard

You are given an array of integers. For every consecutive subarray of size k, find the median of the array within that window.

Cheapest Flights Within K Stops
Medium

There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w. Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to dst with up to k stops.

11. Sorting

Intersection of Two Arrays II
Easy

Given two arrays, write a function to compute their intersection.

Sort Colors
Medium

Given an array with n objects colored red, white, or blue, sort them in-place.

K Closest Points to Origin
Medium

Given an array of points in the plane, find the K closest points to the origin (0, 0).

Sort List
Medium

Sort a linked list in O(n log n) time using constant space complexity.

First Missing Positive
Hard

Given an unsorted integer array, find the smallest missing positive integer.

Sort Characters By Frequency
Hard

Given a string, sort it in decreasing order based on the frequency of characters.

Find Median from Data Stream
Hard

Design a data structure that supports the following two operations: addNum and findMedian.

Merge Intervals
Hard

Given a collection of intervals, merge overlapping intervals.

Sort an Array
Hard

Sort an array using quicksort, mergesort, heapsort, or any other sorting algorithm.

Guess Number Higher or Lower
Easy

You are playing the Guess Game. Each time, you pick a number and guess it. If the guess is wrong, you are told whether the picked number is lower or higher than the target number.

Search Insert Position
Easy

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

Search in Rotated Sorted Array
Medium

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. You are given a target value to search. If found in the array, return its index, otherwise return -1.

Search a 2D Matrix
Medium

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row.

Find Peak Element
Medium

A peak element in an array is an element such that it is greater than its neighbors. Given an input array nums, find the index of the peak element.

Search a 2D Matrix II
Medium

Write an efficient algorithm that searches for a target value in an m x n matrix. The matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending order from top to bottom.

Find Minimum in Rotated Sorted Array
Medium

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated sorted array nums, return the minimum element of this array.

Search a 2D Matrix
Hard

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each column are sorted from left to right. Integers in each row are sorted in ascending order.

Median of Two Sorted Arrays
Hard

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays.

Search in Rotated Sorted Array II
Hard

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. You are given a target value to search. If found in the array, return True; otherwise, return False.

13. Graphs

Clone Graph
Medium

Given a reference of a node in a connected undirected graph, return a deep copy of the graph.

Number of Islands
Medium

Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.

Course Schedule
Medium

There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example, to take course 0 you have to first take course 1, which is expressed as a pair: [0,1].

Word Ladder
Medium

Given two words (beginWord and endWord), and a dictionary's word list, find the length of the shortest transformation sequence from beginWord to endWord, such that only one letter can be changed at a time.

Perfect Squares
Medium

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

Network Delay Time
Medium

There are N network nodes, labelled 1 to N. You are given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from source to target.

Alien Dictionary
Hard

There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of non-empty words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language.

Trapping Rain Water
Hard

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Word Search II
Hard

Given a 2D board and a list of words from the dictionary, find all words in the board.

Dungeon Game
Hard

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.

14. Greedy Algorithms

Jump Game
Medium

Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length from that position. Determine if you can reach the last index.

Task Scheduler
Medium

Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.

Gas Station
Medium

There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

Candy
Hard

There are n children standing in a line. Each child is assigned a rating value given in an integer array ratings. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors.

Minimum Number of Arrows to Burst Balloons
Medium

There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter, and hence, the x-coordinates of start and end of the diameter suffice. Return the minimum number of arrows that must be shot to burst all balloons.

Huffman Encoding
Hard

Given a list of characters along with their frequency, you need to build a Huffman tree and encode the given characters.

Jump Game II
Hard

Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length from that position. Your goal is to reach the last index in the minimum number of jumps.

Reconstruct Itinerary
Hard

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.

Maximize Sum Of Array After K Negations
Easy

Given an array nums of integers, we must modify the array in the following way: we choose an i and replace nums[i] with -nums[i] done K times.

Remove K Digits
Medium

Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.

15. Backtracking

Letter Combinations of a Phone Number
Medium

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent on a phone keypad.

N-Queens
Hard

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

Generate Parentheses
Medium

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Word Search
Medium

Given an m x n grid of characters board and a string word, return True if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring.

Combination Sum
Medium

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.

Sudoku Solver
Hard

Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are represented by the character '.'.

Word Search II
Hard

Given an m x n board of characters and a list of words, return all words on the board.

Palindrome Partitioning
Medium

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

Regular Expression Matching
Hard

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' matches any single character. '*' matches zero or more of the preceding element.

Number of Islands
Medium

Given an m x n 2D binary grid 'grid' which represents a map of '1's (land) and '0's (water), return the number of islands.

16. Dynamic Programming

Climbing Stairs
Easy

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

House Robber
Easy

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. The only constraint stopping you is that adjacent houses have security systems connected, and if you rob two adjacent houses, the security system will automatically alert the police.

Longest Increasing Subsequence
Medium

Given an unsorted array of integers, find the length of the longest increasing subsequence.

Coin Change
Medium

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

Wildcard Matching
Hard

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'. '?' matches any single character. '*' matches any sequence of characters (including the empty sequence).

Edit Distance
Hard

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

Longest Palindromic Substring
Medium

Given a string s, return the longest palindromic substring in s.

Unique Paths
Medium

A robot is located at the top-left corner of a m x n grid. The robot can only move either down or right at any point in time. How many unique paths are there to reach the bottom-right corner?

Maximum Subarray
Easy

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Jump Game
Medium

Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length from that position. Determine if you can reach the last index.

Word Break
Medium

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

17. Divide-and-Conquer

Binary Search
Easy

Implement binary search on a sorted array.

Merge Sort
Medium

Implement the merge sort algorithm to sort an array.

Quick Sort
Medium

Implement the quick sort algorithm to sort an array.

Closest Pair of Points
Hard

Given a set of points in the plane, find the closest pair of points.

Maximum Subarray Sum
Easy

Find the contiguous subarray with the maximum sum using the divide-and-conquer approach.

Count Inversions in an Array
Hard

Given an array, count the number of inversions (a pair of indices i, j such that i < j and nums[i] > nums[j]).

Strassen's Matrix Multiplication
Hard

Implement Strassen's algorithm for matrix multiplication.

Majority Element
Easy

Find the majority element (element that appears more than ⌊n/2⌋ times) in an array using the divide-and-conquer approach.

Median of Two Sorted Arrays
Hard

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays.

Kth Smallest Element in a Sorted Matrix
Medium

Given an n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.