01 Matrix
Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.
Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.
Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.
You are given two non-empty linked lists representing two non-negative integers...
Given the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance k from the target node.
We are given an array asteroids of integers representing asteroids in a row.
Given a string s which represents an expression, evaluate this expression and return its value.
You are given an array prices where prices[i] is the price of a given stock on the ith day.
Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).
Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).
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 binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).
You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.
Return a deep copy (clone) of the graph.
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
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. You may return the combinations in any order.
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.
Find all valid combinations of k numbers that sum up to n such that the following conditions are true.
Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the...
Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.
For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, return false.
Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature.
Given a string s containing only digits, return the number of ways to decode it.
Design a data structure that supports adding new words and finding if a string matches any previously added string.
You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.
Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.
Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.
Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array.
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
Given the sorted rotated array nums of unique elements, return the minimum element of this array.
A peak element is an element that is strictly greater than its neighbors.
There is only one repeated number in nums, return this repeated number.
Given the integer array fruits, return the maximum number of fruits you can pick.
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
Given an integer array nums representing the amount of money of each house, return *the maximum amount of money you can rob tonight without alerting the police.
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle.
A trie (pronounced as try) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
Implement the RandomizedSet class...
You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti.
You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
Given an integer array nums and an integer k, return the kth largest element in the array.
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.
Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.
Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Given a string s, return the longest palindromic substring in s.
Return the length of the longest substring containing the same letter you can get after performing the above operations.
Given a string s, find the length of the longest substring without repeating characters.
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.
Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm...
Given an integer array nums, find a subarray that has the largest product, and return the product.
Given an integer array nums, find the subarray which has the largest sum and return its sum.
Given the root of a binary tree, return the maximum width of the given tree.
Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals...
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Among all possible rooted trees, those with minimum height (i.e. min(h)) are called minimum height trees (MHTs).
There are some spherical balloons taped onto a flat wall that represents the XY-plane...
Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.
A permutation of an array of integers is an arrangement of its members into a sequence or linear order.
Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
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.
Given an integer array nums, return the number of longest increasing subsequences.
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.
There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges.
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
Given a string s, return the number of palindromic substrings in it.
Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.
Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum.
Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.
An array arr a mountain if the following properties hold...
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children.
Given a binary tree. Populate each next pointer to point to its next right node.
Implement pow(x, n), which calculates x raised to the power n.
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].
You need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it.
Given the head of a linked list, remove the nth node from the end of the list and return its head.
You are given the head of a singly linked-list...
Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.
Given a signed 32-bit integer x, return x with its digits reversed.
Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly.
Given the head of a linked list, rotate the list to the right by k places.
Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.
Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.
Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.
Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.
Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.
Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
Given the head of a linked list, return the list after sorting it in ascending order.
Given an m x n matrix, return all elements of the matrix in spiral order.
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
Given an integer array nums of unique elements, return all possible subsets (the power set).
Given an integer array nums that may contain duplicates, return all possible subsets (the power set).
Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)
You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.
Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task.
Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0])...
Determine if a 9 x 9 Sudoku board is valid.
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.
Given an m x n grid of characters board and a string word, return true if word exists in the grid.