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
⌀ |
---|---|---|---|---|---|---|---|---|---|---|---|---|
401 | Binary Watch | binary-watch | A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. Given an integer turnedOn which represents the number of LEDs that are currently on, return all possible times the watch could represent. You may return the answer in any order. The hour must not contain a leading zero. The minute must be consist of two digits and may contain a leading zero. | Backtracking,Bit Manipulation | Easy | 50.4 | 215,786 | 108,789 | 935 | 1,753 | Simplify by seeking for solutions that involve comparing bit counts. Consider calculating all possible times for comparison purposes. | 17,191 |
402 | Remove K Digits | remove-k-digits | Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num. | String,Stack,Greedy,Monotonic Stack | Medium | 30.5 | 849,382 | 258,935 | 5,963 | 249 | null | 321,738,1792,2305 |
403 | Frog Jump | frog-jump | A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water. Given a list of stones' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit. If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction. | Array,Dynamic Programming | Hard | 42.9 | 353,218 | 151,515 | 2,448 | 160 | null | 1952,2262 |
404 | Sum of Left Leaves | sum-of-left-leaves | Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. | Tree,Depth-First Search,Breadth-First Search,Binary Tree | Easy | 55 | 621,755 | 341,893 | 3,236 | 244 | null | null |
405 | Convert a Number to Hexadecimal | convert-a-number-to-hexadecimal | Given an integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself. Note: You are not allowed to use any built-in library method to directly solve this problem. | Math,Bit Manipulation | Easy | 45.7 | 212,775 | 97,344 | 862 | 169 | null | null |
406 | Queue Reconstruction by Height | queue-reconstruction-by-height | You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi. Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] is the person at the front of the queue). | Array,Greedy,Binary Indexed Tree,Segment Tree,Sorting | Medium | 70.1 | 314,990 | 220,723 | 4,787 | 511 | What can you say about the position of the shortest person?
If the position of the shortest person is i, how many people would be in front of the shortest person? Once you fix the position of the shortest person, what can you say about the position of the second shortest person? | 315 |
407 | Trapping Rain Water II | trapping-rain-water-ii | Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. | Array,Breadth-First Search,Heap (Priority Queue),Matrix | Hard | 46.9 | 145,379 | 68,250 | 2,670 | 60 | null | 42 |
408 | Valid Word Abbreviation | valid-word-abbreviation | null | Two Pointers,String | Easy | 34.7 | 267,371 | 92,659 | 434 | 1,591 | null | 411,527,2184 |
409 | Longest Palindrome | longest-palindrome | Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, "Aa" is not considered a palindrome here. | Hash Table,String,Greedy | Easy | 53.5 | 496,778 | 265,829 | 2,591 | 153 | null | 266,2237 |
410 | Split Array Largest Sum | split-array-largest-sum | Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays. | Array,Binary Search,Dynamic Programming,Greedy | Hard | 52 | 393,533 | 204,494 | 5,728 | 149 | null | 1056,1192,2242,2330 |
411 | Minimum Unique Word Abbreviation | minimum-unique-word-abbreviation | null | String,Backtracking,Bit Manipulation | Hard | 38.4 | 34,544 | 13,260 | 164 | 137 | null | 320,408,527 |
412 | Fizz Buzz | fizz-buzz | Given an integer n, return a string array answer (1-indexed) where: | Math,String,Simulation | Easy | 66.5 | 913,322 | 607,795 | 329 | 58 | null | 1316 |
413 | Arithmetic Slices | arithmetic-slices | An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. Given an integer array nums, return the number of arithmetic subarrays of nums. A subarray is a contiguous subsequence of the array. | Array,Dynamic Programming | Medium | 64.4 | 350,296 | 225,542 | 3,847 | 249 | null | 446,1752 |
414 | Third Maximum Number | third-maximum-number | Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number. | Array,Sorting | Easy | 31.8 | 1,005,897 | 319,648 | 1,629 | 2,274 | null | 215 |
415 | Add Strings | add-strings | Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly. | Math,String,Simulation | Easy | 52.1 | 888,575 | 462,692 | 3,167 | 538 | null | 2,43,1031 |
416 | Partition Equal Subset Sum | partition-equal-subset-sum | 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. | Array,Dynamic Programming | Medium | 46.4 | 925,930 | 429,311 | 7,247 | 115 | null | 698,2108,2135,2162 |
417 | Pacific Atlantic Water Flow | pacific-atlantic-water-flow | 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. The island is partitioned into a grid of square cells. You are given an m x n integer matrix heights where heights[r][c] represents the height above sea level of the cell at coordinate (r, c). The island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is less than or equal to the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean. Return a 2D list of grid coordinates result where result[i] = [ri, ci] denotes that rain water can flow from cell (ri, ci) to both the Pacific and Atlantic oceans. | Array,Depth-First Search,Breadth-First Search,Matrix | Medium | 48.9 | 392,980 | 192,213 | 3,494 | 799 | null | null |
418 | Sentence Screen Fitting | sentence-screen-fitting | null | String,Dynamic Programming,Simulation | Medium | 35.4 | 226,515 | 80,122 | 875 | 444 | null | 2082 |
419 | Battleships in a Board | battleships-in-a-board | Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board. Battleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships). | Array,Depth-First Search,Matrix | Medium | 73.4 | 195,795 | 143,656 | 1,452 | 733 | null | null |
420 | Strong Password Checker | strong-password-checker | A password is considered strong if the below conditions are all met: Given a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0. In one step, you can: | String,Greedy,Heap (Priority Queue) | Hard | 14.2 | 170,278 | 24,140 | 473 | 1,251 | null | null |
421 | Maximum XOR of Two Numbers in an Array | maximum-xor-of-two-numbers-in-an-array | Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n. | Array,Hash Table,Bit Manipulation,Trie | Medium | 54.3 | 223,851 | 121,492 | 3,837 | 324 | null | 1826 |
422 | Valid Word Square | valid-word-square | null | Array,Matrix | Easy | 38.6 | 103,273 | 39,896 | 286 | 174 | null | 425,777 |
423 | Reconstruct Original Digits from English | reconstruct-original-digits-from-english | Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order. | Hash Table,Math,String | Medium | 51.2 | 120,508 | 61,662 | 601 | 2,013 | null | null |
424 | Longest Repeating Character Replacement | longest-repeating-character-replacement | You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times. Return the length of the longest substring containing the same letter you can get after performing the above operations. | Hash Table,String,Sliding Window | Medium | 50.7 | 406,149 | 206,085 | 4,188 | 170 | null | 340,1046,2119,2134,2319 |
425 | Word Squares | word-squares | null | Array,String,Backtracking,Trie | Hard | 52.2 | 118,221 | 61,696 | 921 | 59 | null | 422 |
432 | All O`one Data Structure | all-oone-data-structure | Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts. Implement the AllOne class: | Hash Table,Linked List,Design,Doubly-Linked List | Hard | 35.9 | 157,381 | 56,462 | 1,076 | 130 | null | null |
433 | Minimum Genetic Mutation | minimum-genetic-mutation | A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'. Suppose we need to investigate a mutation from a gene string start to a gene string end where one mutation is defined as one single character changed in the gene string. There is also a gene bank bank that records all the valid gene mutations. A gene must be in bank to make it a valid gene string. Given the two gene strings start and end and the gene bank bank, return the minimum number of mutations needed to mutate from start to end. If there is no such a mutation, return -1. Note that the starting point is assumed to be valid, so it might not be included in the bank. | Hash Table,String,Breadth-First Search | Medium | 46.6 | 113,064 | 52,704 | 868 | 102 | null | 127 |
434 | Number of Segments in a String | number-of-segments-in-a-string | Given a string s, return the number of segments in the string. A segment is defined to be a contiguous sequence of non-space characters. | String | Easy | 37.9 | 301,227 | 114,139 | 433 | 1,006 | null | null |
435 | Non-overlapping Intervals | non-overlapping-intervals | 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. | Array,Dynamic Programming,Greedy,Sorting | Medium | 48.1 | 494,769 | 238,037 | 3,819 | 111 | null | 452 |
436 | Find Right Interval | find-right-interval | You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique. The right interval for an interval i is an interval j such that startj >= endi and startj is minimized. Note that i may equal j. Return an array of right interval indices for each interval i. If no right interval exists for interval i, then put -1 at index i. | Array,Binary Search,Sorting | Medium | 49.4 | 154,224 | 76,193 | 1,169 | 248 | null | 352 |
437 | Path Sum III | path-sum-iii | 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. The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes). | Tree,Depth-First Search,Binary Tree | Medium | 50.2 | 713,399 | 357,889 | 7,352 | 359 | null | 112,113,666,687 |
438 | Find All Anagrams in a String | find-all-anagrams-in-a-string | 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. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. | Hash Table,String,Sliding Window | Medium | 48.2 | 1,076,189 | 518,606 | 7,285 | 251 | null | 242,567 |
439 | Ternary Expression Parser | ternary-expression-parser | null | String,Stack,Recursion | Medium | 57.8 | 42,586 | 24,617 | 337 | 41 | null | 385,722,736 |
440 | K-th Smallest in Lexicographical Order | k-th-smallest-in-lexicographical-order | Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n]. | Trie | Hard | 30.5 | 57,068 | 17,419 | 552 | 73 | null | null |
441 | Arranging Coins | arranging-coins | You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete. Given the integer n, return the number of complete rows of the staircase you will build. | Math,Binary Search | Easy | 45.3 | 602,006 | 272,594 | 2,139 | 1,012 | null | null |
442 | Find All Duplicates in an Array | find-all-duplicates-in-an-array | 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. You must write an algorithm that runs in O(n) time and uses only constant extra space. | Array,Hash Table | Medium | 72.3 | 540,996 | 391,236 | 5,995 | 247 | null | 448 |
443 | String Compression | string-compression | Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: The compressed string s should not be returned separately, but instead, be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars. After you are done modifying the input array, return the new length of the array. You must write an algorithm that uses only constant extra space. | Two Pointers,String | Medium | 47.4 | 512,212 | 242,895 | 2,021 | 4,140 | How do you know if you are at the end of a consecutive group of characters? | 38,271,604,1241 |
444 | Sequence Reconstruction | sequence-reconstruction | null | Array,Graph,Topological Sort | Medium | 25 | 175,729 | 43,884 | 453 | 1,385 | null | 210 |
445 | Add Two Numbers II | add-two-numbers-ii | You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. | Linked List,Math,Stack | Medium | 58.5 | 523,092 | 306,223 | 3,414 | 226 | null | 2,1774 |
446 | Arithmetic Slices II - Subsequence | arithmetic-slices-ii-subsequence | Given an integer array nums, return the number of all the arithmetic subsequences of nums. A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array. The test cases are generated so that the answer fits in 32-bit integer. | Array,Dynamic Programming | Hard | 39.4 | 110,325 | 43,491 | 1,340 | 85 | null | 413 |
447 | Number of Boomerangs | number-of-boomerangs | You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters). Return the number of boomerangs. | Array,Hash Table,Math | Medium | 54.1 | 156,588 | 84,744 | 611 | 881 | null | 356 |
448 | Find All Numbers Disappeared in an Array | find-all-numbers-disappeared-in-an-array | Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. | Array,Hash Table | Easy | 59 | 952,265 | 561,997 | 6,409 | 376 | This is a really easy problem if you decide to use additional memory. For those trying to write an initial solution using additional memory, think counters! However, the trick really is to not use any additional space than what is already available to use. Sometimes, multiple passes over the input array help find the solution. However, there's an interesting piece of information in this problem that makes it easy to re-use the input array itself for the solution. The problem specifies that the numbers in the array will be in the range [1, n] where n is the number of elements in the array. Can we use this information and modify the array in-place somehow to find what we need? | 41,442,2107,2305 |
449 | Serialize and Deserialize BST | serialize-and-deserialize-bst | Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You need to ensure that a binary search tree can be serialized to a string, and this string can be deserialized to the original tree structure. The encoded string should be as compact as possible. | String,Tree,Depth-First Search,Breadth-First Search,Design,Binary Search Tree,Binary Tree | Medium | 56.1 | 339,893 | 190,840 | 2,633 | 129 | null | 297,652,765 |
450 | Delete Node in a BST | delete-node-in-a-bst | Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: | Tree,Binary Search Tree,Binary Tree | Medium | 48.9 | 546,379 | 267,213 | 5,181 | 152 | null | 791 |
451 | Sort Characters By Frequency | sort-characters-by-frequency | 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. Return the sorted string. If there are multiple answers, return any of them. | Hash Table,String,Sorting,Heap (Priority Queue),Bucket Sort,Counting | Medium | 67.7 | 524,140 | 354,883 | 4,008 | 178 | null | 347,387,1741 |
452 | Minimum Number of Arrows to Burst Balloons | minimum-number-of-arrows-to-burst-balloons | There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons. Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path. Given the array points, return the minimum number of arrows that must be shot to burst all balloons. | Array,Greedy,Sorting | Medium | 52.9 | 351,182 | 185,715 | 3,362 | 97 | null | 253,435 |
453 | Minimum Moves to Equal Array Elements | minimum-moves-to-equal-array-elements | Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n - 1 elements of the array by 1. | Array,Math | Medium | 54 | 224,354 | 121,115 | 1,419 | 1,548 | null | 462,2263,2273 |
454 | 4Sum II | 4sum-ii | Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: | Array,Hash Table | Medium | 57 | 438,276 | 249,846 | 3,757 | 112 | null | 18 |
455 | Assign Cookies | assign-cookies | Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number. | Array,Greedy,Sorting | Easy | 50.7 | 319,993 | 162,255 | 1,404 | 157 | null | null |
456 | 132 Pattern | 132-pattern | Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false. | Array,Binary Search,Stack,Monotonic Stack,Ordered Set | Medium | 30.9 | 344,145 | 106,371 | 3,199 | 176 | null | null |
457 | Circular Array Loop | circular-array-loop | You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i: Since the array is circular, you may assume that moving forward from the last element puts you on the first element, and moving backwards from the first element puts you on the last element. A cycle in the array consists of a sequence of indices seq of length k where: Return true if there is a cycle in nums, or false otherwise. | Array,Hash Table,Two Pointers | Medium | 31.6 | 184,536 | 58,399 | 343 | 302 | null | null |
458 | Poor Pigs | poor-pigs | There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous. You can feed the pigs according to these steps: Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time. | Math,Dynamic Programming,Combinatorics | Hard | 55.5 | 60,162 | 33,406 | 630 | 1,144 | What if you only have one shot? Eg. 4 buckets, 15 mins to die, and 15 mins to test. How many states can we generate with x pigs and T tests? Find minimum x such that (T+1)^x >= N | null |
459 | Repeated Substring Pattern | repeated-substring-pattern | Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. | String,String Matching | Easy | 43.6 | 545,164 | 237,600 | 3,266 | 312 | null | 28,686 |
460 | LFU Cache | lfu-cache | Design and implement a data structure for a Least Frequently Used (LFU) cache. Implement the LFUCache class: To determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key. When a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it. The functions get and put must each run in O(1) average time complexity. | Hash Table,Linked List,Design,Doubly-Linked List | Hard | 39.3 | 381,837 | 150,130 | 3,133 | 205 | null | 146,588 |
461 | Hamming Distance | hamming-distance | The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return the Hamming distance between them. | Bit Manipulation | Easy | 74.5 | 630,915 | 469,900 | 3,021 | 197 | null | 191,477 |
462 | Minimum Moves to Equal Array Elements II | minimum-moves-to-equal-array-elements-ii | Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment or decrement an element of the array by 1. Test cases are designed so that the answer will fit in a 32-bit integer. | Array,Math,Sorting | Medium | 56.9 | 154,692 | 88,030 | 1,373 | 73 | null | 296,453,2160,2290 |
463 | Island Perimeter | island-perimeter | You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island. | Array,Depth-First Search,Breadth-First Search,Matrix | Easy | 68.9 | 522,927 | 360,401 | 4,279 | 237 | null | 695,733,1104 |
464 | Can I Win | can-i-win | In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins. What if we change the game so that players cannot re-use integers? For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100. Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally. | Math,Dynamic Programming,Bit Manipulation,Memoization,Game Theory,Bitmask | Medium | 29.8 | 250,138 | 74,662 | 1,824 | 294 | null | 294,375,486 |
465 | Optimal Account Balancing | optimal-account-balancing | null | Array,Dynamic Programming,Backtracking,Bit Manipulation,Bitmask | Hard | 48.9 | 140,529 | 68,685 | 1,119 | 107 | null | null |
466 | Count The Repetitions | count-the-repetitions | We define str = [s, n] as the string str which consists of the string s concatenated n times. We define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1. You are given two strings s1 and s2 and two integers n1 and n2. You have the two strings str1 = [s1, n1] and str2 = [s2, n2]. Return the maximum integer m such that str = [str2, m] can be obtained from str1. | String,Dynamic Programming | Hard | 29 | 48,557 | 14,067 | 292 | 260 | null | null |
467 | Unique Substrings in Wraparound String | unique-substrings-in-wraparound-string | We define the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: Given a string p, return the number of unique non-empty substrings of p are present in s. | String,Dynamic Programming | Medium | 37.5 | 92,633 | 34,731 | 1,069 | 135 | One possible solution might be to consider allocating an array size of 26 for each character in the alphabet. (Credits to @r2ysxu) | null |
468 | Validate IP Address | validate-ip-address | Given a string queryIP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type. A valid IPv4 address is an IP in the form "x1.x2.x3.x4" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, "192.168.1.1" and "192.168.1.0" are valid IPv4 addresses but "192.168.01.1", while "192.168.1.00" and "[email protected]" are invalid IPv4 addresses. A valid IPv6 address is an IP in the form "x1:x2:x3:x4:x5:x6:x7:x8" where: For example, "2001:0db8:85a3:0000:0000:8a2e:0370:7334" and "2001:db8:85a3:0:0:8A2E:0370:7334" are valid IPv6 addresses, while "2001:0db8:85a3::8A2E:037j:7334" and "02001:0db8:85a3:0000:0000:8a2e:0370:7334" are invalid IPv6 addresses. | String | Medium | 26.2 | 476,704 | 124,865 | 663 | 2,342 | null | 752 |
469 | Convex Polygon | convex-polygon | null | Math,Geometry | Medium | 38.2 | 24,802 | 9,485 | 84 | 216 | null | null |
471 | Encode String with Shortest Length | encode-string-with-shortest-length | null | String,Dynamic Programming | Hard | 50.6 | 54,524 | 27,610 | 560 | 35 | null | 394,726 |
472 | Concatenated Words | concatenated-words | Given an array of strings words (without duplicates), return all the concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array. | Array,String,Dynamic Programming,Depth-First Search,Trie | Hard | 42.8 | 300,523 | 128,601 | 1,848 | 216 | null | 140 |
473 | Matchsticks to Square | matchsticks-to-square | You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time. Return true if you can make this square and false otherwise. | Array,Dynamic Programming,Backtracking,Bit Manipulation,Bitmask | Medium | 40.3 | 188,482 | 76,024 | 1,571 | 121 | Treat the matchsticks as an array. Can we split the array into 4 equal halves? Every matchstick can belong to either of the 4 sides. We don't know which one. Maybe try out all options! For every matchstick, we have to try out each of the 4 options i.e. which side it can belong to. We can make use of recursion for this. We don't really need to keep track of which matchsticks belong to a particular side during recursion. We just need to keep track of the length of each of the 4 sides. When all matchsticks have been used we simply need to see the length of all 4 sides. If they're equal, we have a square on our hands! | null |
474 | Ones and Zeroes | ones-and-zeroes | You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset. A set x is a subset of a set y if all elements of x are also elements of y. | Array,String,Dynamic Programming | Medium | 44.5 | 237,317 | 105,672 | 2,790 | 322 | null | 510,600,2261 |
475 | Heaters | heaters | Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. Every house can be warmed, as long as the house is within the heater's warm radius range. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses. Notice that all the heaters follow your radius standard, and the warm radius will the same. | Array,Two Pointers,Binary Search,Sorting | Medium | 35.2 | 247,584 | 87,206 | 1,326 | 1,026 | null | null |
476 | Number Complement | number-complement | The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. Given an integer num, return its complement. | Bit Manipulation | Easy | 66.7 | 392,862 | 261,892 | 1,954 | 105 | null | null |
477 | Total Hamming Distance | total-hamming-distance | The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums. | Array,Math,Bit Manipulation | Medium | 52 | 167,545 | 87,042 | 1,614 | 80 | null | 461 |
479 | Largest Palindrome Product | largest-palindrome-product | Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337. | Math | Hard | 31.1 | 65,149 | 20,274 | 123 | 1,448 | null | null |
480 | Sliding Window Median | sliding-window-median | The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values. You are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the median array for each window in the original array. Answers within 10-5 of the actual value will be accepted. | Array,Hash Table,Sliding Window,Heap (Priority Queue) | Hard | 40.8 | 252,073 | 102,947 | 2,111 | 130 | The simplest of solutions comes from the basic idea of finding the median given a set of numbers. We know that by definition, a median is the center element (or an average of the two center elements). Given an unsorted list of numbers, how do we find the median element? If you know the answer to this question, can we extend this idea to every sliding window that we come across in the array? Is there a better way to do what we are doing in the above hint? Don't you think there is duplication of calculation being done there? Is there some sort of optimization that we can do to achieve the same result? This approach is merely a modification of the basic approach except that it simply reduces duplication of calculations once done. The third line of thought is also based on this same idea but achieving the result in a different way. We obviously need the window to be sorted for us to be able to find the median. Is there a data-structure out there that we can use (in one or more quantities) to obtain the median element extremely fast, say O(1) time while having the ability to perform the other operations fairly efficiently as well? | 295 |
481 | Magical String | magical-string | A magical string s consists of only '1' and '2' and obeys the following rules: The first few elements of s is s = "1221121221221121122……". If we group the consecutive 1's and 2's in s, it will be "1 22 11 2 1 22 1 22 11 2 11 22 ......" and the occurrences of 1's or 2's in each group are "1 2 2 1 1 2 1 2 2 1 2 2 ......". You can see that the occurrence sequence is s itself. Given an integer n, return the number of 1's in the first n number in the magical string s. | Two Pointers,String | Medium | 49.6 | 55,628 | 27,608 | 182 | 931 | null | null |
482 | License Key Formatting | license-key-formatting | You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k. We want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase. Return the reformatted license key. | String | Easy | 43.1 | 486,859 | 209,919 | 751 | 1,077 | null | null |
483 | Smallest Good Base | smallest-good-base | Given an integer n represented as a string, return the smallest good base of n. We call k >= 2 a good base of n, if all digits of n base k are 1's. | Math,Binary Search | Hard | 37.8 | 44,231 | 16,728 | 265 | 429 | null | null |
484 | Find Permutation | find-permutation | null | Array,Stack,Greedy | Medium | 64.3 | 42,289 | 27,197 | 485 | 80 | null | null |
485 | Max Consecutive Ones | max-consecutive-ones | Given a binary array nums, return the maximum number of consecutive 1's in the array. | Array | Easy | 55 | 1,160,124 | 638,413 | 2,517 | 395 | You need to think about two things as far as any window is concerned. One is the starting point for the window. How do you detect that a new window of 1s has started? The next part is detecting the ending point for this window.
How do you detect the ending point for an existing window? If you figure these two things out, you will be able to detect the windows of consecutive ones. All that remains afterward is to find the longest such window and return the size. | 487,1046,1542,1999 |
486 | Predict the Winner | predict-the-winner | You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2. Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of the numbers from either end of the array (i.e., nums[0] or nums[nums.length - 1]) which reduces the size of the array by 1. The player adds the chosen number to their score. The game ends when there are no more elements in the array. Return true if Player 1 can win the game. If the scores of both players are equal, then player 1 is still the winner, and you should also return true. You may assume that both players are playing optimally. | Array,Math,Dynamic Programming,Recursion,Game Theory | Medium | 50.2 | 219,956 | 110,418 | 2,836 | 148 | null | 464 |
487 | Max Consecutive Ones II | max-consecutive-ones-ii | null | Array,Dynamic Programming,Sliding Window | Medium | 48.9 | 184,663 | 90,209 | 1,058 | 21 | null | 485,1046,2261 |
488 | Zuma Game | zuma-game | You are playing a variation of the game Zuma. In this variation of Zuma, there is a single row of colored balls on a board, where each ball can be colored red 'R', yellow 'Y', blue 'B', green 'G', or white 'W'. You also have several colored balls in your hand. Your goal is to clear all of the balls from the board. On each turn: Given a string board, representing the row of balls on the board, and a string hand, representing the balls in your hand, return the minimum number of balls you have to insert to clear all the balls from the board. If you cannot clear all the balls from the board using the balls in your hand, return -1. | String,Dynamic Programming,Breadth-First Search,Memoization | Hard | 36.2 | 54,715 | 19,813 | 335 | 394 | null | null |
489 | Kth Smallest Instructions | kth-smallest-instructions | Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination. The instructions are represented as a string, where each character is either: Multiple instructions will lead Bob to destination. For example, if destination is (2, 3), both "HHHVV" and "HVHVH" are valid instructions. However, Bob is very picky. Bob has a lucky number k, and he wants the kth lexicographically smallest instructions that will lead him to destination. k is 1-indexed. Given an integer array destination and an integer k, return the kth lexicographically smallest instructions that will take Bob to destination. | Array,Math,Dynamic Programming,Combinatorics | Hard | 45.5 | 16,295 | 7,410 | 337 | 3 | There are nCr(row + column, row) possible instructions to reach (row, column). Try building the instructions one step at a time. How many instructions start with "H", and how does this compare with k? | null |
490 | The Maze | the-maze | null | Depth-First Search,Breadth-First Search,Graph | Medium | 54.6 | 214,025 | 116,944 | 1,394 | 148 | null | 499,505 |
491 | Increasing Subsequences | increasing-subsequences | Given an integer array nums, return all the different possible increasing subsequences of the given array with at least two elements. You may return the answer in any order. The given array may contain duplicates, and two equal integers should also be considered a special case of increasing sequence. | Array,Hash Table,Backtracking,Bit Manipulation | Medium | 50.7 | 144,735 | 73,425 | 1,426 | 147 | null | 646 |
492 | Construct the Rectangle | construct-the-rectangle | A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: Return an array [L, W] where L and W are the length and width of the web page you designed in sequence. | Math | Easy | 52.6 | 147,485 | 77,542 | 399 | 321 | The W is always less than or equal to the square root of the area, so we start searching at sqrt(area) till we find the result. | null |
493 | Reverse Pairs | reverse-pairs | Given an integer array nums, return the number of reverse pairs in the array. A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j]. | Array,Binary Search,Divide and Conquer,Binary Indexed Tree,Segment Tree,Merge Sort,Ordered Set | Hard | 29.8 | 270,169 | 80,624 | 2,706 | 178 | null | 315,327 |
494 | Target Sum | target-sum | You are given an integer array nums and an integer target. 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. Return the number of different expressions that you can build, which evaluates to target. | Array,Dynamic Programming,Backtracking | Medium | 45.4 | 750,493 | 340,614 | 6,621 | 253 | null | 282 |
495 | Teemo Attacking | teemo-attacking | Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack. You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration. Return the total number of seconds that Ashe is poisoned. | Array,Simulation | Easy | 56.8 | 171,664 | 97,561 | 396 | 37 | null | 56,605,649 |
496 | Next Greater Element I | next-greater-element-i | The next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. For each 0 <= i < nums1.length, find the index j such that nums1[i] == nums2[j] and determine the next greater element of nums2[j] in nums2. If there is no next greater element, then the answer for this query is -1. Return an array ans of length nums1.length such that ans[i] is the next greater element as described above. | Array,Hash Table,Stack,Monotonic Stack | Easy | 70 | 496,323 | 347,209 | 2,593 | 176 | null | 503,556,739,2227 |
498 | Diagonal Traverse | diagonal-traverse | Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. | Array,Matrix,Simulation | Medium | 56.5 | 344,843 | 194,981 | 2,118 | 524 | null | 2197 |
499 | The Maze III | the-maze-iii | null | Depth-First Search,Breadth-First Search,Graph,Heap (Priority Queue),Shortest Path | Hard | 45.2 | 49,931 | 22,545 | 351 | 61 | null | 490,505 |
500 | Keyboard Row | keyboard-row | Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below. In the American keyboard: | Array,Hash Table,String | Easy | 67.9 | 220,657 | 149,901 | 885 | 904 | null | null |
501 | Find Mode in Binary Search Tree | find-mode-in-binary-search-tree | Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, return them in any order. Assume a BST is defined as follows: | Tree,Depth-First Search,Binary Search Tree,Binary Tree | Easy | 47.1 | 315,670 | 148,620 | 2,069 | 557 | null | 98 |
502 | IPO | ipo | Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects. You are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it. Initially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital. Pick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital. The answer is guaranteed to fit in a 32-bit signed integer. | Array,Greedy,Sorting,Heap (Priority Queue) | Hard | 44 | 73,070 | 32,171 | 775 | 70 | null | null |
503 | Next Greater Element II | next-greater-element-ii | Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number. | Array,Stack,Monotonic Stack | Medium | 61.9 | 341,428 | 211,511 | 4,409 | 130 | null | 496,556 |
504 | Base 7 | base-7 | Given an integer num, return a string of its base 7 representation. | Math | Easy | 47.5 | 178,434 | 84,670 | 464 | 192 | null | null |
505 | The Maze II | the-maze-ii | null | Depth-First Search,Breadth-First Search,Graph,Heap (Priority Queue),Shortest Path | Medium | 51.2 | 155,908 | 79,902 | 1,023 | 45 | null | 490,499 |
506 | Relative Ranks | relative-ranks | You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique. The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank: Return an array answer of size n where answer[i] is the rank of the ith athlete. | Array,Sorting,Heap (Priority Queue) | Easy | 56.6 | 155,397 | 87,944 | 456 | 25 | null | null |
507 | Perfect Number | perfect-number | A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly. Given an integer n, return true if n is a perfect number, otherwise return false. | Math | Easy | 37.6 | 269,423 | 101,225 | 543 | 836 | null | 728 |
508 | Most Frequent Subtree Sum | most-frequent-subtree-sum | Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). | Hash Table,Tree,Depth-First Search,Binary Tree | Medium | 62.7 | 169,666 | 106,337 | 1,455 | 222 | null | 572,2126 |
509 | Inorder Successor in BST II | inorder-successor-in-bst-ii | null | Tree,Binary Search Tree,Binary Tree | Medium | 61.4 | 77,173 | 47,391 | 653 | 34 | null | 285 |