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!
Given an array of integers and a target sum, find two numbers in the array that add up to the target.
Given an array of integers, find the contiguous subarray with the maximum sum.
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.
Given an array and a rotation amount, rotate the array by the specified amount.
Given two sorted arrays, merge them into a single sorted array.
Given an array of integers containing all numbers from 1 to n except for one missing number, find the missing number.
Given an array of integers, find the product of all elements except for the element at the current index.
Given a non-negative integer n, generate the nth row of Pascal's Triangle.
Given an array of integers and an integer k, find the kth largest element in the array.
Given an array of integers, find the length of the longest increasing subsequence (LIS) in the array.
Given an array of integers and a target sum, find two numbers in the array that add up to the target.
Given an array of integers, find the contiguous subarray with the maximum sum.
Given an array of strings, group the anagrams together.
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.
Given two strings s and t, determine if they are isomorphic.
Given a pattern and a string s, find if s follows the same pattern.
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
Given two strings s and t, return the minimum window in s which will contain all the characters in t.
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules.
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].
Reverse a singly linked list.
Given a linked list, determine if it has a cycle.
Merge two sorted linked lists into a single sorted list.
Find the middle node of a linked list.
Given only access to a middle node, delete that node from the linked list.
Flatten a nested linked list with multiple levels into a single-level linked list.
Given a linked list, swap every two adjacent nodes and return its head.
Reverse nodes in k-group in a linked list.
Design and implement a Least Recently Used (LRU) cache.
Given a singly linked list, reorder it in-place.
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
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.
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
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.
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.
Given the root of a binary tree, return the inorder traversal of its nodes' values.
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.
Given an encoded string, return its decoded string.
Implement FreqStack, a class which simulates the operation of a stack-like data structure.
Implement a first-in-first-out (FIFO) queue using stacks.
Given a 2D grid map of '1's (land) and '0's (water), count the number of islands.
Given a positive integer n, find the least number of perfect square numbers which sum to n.
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 your implementation of the circular queue.
In a deck of cards, every card has a unique integer. You can order the deck in any order.
You have a queue of integers, you need to retrieve the first unique integer in the queue.
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.
Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C.
Design a Snake game that is played on a device with a screen.
In an infinite chessboard with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
Write a function to compute the factorial of a given non-negative integer n.
Write a function to find the nth Fibonacci number.
Write a recursive function to find the sum of digits of a given integer.
Given an integer n, write a function to determine if it is a power of two.
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.
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.
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
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.
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*'.
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.
Given the root of a binary tree, find its maximum depth.
Given a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Given the root of a binary tree, return the level order traversal of its nodes' values.
Given preorder and inorder traversal of a tree, construct the binary tree.
Given the root of a binary tree, return the inorder traversal of its nodes' values.
Given a non-empty binary tree, find the maximum path sum.
Design an algorithm to serialize and deserialize a binary tree.
Given a binary tree, return the zigzag level order traversal of its nodes' values.
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
Given the root of a binary search tree (BST) and an integer k, return the kth smallest element in the BST.
Given the root of a binary tree, find its maximum depth.
Given a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Given the root of a binary tree, return the level order traversal of its nodes' values.
Given preorder and inorder traversal of a tree, construct the binary tree.
Given the root of a binary tree, return the inorder traversal of its nodes' values.
Given a non-empty binary tree, find the maximum path sum.
Design an algorithm to serialize and deserialize a binary tree.
Given a binary tree, return the zigzag level order traversal of its nodes' values.
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
Given the root of a binary search tree (BST) and an integer k, return the kth smallest element in the BST.
Given the root node of a binary search tree (BST) and a value, search for the value in the BST.
Insert a value into a binary search tree (BST). Return the root node of the resulting BST after the insertion.
Given the root of a binary search tree (BST) and a key, delete the node with the given key from the BST.
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].
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.
Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target.
Given a binary tree, determine if it is height-balanced.
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
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.
Given the root of a complete binary tree, count the number of nodes.
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
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.
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.
Given a string s, sort it in decreasing order based on the frequency of characters, and return the sorted string.
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.
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.
Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.
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.
You are given an array of integers. For every consecutive subarray of size k, find the median of the array within that window.
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.
Given two arrays, write a function to compute their intersection.
Given an array with n objects colored red, white, or blue, sort them in-place.
Given an array of points in the plane, find the K closest points to the origin (0, 0).
Sort a linked list in O(n log n) time using constant space complexity.
Given an unsorted integer array, find the smallest missing positive integer.
Given a string, sort it in decreasing order based on the frequency of characters.
Design a data structure that supports the following two operations: addNum and findMedian.
Given a collection of intervals, merge overlapping intervals.
Sort an array using quicksort, mergesort, heapsort, or any other sorting algorithm.
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.
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.
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.
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.
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.
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.
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.
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.
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays.
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.
Given a reference of a node in a connected undirected graph, return a deep copy of the graph.
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
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].
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.
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.
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.
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.
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.
Given a 2D board and a list of words from the dictionary, find all words in the board.
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.
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.
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.
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.
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.
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.
Given a list of characters along with their frequency, you need to build a Huffman tree and encode the given characters.
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.
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.
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.
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.
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent on a phone keypad.
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
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.
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.
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are represented by the character '.'.
Given an m x n board of characters and a list of words, return all words on the board.
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
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.
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.
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?
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.
Given an unsorted array of integers, find the length of the longest increasing subsequence.
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.
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).
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
Given a string s, return the longest palindromic substring in s.
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?
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
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.
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.
Implement binary search on a sorted array.
Implement the merge sort algorithm to sort an array.
Implement the quick sort algorithm to sort an array.
Given a set of points in the plane, find the closest pair of points.
Find the contiguous subarray with the maximum sum using the divide-and-conquer approach.
Given an array, count the number of inversions (a pair of indices i, j such that i < j and nums[i] > nums[j]).
Implement Strassen's algorithm for matrix multiplication.
Find the majority element (element that appears more than ⌊n/2⌋ times) in an array using the divide-and-conquer approach.
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays.
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.