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
⌀ |
---|---|---|---|---|---|---|---|---|---|---|---|---|
510 | Count Subarrays With More Ones Than Zeros | count-subarrays-with-more-ones-than-zeros | null | Array,Binary Search,Divide and Conquer,Binary Indexed Tree,Segment Tree,Merge Sort,Ordered Set | Medium | 53.6 | 2,799 | 1,499 | 81 | 5 | Change the zeros in nums to -1 and create a prefix sum array prefixSum using the new nums. If prefixSum[i] for any index i in the range 0 <= i < prefixSum.length is positive, that means that there are more ones than zeros in the prefix ending at index i. If prefixSum[j] > prefixSum[i] for two indexes i and j such that 0 <= i < j < prefixSum.length, that means that there are more ones than zeros in nums in the range [i + 1 : j] (inclusive) | 474,1999,2261 |
511 | All Paths from Source Lead to Destination | all-paths-from-source-lead-to-destination | null | Depth-First Search,Graph | Medium | 41.9 | 86,687 | 36,343 | 481 | 120 | What if we can reach to a cycle from the source node? Then the answer will be false, because we eventually get trapped in the cycle forever. What if the we can't reach to a cycle from the source node? Then we need to ensure that from all visited nodes from source the unique node with indegree = 0 is the destination node. | null |
512 | Maximum Alternating Subarray Sum | maximum-alternating-subarray-sum | null | Array,Dynamic Programming | Medium | 41 | 2,668 | 1,093 | 42 | 2 | How can Kadane's Algorithm help us? If you convert all the numbers at odd indices to the negative version of that number, the problem simplifies to finding the maximum subarray sum. However, this strategy needs you to start each subarray at an even index. Do the same except converting all the numbers at even indices to the negative version of that number. | 2022 |
513 | Find Bottom Left Tree Value | find-bottom-left-tree-value | Given the root of a binary tree, return the leftmost value in the last row of the tree. | Tree,Depth-First Search,Breadth-First Search,Binary Tree | Medium | 65.2 | 259,658 | 169,188 | 2,052 | 213 | null | null |
514 | Freedom Trail | freedom-trail | In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door. Given a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword. Initially, the first character of the ring is aligned at the "12:00" direction. You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the "12:00" direction and then by pressing the center button. At the stage of rotating the ring to spell the key character key[i]: | String,Dynamic Programming,Depth-First Search,Breadth-First Search | Hard | 46.2 | 58,661 | 27,099 | 682 | 32 | null | null |
515 | Find Largest Value in Each Tree Row | find-largest-value-in-each-tree-row | Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). | Tree,Depth-First Search,Breadth-First Search,Binary Tree | Medium | 64.4 | 291,567 | 187,850 | 1,980 | 82 | null | null |
516 | Longest Palindromic Subsequence | longest-palindromic-subsequence | Given a string s, find the longest palindromic subsequence's length in s. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. | String,Dynamic Programming | Medium | 59.3 | 418,537 | 248,026 | 5,039 | 246 | null | 5,647,730,1250,1822,1897,2130 |
517 | Super Washing Machines | super-washing-machines | You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time. Given an integer array machines representing the number of dresses in each washing machine from left to right on the line, return the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1. | Array,Greedy | Hard | 39.4 | 55,433 | 21,827 | 530 | 178 | null | null |
518 | Coin Change 2 | coin-change-2 | You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0. You may assume that you have an infinite number of each kind of coin. The answer is guaranteed to fit into a signed 32-bit integer. | Array,Dynamic Programming | Medium | 57.4 | 497,918 | 285,578 | 5,010 | 100 | null | 1393 |
519 | Widest Pair of Indices With Equal Range Sum | widest-pair-of-indices-with-equal-range-sum | null | Array,Hash Table,Prefix Sum | Medium | 53.8 | 2,054 | 1,105 | 44 | 0 | Keep prefix sums of both arrays. Can the difference between the prefix sums at an index help us? What happens if the difference between the two prefix sums at an index a is x, and x again at a different index b? This means that the sum of nums1 from index a + 1 to index b is equal to the sum of nums2 from index a + 1 to index b. | null |
520 | Detect Capital | detect-capital | We define the usage of capitals in a word to be right when one of the following cases holds: Given a string word, return true if the usage of capitals in it is right. | String | Easy | 55.7 | 469,204 | 261,331 | 1,587 | 362 | null | 2235 |
521 | Longest Uncommon Subsequence I | longest-uncommon-subsequence-i | Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1. An uncommon subsequence between two strings is a string that is a subsequence of one but not the other. A subsequence of a string s is a string that can be obtained after deleting any number of characters from s. | String | Easy | 60.1 | 138,850 | 83,443 | 570 | 5,566 | null | 522 |
522 | Longest Uncommon Subsequence II | longest-uncommon-subsequence-ii | Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1. An uncommon subsequence between an array of strings is a string that is a subsequence of one string but not the others. A subsequence of a string s is a string that can be obtained after deleting any number of characters from s. | Array,Hash Table,Two Pointers,String,Sorting | Medium | 40.1 | 106,746 | 42,789 | 367 | 1,065 | null | 521 |
523 | Continuous Subarray Sum | continuous-subarray-sum | Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least two whose elements sum up to a multiple of k, or false otherwise. An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k. | Array,Hash Table,Math,Prefix Sum | Medium | 27.2 | 1,047,671 | 285,001 | 1,762 | 245 | null | 560,2119,2240 |
524 | Longest Word in Dictionary through Deleting | longest-word-in-dictionary-through-deleting | Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string. | Array,Two Pointers,String,Sorting | Medium | 50.9 | 245,280 | 124,739 | 1,308 | 329 | null | 720 |
525 | Contiguous Array | contiguous-array | Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1. | Array,Hash Table,Prefix Sum | Medium | 46.3 | 558,046 | 258,336 | 5,250 | 227 | null | 325 |
526 | Beautiful Arrangement | beautiful-arrangement | Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true: Given an integer n, return the number of the beautiful arrangements that you can construct. | Array,Dynamic Programming,Backtracking,Bit Manipulation,Bitmask | Medium | 64.3 | 198,648 | 127,756 | 2,108 | 285 | null | 667 |
527 | Word Abbreviation | word-abbreviation | null | Array,String,Greedy,Trie,Sorting | Hard | 58.2 | 37,374 | 21,743 | 295 | 201 | null | 408,411 |
528 | Swapping Nodes in a Linked List | swapping-nodes-in-a-linked-list | You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed). | Linked List,Two Pointers | Medium | 68.4 | 229,189 | 156,841 | 2,691 | 100 | We can transform the linked list to an array this should ease things up After transforming the linked list to an array it becomes as easy as swapping two integers in an array then rebuilding the linked list | 19,24,25 |
529 | Minesweeper | minesweeper | Let's play the minesweeper game (Wikipedia, online game)! You are given an m x n char matrix board representing the game board where: You are also given an integer array click where click = [clickr, clickc] represents the next click position among all the unrevealed squares ('M' or 'E'). Return the board after revealing this position according to the following rules: | Array,Depth-First Search,Breadth-First Search,Matrix | Medium | 64.6 | 177,100 | 114,403 | 1,367 | 856 | null | 2206 |
530 | Minimum Absolute Difference in BST | minimum-absolute-difference-in-bst | Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. | Tree,Depth-First Search,Breadth-First Search,Binary Search Tree,Binary Tree | Easy | 56.2 | 273,418 | 153,691 | 1,994 | 117 | null | 532 |
531 | Lonely Pixel I | lonely-pixel-i | null | Array,Hash Table,Matrix | Medium | 60.7 | 50,446 | 30,598 | 298 | 35 | null | 533 |
532 | K-diff Pairs in an Array | k-diff-pairs-in-an-array | Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true: Notice that |val| denotes the absolute value of val. | Array,Hash Table,Two Pointers,Binary Search,Sorting | Medium | 40.1 | 625,811 | 250,865 | 2,553 | 2,046 | null | 530,2116,2150 |
533 | Lonely Pixel II | lonely-pixel-ii | null | Array,Hash Table,Matrix | Medium | 48.3 | 24,738 | 11,958 | 72 | 677 | null | 531 |
535 | Encode and Decode TinyURL | encode-and-decode-tinyurl | TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL. Implement the Solution class: | Hash Table,String,Design,Hash Function | Medium | 83.5 | 198,307 | 165,512 | 1,156 | 2,208 | null | null |
536 | Construct Binary Tree from String | construct-binary-tree-from-string | null | String,Tree,Depth-First Search,Binary Tree | Medium | 55.8 | 135,136 | 75,369 | 899 | 146 | null | 606 |
537 | Complex Number Multiplication | complex-number-multiplication | A complex number can be represented as a string on the form "real+imaginaryi" where: Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications. | Math,String,Simulation | Medium | 71.1 | 113,274 | 80,542 | 503 | 1,123 | null | null |
538 | Convert BST to Greater Tree | convert-bst-to-greater-tree | Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST. As a reminder, a binary search tree is a tree that satisfies these constraints: | Tree,Depth-First Search,Binary Search Tree,Binary Tree | Medium | 65.4 | 346,698 | 226,818 | 4,014 | 158 | null | null |
539 | Minimum Time Difference | minimum-time-difference | null | Array,Math,String,Sorting | Medium | 54.7 | 153,278 | 83,767 | 1,005 | 199 | null | 2266 |
540 | Single Element in a Sorted Array | single-element-in-a-sorted-array | You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element that appears only once. Your solution must run in O(log n) time and O(1) space. | Array,Binary Search | Medium | 58.7 | 484,707 | 284,425 | 4,963 | 111 | null | null |
541 | Reverse String II | reverse-string-ii | Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original. | Two Pointers,String | Easy | 50.1 | 297,991 | 149,401 | 952 | 2,363 | null | 344,557 |
542 | 01 Matrix | 01-matrix | Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. | Array,Dynamic Programming,Breadth-First Search,Matrix | Medium | 43.8 | 534,554 | 233,903 | 4,442 | 221 | null | 550,2259 |
543 | Diameter of Binary Tree | diameter-of-binary-tree | Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. The length of a path between two nodes is represented by the number of edges between them. | Tree,Depth-First Search,Binary Tree | Easy | 54.1 | 1,310,070 | 708,322 | 7,587 | 481 | null | 1665 |
544 | Output Contest Matches | output-contest-matches | null | String,Recursion,Simulation | Medium | 76.5 | 32,253 | 24,659 | 356 | 115 | null | null |
545 | Boundary of Binary Tree | boundary-of-binary-tree | null | Tree,Depth-First Search,Binary Tree | Medium | 43.1 | 228,707 | 98,538 | 1,036 | 1,680 | null | 199 |
546 | Remove Boxes | remove-boxes | You are given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k points. Return the maximum points you can get. | Array,Dynamic Programming,Memoization | Hard | 47.3 | 71,483 | 33,844 | 1,491 | 92 | null | 664,2247 |
547 | Number of Provinces | number-of-provinces | There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c. A province is a group of directly or indirectly connected cities and no other cities outside of the group. You are given an n x n matrix isConnected where isConnected[i][j] = 1 if the ith city and the jth city are directly connected, and isConnected[i][j] = 0 otherwise. Return the total number of provinces. | Depth-First Search,Breadth-First Search,Union Find,Graph | Medium | 62.6 | 713,510 | 446,459 | 4,990 | 235 | null | 323,657,734,737,1085,2206 |
548 | Split Array with Equal Sum | split-array-with-equal-sum | null | Array,Prefix Sum | Hard | 49.8 | 44,249 | 22,021 | 382 | 126 | null | 1678 |
549 | Binary Tree Longest Consecutive Sequence II | binary-tree-longest-consecutive-sequence-ii | null | Tree,Depth-First Search,Binary Tree | Medium | 48.6 | 86,574 | 42,036 | 899 | 72 | null | 298,1416 |
550 | Shortest Path to Get Food | shortest-path-to-get-food | null | Array,Breadth-First Search,Matrix | Medium | 54.3 | 53,077 | 28,812 | 361 | 16 | Run BFS starting from the '*' position. Keep the current number of the steps as a state in the queue. The first time you reach a food, return the number of steps as the answer. In case the queue is empty and you still did not manage to reach a food, return -1. | 542,1414 |
551 | Student Attendance Record I | student-attendance-record-i | You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters: The student is eligible for an attendance award if they meet both of the following criteria: Return true if the student is eligible for an attendance award, or false otherwise. | String | Easy | 47.6 | 297,556 | 141,541 | 285 | 16 | null | 552 |
552 | Student Attendance Record II | student-attendance-record-ii | An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters: Any student is eligible for an attendance award if they meet both of the following criteria: Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award. The answer may be very large, so return it modulo 109 + 7. | Dynamic Programming | Hard | 40.5 | 113,522 | 45,966 | 1,159 | 196 | null | 551 |
553 | Optimal Division | optimal-division | You are given an integer array nums. The adjacent integers in nums will perform the float division. However, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum. Return the corresponding expression that has the maximum value in string format. Note: your expression should not contain redundant parenthesis. | Array,Math,Dynamic Programming | Medium | 59 | 53,447 | 31,520 | 265 | 1,380 | null | null |
554 | Brick Wall | brick-wall | There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same. Draw a vertical line from the top to the bottom and cross the least bricks. If your line goes through the edge of a brick, then the brick is not considered as crossed. You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks. Given the 2D array wall that contains the information about the wall, return the minimum number of crossed bricks after drawing such a vertical line. | Array,Hash Table | Medium | 52.6 | 189,678 | 99,768 | 1,789 | 101 | null | 2322 |
555 | Split Concatenated Strings | split-concatenated-strings | null | Array,String,Greedy | Medium | 43.2 | 13,680 | 5,912 | 62 | 238 | null | null |
556 | Next Greater Element III | next-greater-element-iii | Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1. Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1. | Math,Two Pointers,String | Medium | 33.8 | 285,936 | 96,588 | 2,171 | 342 | null | 496,503,1997 |
557 | Reverse Words in a String III | reverse-words-in-a-string-iii | Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. | Two Pointers,String | Easy | 78.5 | 548,465 | 430,729 | 2,698 | 160 | null | 541 |
560 | Subarray Sum Equals K | subarray-sum-equals-k | Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. | Array,Hash Table,Prefix Sum | Medium | 44.2 | 1,715,764 | 758,711 | 12,822 | 409 | Will Brute force work here? Try to optimize it. Can we optimize it by using some extra space? What about storing sum frequencies in a hash table? Will it be useful? sum(i,j)=sum(0,j)-sum(0,i), where sum(i,j) represents the sum of all the elements from index i to j-1.
Can we use this property to optimize it. | 1,523,713,724,1016,1776,2211,2369 |
561 | Array Partition I | array-partition-i | Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. | Array,Greedy,Sorting,Counting Sort | Easy | 75.6 | 427,183 | 322,789 | 780 | 132 | Obviously, brute force won't help here. Think of something else, take some example like 1,2,3,4. How will you make pairs to get the result? There must be some pattern. Did you observe that- Minimum element gets add into the result in sacrifice of maximum element. Still won't able to find pairs? Sort the array and try to find the pattern. | 2112,2248,2261 |
562 | Longest Line of Consecutive One in Matrix | longest-line-of-consecutive-one-in-matrix | null | Array,Dynamic Programming,Matrix | Medium | 49.1 | 117,977 | 57,914 | 695 | 97 | One solution is to count ones in each direction separately and find the longest line. Don't you think it will take too much lines of code? Is it possible to use some extra space to make the solution simple? Can we use dynamic programming to make use of intermediate results? Think of a 3D array which can be used to store the longest line obtained so far for each direction. | null |
563 | Binary Tree Tilt | binary-tree-tilt | Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if the node does not have a right child. | Tree,Depth-First Search,Binary Tree | Easy | 58.5 | 282,699 | 165,284 | 1,601 | 1,903 | Don't think too much, this is an easy problem. Take some small tree as an example. Can a parent node use the values of its child nodes? How will you implement it? May be recursion and tree traversal can help you in implementing. What about postorder traversal, using values of left and right childs? | 1609 |
564 | Find the Closest Palindrome | find-the-closest-palindrome | Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one. The closest is defined as the absolute difference minimized between two integers. | Math,String | Hard | 21.2 | 145,985 | 31,011 | 474 | 1,117 | Will brute force work for this problem? Think of something else. Take some examples like 1234, 999,1000, etc and check their closest palindromes. How many different cases are possible? Do we have to consider only left half or right half of the string or both? Try to find the closest palindrome of these numbers- 12932, 99800, 12120. Did you observe something? | 1375,1997 |
565 | Array Nesting | array-nesting | You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1]. You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the following rule: Return the longest length of a set s[k]. | Array,Depth-First Search | Medium | 56.3 | 200,038 | 112,566 | 1,833 | 138 | null | 339,341,364 |
566 | Reshape the Matrix | reshape-the-matrix | In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data. You are given an m x n matrix mat and two integers r and c representing the number of rows and the number of columns of the wanted reshaped matrix. The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were. If the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix. | Array,Matrix,Simulation | Easy | 62.4 | 365,645 | 228,101 | 2,155 | 243 | Do you know how 2d matrix is stored in 1d memory? Try to map 2-dimensions into one. M[i][j]=M[n*i+j] , where n is the number of cols.
This is the one way of converting 2-d indices into one 1-d index.
Now, how will you convert 1-d index into 2-d indices? Try to use division and modulus to convert 1-d index into 2-d indices. M[i] => M[i/n][i%n] Will it result in right mapping? Take some example and check this formula. | 2132 |
567 | Permutation in String | permutation-in-string | Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutations is the substring of s2. | Hash Table,Two Pointers,String,Sliding Window | Medium | 44.8 | 824,372 | 369,629 | 5,663 | 164 | Obviously, brute force will result in TLE. Think of something else. How will you check whether one string is a permutation of another string? One way is to sort the string and then compare. But, Is there a better way? If one string is a permutation of another string then they must one common metric. What is that? Both strings must have same character frequencies, if one is permutation of another. Which data structure should be used to store frequencies? What about hash table? An array of size 26? | 76,438 |
568 | Maximum Vacation Days | maximum-vacation-days | null | Array,Dynamic Programming,Matrix | Hard | 44.3 | 75,981 | 33,686 | 502 | 92 | First try to understand the problem carefully and then take some example and solve it on a paper. Can you interpret the given input as a graph? Which graph traversal technique is suitable here? Can we use some space to avoid redundant function calls? | 803 |
569 | Median Employee Salary | median-employee-salary | null | Database | Hard | 66.6 | 40,172 | 26,766 | 228 | 124 | Still remember how to select the sum which group by one column? Try to think about how to get the median from a sorted list. How to get the median one item for odd number list while how to get the median two items for even number list, try to unify them. | 571 |
570 | Managers with at Least 5 Direct Reports | managers-with-at-least-5-direct-reports | null | Database | Medium | 66.9 | 85,217 | 57,047 | 218 | 31 | Try to get all the mangerIDs that have count bigger than 5 Use the last hint's result as a table and do join with origin table at id equals to managerId This is a very good example to show the performance of SQL code. Try to work out other solutions and you may be surprised by running time difference. If your solution uses 'IN' function and runs more than 5 seconds, try to optimize it by using 'JOIN' instead. | null |
571 | Find Median Given Frequency of Numbers | find-median-given-frequency-of-numbers | null | Database | Hard | 44.5 | 41,801 | 18,601 | 221 | 63 | null | 569 |
572 | Subtree of Another Tree | subtree-of-another-tree | Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself. | Tree,Depth-First Search,String Matching,Binary Tree,Hash Function | Easy | 45.3 | 996,628 | 451,495 | 5,105 | 265 | Which approach is better here- recursive or iterative? If recursive approach is better, can you write recursive function with its parameters? Two trees s and t are said to be identical if their root values are same and their left and right subtrees are identical. Can you write this in form of recursive formulae? Recursive formulae can be:
isIdentical(s,t)= s.val==t.val AND isIdentical(s.left,t.left) AND isIdentical(s.right,t.right) | 250,508 |
573 | Squirrel Simulation | squirrel-simulation | null | Array,Math | Medium | 54.6 | 30,992 | 16,937 | 306 | 33 | Will Brute force solution works here? What will be its complexity? Brute force definitely won't work here. Think of some simple solution. Take some example and make some observations. Will order of nuts traversed by squirrel is important or only first nut traversed by squirrel is important? Are there some paths which squirrel have to cover in any case? If yes, what are they? Did you notice only first nut traversed by squirrel matters? Obviously squirrel will choose first nut which will result in minimum distance. | null |
574 | Winning Candidate | winning-candidate | null | Database | Medium | 58.2 | 78,268 | 45,527 | 127 | 381 | null | null |
575 | Distribute Candies | distribute-candies | Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice. Given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them. | Array,Hash Table | Easy | 65.6 | 308,181 | 202,137 | 936 | 1,147 | To maximize the number of kinds of candies, we should try to distribute candies such that sister will gain all kinds. What is the upper limit of the number of kinds of candies sister will gain? Remember candies are to distributed equally. Which data structure is the most suitable for finding the number of kinds of candies? Will hashset solves the problem? Inserting all candies kind in the hashset and then checking its size with upper limit. | null |
576 | Out of Boundary Paths | out-of-boundary-paths | There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball. Given the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 109 + 7. | Dynamic Programming | Medium | 40.1 | 157,850 | 63,268 | 1,475 | 182 | Is traversing every path feasible? There are many possible paths for a small matrix. Try to optimize it. Can we use some space to store the number of paths and update them after every move? One obvious thing: the ball will go out of the boundary only by crossing it. Also, there is only one possible way the ball can go out of the boundary from the boundary cell except for corner cells. From the corner cell, the ball can go out in two different ways.
Can you use this thing to solve the problem? | 688,2239 |
577 | Employee Bonus | employee-bonus | null | Database | Easy | 74.7 | 77,789 | 58,105 | 159 | 89 | If the EmpId in table Employee has no match in table Bonus, we consider that the corresponding bonus is null and null is smaller than 1000. Inner join is the default join, we can solve the mismatching problem by using outer join. | 175 |
578 | Get Highest Answer Rate Question | get-highest-answer-rate-question | null | Database | Medium | 42.9 | 92,016 | 39,469 | 86 | 809 | Try to find all question ids by group Try to find each group answer number and show number. Rank all the rates (answer/(answer+show)) and return the max one | null |
579 | Find Cumulative Salary of an Employee | find-cumulative-salary-of-an-employee | null | Database | Hard | 42.8 | 59,875 | 25,635 | 173 | 375 | Seem hard at first glance? Try to divide this problem into some sub-problems.
Think about how to calculate the cumulative sum of one employee, how to get the cumulative sum for many employees, and how to except the most recent month of the result. Use the technique of self-join if you have only one table but to write a complex query. Still remember how to use the function `sum` and `max`? | null |
580 | Count Student Number in Departments | count-student-number-in-departments | null | Database | Medium | 56.5 | 77,484 | 43,811 | 184 | 30 | Still remember the difference between 'INNER JOIN' and 'OUTTER JOIN' in SQL? Do you know other expressions using the 'COUNT' function besides 'COUNT(*)'? | null |
581 | Shortest Unsorted Continuous Subarray | shortest-unsorted-continuous-subarray | Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order. Return the shortest such subarray and output its length. | Array,Two Pointers,Stack,Greedy,Sorting,Monotonic Stack | Medium | 34.2 | 631,258 | 215,582 | 4,950 | 201 | null | null |
582 | Kill Process | kill-process | null | Array,Hash Table,Tree,Depth-First Search,Breadth-First Search | Medium | 66.9 | 97,653 | 65,300 | 886 | 17 | null | null |
583 | Delete Operation for Two Strings | delete-operation-for-two-strings | Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same. In one step, you can delete exactly one character in either string. | String,Dynamic Programming | Medium | 55.7 | 203,295 | 113,212 | 2,708 | 45 | null | 72,712,1250 |
584 | Find Customer Referee | find-customer-referee | Table: Customer Write an SQL query to report the IDs of the customer that are not referred by the customer with id = 2. Return the result table in any order. The query result format is in the following example. | Database | Easy | 77 | 78,389 | 60,330 | 198 | 113 | Be careful of the NULL value | null |
585 | Investments in 2016 | investments-in-2016 | null | Database | Medium | 55 | 58,357 | 32,099 | 192 | 200 | Make the (LAT, LON) a pair to represent the location information | null |
586 | Customer Placing the Largest Number of Orders | customer-placing-the-largest-number-of-orders | Table: Orders Write an SQL query to find the customer_number for the customer who has placed the largest number of orders. The test cases are generated so that exactly one customer will have placed more orders than any other customer. The query result format is in the following example. | Database | Easy | 74.3 | 92,168 | 68,512 | 235 | 21 | MySQL uses a different expression to get the first records other than MSSQL's TOP expression. | null |
587 | Erect the Fence | erect-the-fence | You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden. You are asked to fence the entire garden using the minimum length of rope as it is expensive. The garden is well fenced only if all the trees are enclosed. Return the coordinates of trees that are exactly located on the fence perimeter. | Array,Math,Geometry | Hard | 43.2 | 55,809 | 24,131 | 550 | 344 | null | 2074 |
588 | Design In-Memory File System | design-in-memory-file-system | null | Hash Table,String,Design,Trie | Hard | 48.3 | 130,148 | 62,873 | 1,042 | 123 | null | 146,460,635 |
591 | Tag Validator | tag-validator | Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid. A code snippet is valid if all the following rules hold: | String,Stack | Hard | 36.4 | 30,498 | 11,096 | 130 | 560 | null | 616 |
592 | Fraction Addition and Subtraction | fraction-addition-and-subtraction | Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format. The final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1. | Math,String,Simulation | Medium | 51.7 | 55,560 | 28,714 | 303 | 435 | null | 640 |
593 | Valid Square | valid-square | Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order. A valid square has four equal sides with positive length and four equal angles (90-degree angles). | Math,Geometry | Medium | 43.8 | 186,845 | 81,890 | 674 | 739 | null | null |
594 | Longest Harmonious Subsequence | longest-harmonious-subsequence | We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1. Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences. A subsequence of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. | Array,Hash Table,Sorting | Easy | 52.6 | 217,843 | 114,669 | 1,522 | 151 | null | null |
595 | Big Countries | big-countries | Table: World A country is big if: Write an SQL query to report the name, population, and area of the big countries. Return the result table in any order. The query result format is in the following example. | Database | Easy | 77.3 | 355,541 | 274,906 | 778 | 896 | null | null |
596 | Classes More Than 5 Students | classes-more-than-5-students | Table: Courses Write an SQL query to report all the classes that have at least five students. Return the result table in any order. The query result format is in the following example. | Database | Easy | 42.4 | 369,293 | 156,624 | 429 | 907 | null | null |
597 | Friend Requests I: Overall Acceptance Rate | friend-requests-i-overall-acceptance-rate | null | Database | Easy | 42.6 | 133,759 | 57,020 | 235 | 581 | Still remember how to count the number of rows in a table? What is the keyword to filter the duplicated records in a table? | null |
598 | Range Addition II | range-addition-ii | You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi. Count and return the number of maximum integers in the matrix after performing all the operations. | Array,Math | Easy | 54.7 | 141,345 | 77,261 | 649 | 803 | null | 370 |
599 | Minimum Index Sum of Two Lists | minimum-index-sum-of-two-lists | Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer. | Array,Hash Table,String | Easy | 52.8 | 279,803 | 147,774 | 1,170 | 318 | null | 160 |
600 | Non-negative Integers without Consecutive Ones | non-negative-integers-without-consecutive-ones | Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones. | Dynamic Programming | Hard | 38.8 | 78,458 | 30,430 | 1,055 | 114 | null | 198,213,474 |
601 | Human Traffic of Stadium | human-traffic-of-stadium | Table: Stadium Write an SQL query to display the records with three or more rows with consecutive id's, and the number of people is greater than or equal to 100 for each. Return the result table ordered by visit_date in ascending order. The query result format is in the following example. | Database | Hard | 49.5 | 122,010 | 60,401 | 338 | 480 | null | null |
602 | Friend Requests II: Who Has the Most Friends | friend-requests-ii-who-has-the-most-friends | null | Database | Medium | 60.7 | 79,962 | 48,563 | 248 | 73 | Being friends is bidirectional. If you accept someone's adding friend request, both you and the other person will have one more friend. | null |
603 | Consecutive Available Seats | consecutive-available-seats | null | Database | Easy | 67.8 | 80,558 | 54,624 | 456 | 40 | null | null |
604 | Design Compressed String Iterator | design-compressed-string-iterator | null | Array,Hash Table,String,Design,Iterator | Easy | 39.1 | 66,766 | 26,081 | 358 | 124 | null | 146,443 |
605 | Can Place Flowers | can-place-flowers | You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule. | Array,Greedy | Easy | 33.1 | 874,930 | 289,310 | 2,857 | 641 | null | 495,735 |
606 | Construct String from Binary Tree | construct-string-from-binary-tree | Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree. | String,Tree,Depth-First Search,Binary Tree | Easy | 57.6 | 220,994 | 127,369 | 1,343 | 1,714 | null | 536,652 |
607 | Sales Person | sales-person | Table: SalesPerson Table: Company Table: Orders Write an SQL query to report the names of all the salespersons who did not have any orders related to the company with the name "RED". Return the result table in any order. The query result format is in the following example. | Database | Easy | 68.6 | 76,777 | 52,667 | 268 | 48 | You need to query who sold to company 'RED' first, then output the sales person who is not in the first query result. | null |
608 | Tree Node | tree-node | Table: Tree Each node in the tree can be one of three types: Write an SQL query to report the type of each node in the tree. Return the result table ordered by id in ascending order. The query result format is in the following example. | Database | Medium | 72 | 62,167 | 44,777 | 364 | 32 | You can judge the node type by querying whether the node's id shows up in p_id column and whether the node's p_id is null. | null |
609 | Find Duplicate File in System | find-duplicate-file-in-system | Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order. A group of duplicate files consists of at least two files that have the same content. A single directory info string in the input list has the following format: It means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory "root/d1/d2/.../dm". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory. The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format: | Array,Hash Table,String | Medium | 63.8 | 148,776 | 94,858 | 808 | 916 | null | 2079 |
610 | Triangle Judgement | triangle-judgement | null | Database | Easy | 70.8 | 69,971 | 49,574 | 211 | 50 | null | null |
611 | Valid Triangle Number | valid-triangle-number | Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. | Array,Two Pointers,Binary Search,Greedy,Sorting | Medium | 49.7 | 270,227 | 134,273 | 2,468 | 150 | null | 259 |
612 | Shortest Distance in a Plane | shortest-distance-in-a-plane | null | Database | Medium | 63.1 | 47,090 | 29,715 | 168 | 60 | null | null |
613 | Shortest Distance in a Line | shortest-distance-in-a-line | null | Database | Easy | 81.1 | 61,858 | 50,158 | 250 | 35 | null | null |
614 | Second Degree Follower | second-degree-follower | null | Database | Medium | 35.5 | 110,233 | 39,114 | 117 | 697 | null | null |