id
int64
1
2.39k
title
stringlengths
3
79
title_slug
stringlengths
3
79
question_content
stringlengths
38
1.55k
tag
stringlengths
4
122
level
stringclasses
3 values
success_rate
float64
14.2
95.5
total_submission
int64
186
13.2M
total_accepted
int64
153
6.4M
question_likes
int64
4
31.2k
question_dislikes
int64
0
11.5k
question_hints
stringlengths
19
3.98k
similar_question_ids
stringlengths
1
51
101
Symmetric Tree
symmetric-tree
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
51.5
2,345,643
1,207,686
9,140
225
null
null
102
Binary Tree Level Order Traversal
binary-tree-level-order-traversal
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).
Tree,Breadth-First Search,Binary Tree
Medium
60.8
1,979,250
1,203,028
7,903
156
null
103,107,111,314,637,764,1035
103
Binary Tree Zigzag Level Order Traversal
binary-tree-zigzag-level-order-traversal
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).
Tree,Breadth-First Search,Binary Tree
Medium
53.5
1,299,175
694,977
5,665
168
null
102
104
Maximum Depth of Binary Tree
maximum-depth-of-binary-tree
Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
71.8
2,259,723
1,621,474
6,744
124
null
110,111,774,1492
105
Construct Binary Tree from Preorder and Inorder Traversal
construct-binary-tree-from-preorder-and-inorder-traversal
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.
Array,Hash Table,Divide and Conquer,Tree,Binary Tree
Medium
57.5
1,199,122
688,958
8,192
218
null
106
106
Construct Binary Tree from Inorder and Postorder Traversal
construct-binary-tree-from-inorder-and-postorder-traversal
Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.
Array,Hash Table,Divide and Conquer,Tree,Binary Tree
Medium
55.2
707,765
390,759
4,348
72
null
105
107
Binary Tree Level Order Traversal II
binary-tree-level-order-traversal-ii
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).
Tree,Breadth-First Search,Binary Tree
Medium
58.6
841,912
493,042
3,118
276
null
102,637
108
Convert Sorted Array to Binary Search Tree
convert-sorted-array-to-binary-search-tree
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.
Array,Divide and Conquer,Tree,Binary Search Tree,Binary Tree
Easy
65.9
1,096,431
722,308
6,158
349
null
109
109
Convert Sorted List to Binary Search Tree
convert-sorted-list-to-binary-search-tree
Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Linked List,Divide and Conquer,Tree,Binary Search Tree,Binary Tree
Medium
55.4
664,109
367,942
4,468
113
null
108,2306
110
Balanced Binary Tree
balanced-binary-tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
Tree,Depth-First Search,Binary Tree
Easy
46.7
1,589,907
742,307
5,563
301
null
104
111
Minimum Depth of Binary Tree
minimum-depth-of-binary-tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children.
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
42.4
1,740,210
737,939
3,963
942
null
102,104
112
Path Sum
path-sum
Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. A leaf is a node with no children.
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
45.4
1,884,955
856,231
5,299
779
null
113,124,129,437,666
113
Path Sum II
path-sum-ii
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. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children.
Backtracking,Tree,Depth-First Search,Binary Tree
Medium
53.9
1,052,748
567,301
4,603
109
null
112,257,437,666,2217
114
Flatten Binary Tree to Linked List
flatten-binary-tree-to-linked-list
Given the root of a binary tree, flatten the tree into a "linked list":
Linked List,Stack,Tree,Depth-First Search,Binary Tree
Medium
57.7
1,026,199
591,658
6,892
461
If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
766,1796
115
Distinct Subsequences
distinct-subsequences
Given two strings s and t, return the number of distinct subsequences of s which equals t. A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions. (i.e., "ACE" is a subsequence of "ABCDE" while "AEC" is not). The test cases are generated so that the answer fits on a 32-bit signed integer.
String,Dynamic Programming
Hard
42.2
509,853
215,300
3,321
146
null
2115
116
Populating Next Right Pointers in Each Node
populating-next-right-pointers-in-each-node
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL.
Linked List,Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
56.8
1,278,931
726,230
6,291
229
null
117,199
117
Populating Next Right Pointers in Each Node II
populating-next-right-pointers-in-each-node-ii
Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL.
Linked List,Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
46.5
923,889
429,180
3,606
237
null
116
118
Pascal's Triangle
pascals-triangle
Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
Array,Dynamic Programming
Easy
64.2
1,195,766
767,602
5,477
206
null
119
119
Pascal's Triangle II
pascals-triangle-ii
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
Array,Dynamic Programming
Easy
57.3
888,446
509,354
2,474
263
null
118,2324
120
Triangle
triangle
Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.
Array,Dynamic Programming
Medium
50.6
807,721
409,106
4,786
380
null
null
121
Best Time to Buy and Sell Stock
best-time-to-buy-and-sell-stock
You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
Array,Dynamic Programming
Easy
54
3,860,000
2,084,089
15,488
522
null
53,122,123,188,309,2138,2144
122
Best Time to Buy and Sell Stock II
best-time-to-buy-and-sell-stock-ii
You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day. Find and return the maximum profit you can achieve.
Array,Dynamic Programming,Greedy
Medium
61.9
1,815,327
1,123,641
7,301
2,353
null
121,123,188,309,714
123
Best Time to Buy and Sell Stock III
best-time-to-buy-and-sell-stock-iii
You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transactions. Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
Array,Dynamic Programming
Hard
43.1
870,907
375,384
5,662
115
null
121,122,188,689
124
Binary Tree Maximum Path Sum
binary-tree-maximum-path-sum
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path.
Dynamic Programming,Tree,Depth-First Search,Binary Tree
Hard
37.6
1,899,960
714,542
9,151
529
null
112,129,666,687,1492
125
Valid Palindrome
valid-palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise.
Two Pointers,String
Easy
41.5
2,944,250
1,220,904
3,460
5,081
null
234,680,2130,2231
126
Word Ladder II
word-ladder-ii
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words [beginWord, s1, s2, ..., sk].
Hash Table,String,Backtracking,Breadth-First Search
Hard
26.9
1,063,919
286,219
3,571
333
null
127,2276
127
Word Ladder
word-ladder
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.
Hash Table,String,Breadth-First Search
Hard
35.4
2,134,427
754,570
7,748
1,635
null
126,433
128
Longest Consecutive Sequence
longest-consecutive-sequence
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time.
Array,Hash Table,Union Find
Medium
48.7
1,319,683
642,062
9,034
398
null
298,2278
129
Sum Root to Leaf Numbers
sum-root-to-leaf-numbers
You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer. A leaf node is a node with no children.
Tree,Depth-First Search,Binary Tree
Medium
56.8
795,340
451,675
4,097
78
null
112,124,1030
130
Surrounded Regions
surrounded-regions
Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region.
Array,Depth-First Search,Breadth-First Search,Union Find,Matrix
Medium
33.9
1,196,214
405,287
4,684
1,164
null
200,286
131
Palindrome Partitioning
palindrome-partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads the same backward as forward.
String,Dynamic Programming,Backtracking
Medium
59.3
746,356
442,390
6,475
201
null
132,1871
132
Palindrome Partitioning II
palindrome-partitioning-ii
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.
String,Dynamic Programming
Hard
33.1
606,455
200,922
3,268
77
null
131,1871
133
Clone Graph
clone-graph
Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. Test case format: For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list. An adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph. The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.
Hash Table,Depth-First Search,Breadth-First Search,Graph
Medium
47.4
1,475,624
699,812
5,546
2,459
null
138,1624,1634
134
Gas Station
gas-station
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. You begin the journey with an empty tank at one of the gas stations. Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique
Array,Greedy
Medium
44.4
899,594
399,619
5,703
595
null
1346
135
Candy
candy
There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Return the minimum number of candies you need to have to distribute the candies to the children.
Array,Greedy
Hard
36.9
570,383
210,748
2,714
246
null
null
136
Single Number
single-number
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space.
Array,Bit Manipulation
Easy
69.3
2,321,213
1,608,367
9,569
339
null
137,260,268,287,389
137
Single Number II
single-number-ii
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space.
Array,Bit Manipulation
Medium
56.5
605,201
342,067
4,009
475
null
136,260
138
Copy List with Random Pointer
copy-list-with-random-pointer
A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list. For example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y. Return the head of the copied linked list. The linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where: Your code will only be given the head of the original linked list.
Hash Table,Linked List
Medium
47.9
1,610,957
772,244
8,313
965
Just iterate the linked list and create copies of the nodes on the go. Since a node can be referenced from multiple nodes due to the random pointers, make sure you are not making multiple copies of the same node. You may want to use extra space to keep old node ---> new node mapping to prevent creating multiples copies of same node. We can avoid using extra space for old node ---> new node mapping, by tweaking the original linked list. Simply interweave the nodes of the old and copied list. For e.g. Old List: A --> B --> C --> D InterWeaved List: A --> A' --> B --> B' --> C --> C' --> D --> D' The interweaving is done using next pointers and we can make use of interweaved structure to get the correct reference nodes for random pointers.
133,1624,1634
139
Word Break
word-break
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. Note that the same word in the dictionary may be reused multiple times in the segmentation.
Hash Table,String,Dynamic Programming,Trie,Memoization
Medium
44.5
2,363,412
1,051,065
10,183
448
null
140
140
Word Break II
word-break-ii
Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note that the same word in the dictionary may be reused multiple times in the segmentation.
Hash Table,String,Dynamic Programming,Backtracking,Trie,Memoization
Hard
41.9
1,036,483
434,784
4,595
475
null
139,472
141
Linked List Cycle
linked-list-cycle
Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. Return true if there is a cycle in the linked list. Otherwise, return false.
Hash Table,Linked List,Two Pointers
Easy
45.8
3,048,390
1,395,560
7,823
773
null
142,202
142
Linked List Cycle II
linked-list-cycle-ii
Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note that pos is not passed as a parameter. Do not modify the linked list.
Hash Table,Linked List,Two Pointers
Medium
44.1
1,486,657
656,083
7,044
462
null
141,287
143
Reorder List
reorder-list
You are given the head of a singly linked-list. The list can be represented as: Reorder the list to be on the following form: You may not modify the values in the list's nodes. Only nodes themselves may be changed.
Linked List,Two Pointers,Stack,Recursion
Medium
47.6
983,282
468,499
5,689
207
null
2216
144
Binary Tree Preorder Traversal
binary-tree-preorder-traversal
Given the root of a binary tree, return the preorder traversal of its nodes' values.
Stack,Tree,Depth-First Search,Binary Tree
Easy
62.3
1,471,175
917,273
3,931
125
null
94,255,775
145
Binary Tree Postorder Traversal
binary-tree-postorder-traversal
Given the root of a binary tree, return the postorder traversal of its nodes' values.
Stack,Tree,Depth-First Search,Binary Tree
Easy
63.9
1,095,333
699,695
4,035
136
null
94,776
146
LRU Cache
lru-cache
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: The functions get and put must each run in O(1) average time complexity.
Hash Table,Linked List,Design,Doubly-Linked List
Medium
39.7
2,621,253
1,041,470
12,803
498
null
460,588,604,1903
147
Insertion Sort List
insertion-sort-list
Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head. The steps of the insertion sort algorithm: The following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in-place into the sorted list with each iteration.
Linked List,Sorting
Medium
48.8
578,361
282,033
1,974
787
null
148,850
148
Sort List
sort-list
Given the head of a linked list, return the list after sorting it in ascending order.
Linked List,Two Pointers,Divide and Conquer,Sorting,Merge Sort
Medium
51.9
930,950
483,584
6,985
229
null
21,75,147,1992
149
Max Points on a Line
max-points-on-a-line
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.
Array,Hash Table,Math,Geometry
Hard
20.4
1,113,777
226,781
997
176
null
356,2287
150
Evaluate Reverse Polish Notation
evaluate-reverse-polish-notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, and /. Each operand may be an integer or another expression. Note that division between two integers should truncate toward zero. It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.
Array,Math,Stack
Medium
42.3
936,103
396,146
2,884
615
null
224,282
151
Reverse Words in a String
reverse-words-in-a-string
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.
Two Pointers,String
Medium
28.4
2,433,332
690,127
3,004
3,851
null
186
152
Maximum Product Subarray
maximum-product-subarray
Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequence of the array.
Array,Dynamic Programming
Medium
34.5
2,086,147
720,227
11,150
345
null
53,198,238,628,713
153
Find Minimum in Rotated Sorted Array
find-minimum-in-rotated-sorted-array
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]]. Given the sorted rotated array nums of unique elements, return the minimum element of this array. You must write an algorithm that runs in O(log n) time.
Array,Binary Search
Medium
47.9
1,871,809
896,070
6,537
382
Array was originally in ascending order. Now that the array is rotated, there would be a point in the array where there is a small deflection from the increasing sequence. eg. The array would be something like [4, 5, 6, 7, 0, 1, 2]. You can divide the search space into two and see which direction to go. Can you think of an algorithm which has O(logN) search complexity? All the elements to the left of inflection point > first element of the array. All the elements to the right of inflection point < first element of the array.
33,154
154
Find Minimum in Rotated Sorted Array II
find-minimum-in-rotated-sorted-array-ii
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become: Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]]. Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array. You must decrease the overall operation steps as much as possible.
Array,Binary Search
Hard
43.3
744,137
321,946
2,833
367
null
153
155
Min Stack
min-stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class:
Stack,Design
Easy
50.1
1,905,408
953,827
7,800
609
Consider each node in the stack having a minimum value. (Credits to @aakarshmadhavan)
239,716
156
Binary Tree Upside Down
binary-tree-upside-down
null
Tree,Depth-First Search,Binary Tree
Medium
60.2
142,493
85,770
118
211
null
206
157
Read N Characters Given Read4
read-n-characters-given-read4
null
String,Simulation,Interactive
Easy
40.3
416,981
167,934
494
2,967
null
158
158
Read N Characters Given read4 II - Call Multiple Times
read-n-characters-given-read4-ii-call-multiple-times
null
String,Simulation,Interactive
Hard
40.8
403,463
164,563
797
1,650
null
157
159
Longest Substring with At Most Two Distinct Characters
longest-substring-with-at-most-two-distinct-characters
null
Hash Table,String,Sliding Window
Medium
52.6
359,190
188,975
1,676
25
null
3,239,340,1034
160
Intersection of Two Linked Lists
intersection-of-two-linked-lists
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. For example, the following two linked lists begin to intersect at node c1: The test cases are generated such that there are no cycles anywhere in the entire linked structure. Note that the linked lists must retain their original structure after the function returns. Custom Judge: The inputs to the judge are given as follows (your program is not given these inputs): The judge will then create the linked structure based on these inputs and pass the two heads, headA and headB to your program. If you correctly return the intersected node, then your solution will be accepted.
Hash Table,Linked List,Two Pointers
Easy
49.7
1,835,868
912,851
8,536
852
null
599
161
One Edit Distance
one-edit-distance
null
Two Pointers,String
Medium
33.9
505,408
171,423
1,112
164
null
72
162
Find Peak Element
find-peak-element
A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. You must write an algorithm that runs in O(log n) time.
Array,Binary Search
Medium
45.9
1,665,853
764,441
5,815
3,661
null
882,2047,2273,2316
163
Missing Ranges
missing-ranges
null
Array
Easy
31.2
533,983
166,594
759
2,499
null
228
164
Maximum Gap
maximum-gap
Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0. You must write an algorithm that runs in linear time and uses linear extra space.
Array,Sorting,Bucket Sort,Radix Sort
Hard
41.3
333,410
137,727
2,054
281
null
null
165
Compare Version Numbers
compare-version-numbers
Given two version numbers, version1 and version2, compare them. Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example 2.5.33 and 0.1 are valid version numbers. To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their integer value ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, then treat the revision as 0. For example, version 1.0 is less than version 1.1 because their revision 0s are the same, but their revision 1s are 0 and 1 respectively, and 0 < 1. Return the following:
Two Pointers,String
Medium
34.5
908,413
313,170
1,565
2,237
null
null
166
Fraction to Recurring Decimal
fraction-to-recurring-decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. If multiple answers are possible, return any of them. It is guaranteed that the length of the answer string is less than 104 for all the given inputs.
Hash Table,Math,String
Medium
23.6
770,005
181,343
1,555
2,915
No scary math, just apply elementary math knowledge. Still remember how to perform a long division? Try a long division on 4/9, the repeating part is obvious. Now try 4/333. Do you see a pattern? Notice that once the remainder starts repeating, so does the divided result. Be wary of edge cases! List out as many test cases as you can think of and test your code thoroughly.
null
167
Two Sum II - Input Array Is Sorted
two-sum-ii-input-array-is-sorted
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. The tests are generated such that there is exactly one solution. You may not use the same element twice. Your solution must use only constant extra space.
Array,Two Pointers,Binary Search
Medium
58.6
1,583,339
928,226
5,160
923
null
1,653,1083
168
Excel Sheet Column Title
excel-sheet-column-title
Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. For example:
Math,String
Easy
33.8
915,696
309,891
2,707
407
null
171,2304
169
Majority Element
majority-element
Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
Array,Hash Table,Divide and Conquer,Sorting,Counting
Easy
62.8
1,906,897
1,198,357
9,327
333
null
229,1102
170
Two Sum III - Data structure design
two-sum-iii-data-structure-design
null
Array,Hash Table,Two Pointers,Design,Data Stream
Easy
36.7
335,478
123,087
531
367
null
1,288,653
171
Excel Sheet Column Number
excel-sheet-column-number
Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number. For example:
Math,String
Easy
60.6
818,368
495,807
3,221
271
null
168,2304
172
Factorial Trailing Zeroes
factorial-trailing-zeroes
Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.
Math
Medium
40.7
769,195
313,232
1,949
1,657
null
233,809,2222
173
Binary Search Tree Iterator
binary-search-tree-iterator
Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST. You may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.
Stack,Tree,Design,Binary Search Tree,Binary Tree,Iterator
Medium
65.7
799,738
525,235
5,195
362
null
94,251,281,284,285,1729
174
Dungeon Game
dungeon-game
The demons had captured the princess 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 was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess. The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately. Some of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers). To reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step. Return the knight's minimum initial health so that he can rescue the princess. Note that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.
Array,Dynamic Programming,Matrix
Hard
36.4
465,945
169,797
3,977
80
null
62,64,741,2354
175
Combine Two Tables
combine-two-tables
Table: Person Table: Address Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead. Return the result table in any order. The query result format is in the following example.
Database
Easy
70
745,530
521,526
1,864
185
null
577
176
Second Highest Salary
second-highest-salary
Table: Employee Write an SQL query to report the second highest salary from the Employee table. If there is no second highest salary, the query should report null. The query result format is in the following example.
Database
Medium
35.2
1,311,546
462,069
1,761
703
null
null
177
Nth Highest Salary
nth-highest-salary
Table: Employee Write an SQL query to report the nth highest salary from the Employee table. If there is no nth highest salary, the query should report null. The query result format is in the following example.
Database
Medium
36
646,344
232,809
1,024
646
null
2336
178
Rank Scores
rank-scores
Table: Scores Write an SQL query to rank the scores. The ranking should be calculated according to the following rules: Return the result table ordered by score in descending order. The query result format is in the following example.
Database
Medium
57.3
384,697
220,318
1,282
204
null
null
179
Largest Number
largest-number
Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer.
String,Greedy,Sorting
Medium
32.8
950,354
312,186
4,751
400
null
2284
180
Consecutive Numbers
consecutive-numbers
Table: Logs Write an SQL query to find all numbers that appear at least three times consecutively. Return the result table in any order. The query result format is in the following example.
Database
Medium
45.6
405,173
184,561
971
187
null
null
181
Employees Earning More Than Their Managers
employees-earning-more-than-their-managers
Table: Employee Write an SQL query to find the employees who earn more than their managers. Return the result table in any order. The query result format is in the following example.
Database
Easy
66.2
528,367
349,741
1,341
152
null
null
182
Duplicate Emails
duplicate-emails
Table: Person Write an SQL query to report all the duplicate emails. Return the result table in any order. The query result format is in the following example.
Database
Easy
68.8
500,539
344,202
1,034
46
null
null
183
Customers Who Never Order
customers-who-never-order
Table: Customers Table: Orders Write an SQL query to report all customers who never order anything. Return the result table in any order. The query result format is in the following example.
Database
Easy
62.8
528,374
332,018
906
72
null
null
184
Department Highest Salary
department-highest-salary
Table: Employee Table: Department Write an SQL query to find employees who have the highest salary in each of the departments. Return the result table in any order. The query result format is in the following example.
Database
Medium
46.7
464,334
216,861
1,076
163
null
1214
185
Department Top Three Salaries
department-top-three-salaries
Table: Employee Table: Department A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department. Write an SQL query to find the employees who are high earners in each of the departments. Return the result table in any order. The query result format is in the following example.
Database
Hard
46.9
348,161
163,363
1,055
181
null
null
186
Reverse Words in a String II
reverse-words-in-a-string-ii
null
Two Pointers,String
Medium
50.9
259,329
131,874
840
127
null
151,189
187
Repeated DNA Sequences
repeated-dna-sequences
The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. When studying DNA, it is useful to identify repeated sequences within the DNA. Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.
Hash Table,String,Bit Manipulation,Sliding Window,Rolling Hash,Hash Function
Medium
44.6
587,059
261,815
1,945
406
null
null
188
Best Time to Buy and Sell Stock IV
best-time-to-buy-and-sell-stock-iv
You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k. Find the maximum profit you can achieve. You may complete at most k transactions. Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
Array,Dynamic Programming
Hard
33.5
716,430
239,980
3,790
152
null
121,122,123
189
Rotate Array
rotate-array
Given an array, rotate the array to the right by k steps, where k is non-negative.
Array,Math,Two Pointers
Medium
38.5
2,796,554
1,077,386
9,117
1,268
The easiest solution would use additional memory and that is perfectly fine. The actual trick comes when trying to solve this problem without using any additional memory. This means you need to use the original array somehow to move the elements around. Now, we can place each element in its original location and shift all the elements around it to adjust as that would be too costly and most likely will time out on larger input arrays. One line of thought is based on reversing the array (or parts of it) to obtain the desired result. Think about how reversal might potentially help us out by using an example. The other line of thought is a tad bit complicated but essentially it builds on the idea of placing each element in its original position while keeping track of the element originally in that position. Basically, at every step, we place an element in its rightful position and keep track of the element already there or the one being overwritten in an additional variable. We can't do this in one linear pass and the idea here is based on cyclic-dependencies between elements.
61,186
190
Reverse Bits
reverse-bits
Reverse bits of a given 32 bits unsigned integer. Note:
Divide and Conquer,Bit Manipulation
Easy
48.6
944,361
459,430
2,939
789
null
7,191,2238
191
Number of 1 Bits
number-of-1-bits
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Note:
Bit Manipulation
Easy
60.2
1,157,530
697,346
2,922
785
null
190,231,338,401,461,693,767
192
Word Frequency
word-frequency
Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity sake, you may assume: Example: Assume that words.txt has the following content: Your script should output the following, sorted by descending frequency: Note:
Shell
Medium
25.6
143,923
36,852
362
239
null
347
193
Valid Phone Numbers
valid-phone-numbers
Given a text file file.txt that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers. You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit) You may also assume each line in the text file must not contain leading or trailing white spaces. Example: Assume that file.txt has the following content: Your script should output the following valid phone numbers:
Shell
Easy
25.8
213,440
55,140
265
704
null
null
194
Transpose File
transpose-file
Given a text file file.txt, transpose its content. You may assume that each row has the same number of columns, and each field is separated by the ' ' character. Example: If file.txt has the following content: Output the following:
Shell
Medium
25
72,692
18,204
105
241
null
null
195
Tenth Line
tenth-line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has the following content: Your script should output the tenth line, which is:
Shell
Easy
32.9
220,761
72,559
259
336
null
null
196
Delete Duplicate Emails
delete-duplicate-emails
Table: Person Write an SQL query to delete all the duplicate emails, keeping only one unique email with the smallest id. Note that you are supposed to write a DELETE statement and not a SELECT one. Return the result table in any order. The query result format is in the following example.
Database
Easy
51.9
408,492
211,951
62
18
null
null
197
Rising Temperature
rising-temperature
Table: Weather Write an SQL query to find all dates' Id with higher temperatures compared to its previous dates (yesterday). Return the result table in any order. The query result format is in the following example.
Database
Easy
42.4
511,091
216,573
849
349
null
null
198
House Robber
house-robber
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 from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night. 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.
Array,Dynamic Programming
Medium
47
2,334,058
1,098,090
11,854
255
null
152,213,256,276,337,600,656,740,2262
199
Binary Tree Right Side View
binary-tree-right-side-view
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.
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
59.5
1,098,642
653,709
6,288
337
null
116,545
200
Number of Islands
number-of-islands
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. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Array,Depth-First Search,Breadth-First Search,Union Find,Matrix
Medium
53.8
2,825,342
1,518,896
13,254
320
null
130,286,305,323,694,695,2035,2103