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
728
Self Dividing Numbers
self-dividing-numbers
A self-dividing number is a number that is divisible by every digit it contains. A self-dividing number is not allowed to contain the digit zero. Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right].
Math
Easy
76.9
226,706
174,351
1,130
347
For each number in the range, check whether it is self dividing by converting that number to a character array (or string in Python), then checking that each digit is nonzero and divides the original number.
507
729
My Calendar I
my-calendar-i
You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking. A double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events.). The event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end. Implement the MyCalendar class:
Design,Segment Tree,Ordered Set
Medium
55.1
262,105
144,447
1,894
58
Store the events as a sorted list of intervals. If none of the events conflict, then the new event can be added.
731,732
730
Count Different Palindromic Subsequences
count-different-palindromic-subsequences
Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7. A subsequence of a string is obtained by deleting zero or more characters from the string. A sequence is palindromic if it is equal to the sequence reversed. Two sequences a1, a2, ... and b1, b2, ... are different if there is some i for which ai != bi.
String,Dynamic Programming
Hard
44.3
59,687
26,437
1,270
68
Let dp(i, j) be the answer for the string T = S[i:j+1] including the empty sequence. The answer is the number of unique characters in T, plus palindromes of the form "a_a", "b_b", "c_c", and "d_d", where "_" represents zero or more characters.
516
731
My Calendar II
my-calendar-ii
You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking. A triple booking happens when three events have some non-empty intersection (i.e., some moment is common to all the three events.). The event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end. Implement the MyCalendarTwo class:
Design,Segment Tree,Ordered Set
Medium
53.3
135,700
72,357
1,129
123
Store two sorted lists of intervals: one list will be all times that are at least single booked, and another list will be all times that are definitely double booked. If none of the double bookings conflict, then the booking will succeed, and you should update your single and double bookings accordingly.
729,732
732
My Calendar III
my-calendar-iii
A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.) You are given some events [start, end), after each given event, return an integer k representing the maximum k-booking between all the previous events. Implement the MyCalendarThree class:
Design,Segment Tree,Ordered Set
Hard
66.4
59,885
39,769
703
146
Treat each interval [start, end) as two events "start" and "end", and process them in sorted order.
729,731
733
Flood Fill
flood-fill
An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with newColor. Return the modified image after performing the flood fill.
Array,Depth-First Search,Breadth-First Search,Matrix
Easy
58.2
673,313
391,611
3,924
373
Write a recursive function that paints the pixel if it's the correct color, then recurses on neighboring pixels.
463
734
Sentence Similarity
sentence-similarity
null
Array,Hash Table,String
Easy
43
117,004
50,277
280
446
Two words w1 and w2 are similar if and only if w1 == w2, (w1, w2) was a pair, or (w2, w1) was a pair.
547,721,737
735
Asteroid Collision
asteroid-collision
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Array,Stack
Medium
44.4
433,907
192,607
3,407
267
Say a row of asteroids is stable. What happens when a new asteroid is added on the right?
605,2245,2317
736
Parse Lisp Expression
parse-lisp-expression
You are given a string expression representing a Lisp-like expression to return the integer value of. The syntax for these expressions is given as follows.
Hash Table,String,Stack,Recursion
Hard
51.2
35,889
18,389
386
304
* If the expression starts with a digit or '-', it's an integer: return it. * If the expression starts with a letter, it's a variable. Recall it by checking the current scope in reverse order. * Otherwise, group the tokens (variables or expressions) within this expression by counting the "balance" `bal` of the occurrences of `'('` minus the number of occurrences of `')'`. When the balance is zero, we have ended a token. For example, `(add 1 (add 2 3))` should have tokens `'1'` and `'(add 2 3)'`. * For add and mult expressions, evaluate each token and return the addition or multiplication of them. * For let expressions, evaluate each expression sequentially and assign it to the variable in the current scope, then return the evaluation of the final expression.
439,726,781
737
Sentence Similarity II
sentence-similarity-ii
null
Array,Hash Table,String,Depth-First Search,Breadth-First Search,Union Find
Medium
48.1
121,807
58,568
704
42
Consider the graphs where each pair in "pairs" is an edge. Two words are similar if they are the same, or are in the same connected component of this graph.
547,721,734
738
Monotone Increasing Digits
monotone-increasing-digits
An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y. Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.
Math,Greedy
Medium
46.7
79,953
37,361
901
87
Build the answer digit by digit, adding the largest possible one that would make the number still less than or equal to N.
402
739
Daily Temperatures
daily-temperatures
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
Array,Stack,Monotonic Stack
Medium
67
559,365
374,997
6,760
155
If the temperature is say, 70 today, then in the future a warmer temperature must be either 71, 72, 73, ..., 99, or 100. We could remember when all of them occur next.
496,937
740
Delete and Earn
delete-and-earn
You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: Return the maximum number of points you can earn by applying the above operation some number of times.
Array,Hash Table,Dynamic Programming
Medium
57.3
311,800
178,651
4,623
258
If you take a number, you might as well take them all. Keep track of what the value is of the subset of the input with maximum M when you either take or don't take M.
198
741
Cherry Pickup
cherry-pickup
You are given an n x n grid representing a field of cherries, each cell is one of three possible integers. Return the maximum number of cherries you can collect by following the rules below:
Array,Dynamic Programming,Matrix
Hard
36.2
144,841
52,406
2,555
120
null
64,174,2189
742
To Lower Case
to-lower-case
Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.
String
Easy
81.3
413,860
336,519
1,053
2,298
Most languages support lowercase conversion for a string data type. However, that is certainly not the purpose of the problem. Think about how the implementation of the lowercase function call can be done easily. Think ASCII! Think about the different capital letters and their ASCII codes and how that relates to their lowercase counterparts. Does there seem to be any pattern there? Any mathematical relationship that we can use?
2235
743
Closest Leaf in a Binary Tree
closest-leaf-in-a-binary-tree
null
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
45.6
82,896
37,835
753
147
Convert the tree to a general graph, and do a breadth-first search. Alternatively, find the closest leaf for every node on the path from root to target.
null
744
Network Delay Time
network-delay-time
You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target. We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.
Depth-First Search,Breadth-First Search,Graph,Heap (Priority Queue),Shortest Path
Medium
48.4
479,952
232,392
3,920
275
We visit each node at some time, and if that time is better than the fastest time we've reached this node, we travel along outgoing edges in sorted order. Alternatively, we could use Dijkstra's algorithm.
2151,2171
745
Find Smallest Letter Greater Than Target
find-smallest-letter-greater-than-target
Given a characters array letters that is sorted in non-decreasing order and a character target, return the smallest character in the array that is larger than target. Note that the letters wrap around.
Array,Binary Search
Easy
45.2
402,960
182,233
1,541
1,403
Try to find whether each of 26 next letters are in the given string array.
2269
746
Prefix and Suffix Search
prefix-and-suffix-search
Design a special dictionary with some words that searchs the words in it by a prefix and a suffix. Implement the WordFilter class:
String,Design,Trie
Hard
36.5
136,211
49,693
1,040
329
For a word like "test", consider "#test", "t#test", "st#test", "est#test", "test#test". Then if we have a query like prefix = "te", suffix = "t", we can find it by searching for something we've inserted starting with "t#te".
211
747
Min Cost Climbing Stairs
min-cost-climbing-stairs
You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with index 1. Return the minimum cost to reach the top of the floor.
Array,Dynamic Programming
Easy
58.6
769,739
450,967
5,723
992
Say f[i] is the final cost to climb to the top from step i. Then f[i] = cost[i] + min(f[i+1], f[i+2]).
70
748
Largest Number At Least Twice of Others
largest-number-at-least-twice-of-others
You are given an integer array nums where the largest integer is unique. Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
Array,Sorting
Easy
45.2
342,731
154,812
665
752
Scan through the array to find the unique largest element `m`, keeping track of it's index `maxIndex`. Scan through the array again. If we find some `x != m` with `m < 2*x`, we should return `-1`. Otherwise, we should return `maxIndex`.
2274,2327
749
Shortest Completing Word
shortest-completing-word
Given a string licensePlate and an array of strings words, find the shortest completing word in words. A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more. For example, if licensePlate = "aBc 12c", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are "abccdef", "caaacab", and "cbca". Return the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.
Array,Hash Table,String
Easy
58.9
84,073
49,487
312
851
Count only the letters (possibly converted to lowercase) of each word. If a word is shorter and the count of each letter is at least the count of that letter in the licensePlate, it is the best answer we've seen yet.
null
750
Contain Virus
contain-virus
A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls. The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents cells contaminated with the virus. A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary. Every night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall. Resources are limited. Each day, you can install walls around only one region (i.e., the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night). There will never be a tie. Return the number of walls used to quarantine all the infected regions. If the world will become fully infected, return the number of walls used.
Array,Depth-First Search,Breadth-First Search,Matrix,Simulation
Hard
50
16,339
8,173
229
367
The implementation is long - we want to perfrom the following steps: * Find all viral regions (connected components), additionally for each region keeping track of the frontier (neighboring uncontaminated cells), and the perimeter of the region. * Disinfect the most viral region, adding it's perimeter to the answer. * Spread the virus in the remaining regions outward by 1 square.
null
751
Number Of Corner Rectangles
number-of-corner-rectangles
null
Array,Math,Dynamic Programming,Matrix
Medium
67.5
52,675
35,574
576
85
For each pair of 1s in the new row (say at `new_row[i]` and `new_row[j]`), we could create more rectangles where that pair forms the base. The number of new rectangles is the number of times some previous row had `row[i] = row[j] = 1`.
null
752
IP to CIDR
ip-to-cidr
null
String,Bit Manipulation
Medium
54.9
25,225
13,856
30
79
Convert the ip addresses to and from (long) integers. You want to know what is the most addresses you can put in this block starting from the "start" ip, up to n. It is the smallest between the lowest bit of start and the highest bit of n. Then, repeat this process with a new start and n.
93,468
753
Open the Lock
open-the-lock
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot. The lock initially starts at '0000', a string representing the state of the 4 wheels. You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it. Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.
Array,Hash Table,String,Breadth-First Search
Medium
55.3
286,226
158,379
2,748
93
We can think of this problem as a shortest path problem on a graph: there are `10000` nodes (strings `'0000'` to `'9999'`), and there is an edge between two nodes if they differ in one digit, that digit differs by 1 (wrapping around, so `'0'` and `'9'` differ by 1), and if *both* nodes are not in `deadends`.
null
754
Cracking the Safe
cracking-the-safe
There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. The safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit. Return any string of minimum length that will unlock the safe at some point of entering it.
Depth-First Search,Graph,Eulerian Circuit
Hard
54.6
83,640
45,652
194
36
We can think of this problem as the problem of finding an Euler path (a path visiting every edge exactly once) on the following graph: there are $$k^{n-1}$$ nodes with each node having $$k$$ edges. It turns out this graph always has an Eulerian circuit (path starting where it ends.) We should visit each node in "post-order" so as to not get stuck in the graph prematurely.
null
755
Reach a Number
reach-a-number
You are standing at position 0 on an infinite number line. There is a destination at position target. You can make some number of moves numMoves so that: Given the integer target, return the minimum number of moves required (i.e., the minimum numMoves) to reach the destination.
Math,Binary Search
Medium
41.8
91,375
38,208
1,102
660
null
null
756
Pour Water
pour-water
null
Array,Simulation
Medium
45.5
65,750
29,923
258
601
null
42
757
Pyramid Transition Matrix
pyramid-transition-matrix
You are stacking blocks to form a pyramid. Each block has a color, which is represented by a single letter. Each row of blocks contains one less block than the row beneath it and is centered on top. To make the pyramid aesthetically pleasing, there are only specific triangular patterns that are allowed. A triangular pattern consists of a single block stacked on top of two blocks. The patterns are given as a list of three-letter strings allowed, where the first two characters of a pattern represent the left and right bottom blocks respectively, and the third character is the top block. You start with a bottom row of blocks bottom, given as a single string, that you must use as the base of the pyramid. Given bottom and allowed, return true if you can build the pyramid all the way to the top such that every triangular pattern in the pyramid is in allowed, or false otherwise.
Bit Manipulation,Depth-First Search,Breadth-First Search
Medium
54.6
49,490
27,038
450
427
null
null
758
Convert Binary Search Tree to Sorted Doubly Linked List
convert-binary-search-tree-to-sorted-doubly-linked-list
null
Linked List,Stack,Tree,Depth-First Search,Binary Search Tree,Binary Tree,Doubly-Linked List
Medium
64.3
320,660
206,269
2,144
175
null
94
759
Set Intersection Size At Least Two
set-intersection-size-at-least-two
An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b. Find the minimum size of a set S such that for every integer interval A in intervals, the intersection of S with A has a size of at least two.
Array,Greedy,Sorting
Hard
43.1
35,767
15,431
445
59
null
null
760
Bold Words in String
bold-words-in-string
null
Array,Hash Table,String,Trie,String Matching
Medium
50.2
32,809
16,464
234
117
First, determine which letters are bold and store that information in mask[i] = if i-th character is bold. Then, insert the tags at the beginning and end of groups. The start of a group is if and only if (mask[i] and (i == 0 or not mask[i-1])), and the end of a group is similar.
null
761
Employee Free Time
employee-free-time
null
Array,Sorting,Heap (Priority Queue)
Hard
71
148,539
105,458
1,371
86
Take all the intervals and do an "events" (or "line sweep") approach - an event of (x, OPEN) increases the number of active intervals, while (x, CLOSE) decreases it. Processing in sorted order from left to right, if the number of active intervals is zero, then you crossed a region of common free time.
56,1028
762
Find Anagram Mappings
find-anagram-mappings
null
Array,Hash Table
Easy
82.7
97,445
80,568
484
194
Create a hashmap so that D[x] = i whenever B[i] = x. Then, the answer is [D[x] for x in A].
null
763
Special Binary String
special-binary-string
Special binary strings are binary strings with the following two properties: You are given a special binary string s. A move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string. Return the lexicographically largest resulting string possible after applying the mentioned operations on the string.
String,Recursion
Hard
59.9
22,164
13,266
529
168
Draw a line from (x, y) to (x+1, y+1) if we see a "1", else to (x+1, y-1). A special substring is just a line that starts and ends at the same y-coordinate, and that is the lowest y-coordinate reached. Call a mountain a special substring with no special prefixes - ie. only at the beginning and end is the lowest y-coordinate reached. If F is the answer function, and S has mountain decomposition M1,M2,M3,...,Mk, then the answer is: reverse_sorted(F(M1), F(M2), ..., F(Mk)). However, you'll also need to deal with the case that S is a mountain, such as 11011000 -> 11100100.
678
764
N-ary Tree Level Order Traversal
n-ary-tree-level-order-traversal
Given an n-ary tree, return the level order traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
Tree,Breadth-First Search
Medium
68.8
251,213
172,915
1,774
81
null
102,775,776,2151
765
Serialize and Deserialize N-ary Tree
serialize-and-deserialize-n-ary-tree
null
String,Tree,Depth-First Search,Breadth-First Search
Hard
64.3
100,138
64,339
818
49
null
297,449,771
766
Flatten a Multilevel Doubly Linked List
flatten-a-multilevel-doubly-linked-list
You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure as shown in the example below. Given the head of the first level of the list, flatten the list so that all the nodes appear in a single-level, doubly linked list. Let curr be a node with a child list. The nodes in the child list should appear after curr and before curr.next in the flattened list. Return the head of the flattened list. The nodes in the list must have all of their child pointers set to null.
Linked List,Depth-First Search,Doubly-Linked List
Medium
58.9
389,156
229,148
3,579
249
null
114,1796
767
Prime Number of Set Bits in Binary Representation
prime-number-of-set-bits-in-binary-representation
Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation. Recall that the number of set bits an integer has is the number of 1's present when written in binary.
Math,Bit Manipulation
Easy
66.7
102,152
68,143
452
460
Write a helper function to count the number of set bits in a number, then check whether the number of set bits is 2, 3, 5, 7, 11, 13, 17 or 19.
191
768
Partition Labels
partition-labels
You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s. Return a list of integers representing the size of these parts.
Hash Table,Two Pointers,String,Greedy
Medium
79.5
475,982
378,565
7,541
287
Try to greedily choose the smallest partition that includes the first letter. If you have something like "abaccbdeffed", then you might need to add b. You can use an map like "last['b'] = 5" to help you expand the width of your partition.
56
769
Largest Plus Sign
largest-plus-sign
You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined as mines[i] = [xi, yi] where grid[xi][yi] == 0. Return the order of the largest axis-aligned plus sign of 1's contained in grid. If there is none, return 0. An axis-aligned plus sign of 1's of order k has some center grid[r][c] == 1 along with four arms of length k - 1 going up, down, left, and right, and made of 1's. Note that there could be 0's or 1's beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1's.
Array,Dynamic Programming
Medium
48.6
98,947
48,062
1,104
189
For each direction such as "left", find left[r][c] = the number of 1s you will see before a zero starting at r, c and walking left. You can find this in N^2 time with a dp. The largest plus sign at r, c is just the minimum of left[r][c], up[r][c] etc.
221
770
Couples Holding Hands
couples-holding-hands
There are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2n - 2, 2n - 1). Return the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.
Greedy,Depth-First Search,Breadth-First Search,Union Find,Graph
Hard
56.5
76,653
43,314
1,580
85
Say there are N two-seat couches. For each couple, draw an edge from the couch of one partner to the couch of the other partner.
41,268,884
771
Encode N-ary Tree to Binary Tree
encode-n-ary-tree-to-binary-tree
null
Tree,Depth-First Search,Breadth-First Search,Design,Binary Tree
Hard
76.4
19,556
14,938
386
21
null
765
772
Construct Quad Tree
construct-quad-tree
Given a n * n matrix grid of 0's and 1's only. We want to represent the grid with a Quad-Tree. Return the root of the Quad-Tree representing the grid. Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer. A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: We can construct a Quad-Tree from a two-dimensional area using the following steps: If you want to know more about the Quad-Tree, you can refer to the wiki. Quad-Tree format: The output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below. It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val]. If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.
Array,Divide and Conquer,Tree,Matrix
Medium
65.2
63,124
41,160
479
671
null
null
773
Logical OR of Two Binary Grids Represented as Quad-Trees
logical-or-of-two-binary-grids-represented-as-quad-trees
A Binary Matrix is a matrix in which all the elements are either 0 or 1. Given quadTree1 and quadTree2. quadTree1 represents a n * n binary matrix and quadTree2 represents another n * n binary matrix. Return a Quad-Tree representing the n * n binary matrix which is the result of logical bitwise OR of the two binary matrixes represented by quadTree1 and quadTree2. Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer. A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: We can construct a Quad-Tree from a two-dimensional area using the following steps: If you want to know more about the Quad-Tree, you can refer to the wiki. Quad-Tree format: The input/output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below. It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val]. If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.
Divide and Conquer,Tree
Medium
47.1
23,602
11,128
127
409
null
null
774
Maximum Depth of N-ary Tree
maximum-depth-of-n-ary-tree
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
Tree,Depth-First Search,Breadth-First Search
Easy
71
291,893
207,200
1,947
69
null
104,2151
775
N-ary Tree Preorder Traversal
n-ary-tree-preorder-traversal
Given the root of an n-ary tree, return the preorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)
Stack,Tree,Depth-First Search
Easy
76.1
295,173
224,480
1,708
80
null
144,764,776
776
N-ary Tree Postorder Traversal
n-ary-tree-postorder-traversal
Given the root of an n-ary tree, return the postorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)
Stack,Tree,Depth-First Search
Easy
76.1
234,316
178,336
1,553
82
null
145,764,775
777
Toeplitz Matrix
toeplitz-matrix
Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
Array,Matrix
Easy
68
269,427
183,077
1,915
119
Check whether each value is equal to the value of it's top-left neighbor.
422
778
Reorganize String
reorganize-string
Given a string s, rearrange the characters of s so that any two adjacent characters are not the same. Return any possible rearrangement of s or return "" if not possible.
Hash Table,String,Greedy,Sorting,Heap (Priority Queue),Counting
Medium
52
395,857
205,838
4,519
173
Alternate placing the most common letters.
358,621,1304
779
Max Chunks To Make Sorted II
max-chunks-to-make-sorted-ii
You are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return the largest number of chunks we can make to sort the array.
Array,Stack,Greedy,Sorting,Monotonic Stack
Hard
51.9
77,723
40,366
1,141
32
Each k for which some permutation of arr[:k] is equal to sorted(arr)[:k] is where we should cut each chunk.
780
780
Max Chunks To Make Sorted
max-chunks-to-make-sorted
You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return the largest number of chunks we can make to sort the array.
Array,Stack,Greedy,Sorting,Monotonic Stack
Medium
57.6
122,156
70,386
1,828
182
The first chunk can be found as the smallest k for which A[:k+1] == [0, 1, 2, ...k]; then we repeat this process.
779
781
Basic Calculator IV
basic-calculator-iv
Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {"e": 1} (given in terms of evalvars = ["e"] and evalints = [1]), return a list of tokens representing the simplified expression, such as ["-1*a","14"] Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction. The format of the output is as follows:
Hash Table,Math,String,Stack,Recursion
Hard
55.7
14,468
8,052
112
1,184
One way is with a Polynomial class. For example, * `Poly:add(this, that)` returns the result of `this + that`. * `Poly:sub(this, that)` returns the result of `this - that`. * `Poly:mul(this, that)` returns the result of `this * that`. * `Poly:evaluate(this, evalmap)` returns the polynomial after replacing all free variables with constants as specified by `evalmap`. * `Poly:toList(this)` returns the polynomial in the correct output format. * `Solution::combine(left, right, symbol)` returns the result of applying the binary operator represented by `symbol` to `left` and `right`. * `Solution::make(expr)` makes a new `Poly` represented by either the constant or free variable specified by `expr`. * `Solution::parse(expr)` parses an expression into a new `Poly`.
736,785
782
Jewels and Stones
jewels-and-stones
You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A".
Hash Table,String
Easy
87.7
832,734
730,256
3,471
484
For each stone, check if it is a jewel.
null
783
Search in a Binary Search Tree
search-in-a-binary-search-tree
You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.
Tree,Binary Search Tree,Binary Tree
Easy
76.3
614,317
468,905
3,234
150
null
270,784
784
Insert into a Binary Search Tree
insert-into-a-binary-search-tree
You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.
Tree,Binary Search Tree,Binary Tree
Medium
74.9
398,561
298,712
3,244
141
null
783
785
Basic Calculator III
basic-calculator-iii
null
Math,String,Stack,Recursion
Hard
47.4
175,148
83,066
850
245
null
224,227,781,1736
786
Search in a Sorted Array of Unknown Size
search-in-a-sorted-array-of-unknown-size
null
Array,Binary Search,Interactive
Medium
70.8
96,845
68,554
695
34
null
792,1672
787
Sliding Puzzle
sliding-puzzle
On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it. The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]]. Given the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.
Array,Breadth-First Search,Matrix
Hard
63.1
111,608
70,414
1,461
37
Perform a breadth-first-search, where the nodes are the puzzle boards and edges are if two puzzle boards can be transformed into one another with one move.
null
788
Minimize Max Distance to Gas Station
minimize-max-distance-to-gas-station
null
Array,Binary Search
Hard
50.4
50,411
25,395
579
82
Use a binary search. We'll binary search the monotone function "possible(D) = can we use K or less gas stations to ensure each adjacent distance between gas stations is at most D?"
907
789
Kth Largest Element in a Stream
kth-largest-element-in-a-stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class:
Tree,Design,Binary Search Tree,Heap (Priority Queue),Binary Tree,Data Stream
Easy
54.7
441,935
241,821
2,820
1,676
null
215,1953,2207
790
Global and Local Inversions
global-and-local-inversions
You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1]. The number of global inversions is the number of the different pairs (i, j) where: The number of local inversions is the number of indices i where: Return true if the number of global inversions is equal to the number of local inversions.
Array,Math
Medium
45.2
124,782
56,436
1,183
300
Where can the 0 be placed in an ideal permutation? What about the 1?
null
791
Split BST
split-bst
null
Tree,Binary Search Tree,Recursion,Binary Tree
Medium
58.3
45,949
26,792
889
89
Use recursion. If root.val <= V, you split root.right into two halves, then join it's left half back on root.right.
450
792
Binary Search
binary-search
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity.
Array,Binary Search
Easy
55.3
1,475,426
816,061
4,525
106
null
786
793
Swap Adjacent in LR String
swap-adjacent-in-lr-string
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.
Two Pointers,String
Medium
36.3
144,772
52,578
782
682
Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX.
null
794
Swim in Rising Water
swim-in-rising-water
You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim. Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).
Array,Binary Search,Depth-First Search,Breadth-First Search,Union Find,Heap (Priority Queue),Matrix
Hard
58.7
126,837
74,390
1,876
133
Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T.
1753
795
K-th Symbol in Grammar
k-th-symbol-in-grammar
We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.
Math,Bit Manipulation,Recursion
Medium
39.9
208,528
83,191
1,671
246
Try to represent the current (N, K) in terms of some (N-1, prevK). What is prevK ?
null
796
Reaching Points
reaching-points
Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise. The allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).
Math
Hard
31.6
131,046
41,397
936
161
null
null
797
Rabbits in Forest
rabbits-in-forest
There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an integer array answers where answers[i] is the answer of the ith rabbit. Given the array answers, return the minimum number of rabbits that could be in the forest.
Array,Hash Table,Math,Greedy
Medium
55.7
64,908
36,151
709
484
null
null
798
Transform to Chessboard
transform-to-chessboard
You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other. Return the minimum number of moves to transform the board into a chessboard board. If the task is impossible, return -1. A chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.
Array,Math,Bit Manipulation,Matrix
Hard
52
28,761
14,953
287
282
null
null
799
Minimum Distance Between BST Nodes
minimum-distance-between-bst-nodes
Given the root of a Binary Search Tree (BST), return the minimum 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
212,326
118,984
1,591
311
null
94
800
Letter Case Permutation
letter-case-permutation
Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. Return the output in any order.
String,Backtracking,Bit Manipulation
Medium
72.3
288,601
208,542
3,215
142
null
78,1076
801
Is Graph Bipartite?
is-graph-bipartite
There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties: A graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B. Return true if and only if it is bipartite.
Depth-First Search,Breadth-First Search,Union Find,Graph
Medium
50.4
547,070
275,749
4,050
261
null
null
802
K-th Smallest Prime Fraction
k-th-smallest-prime-fraction
You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k. For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j]. Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].
Array,Binary Search,Heap (Priority Queue)
Hard
48.4
53,283
25,777
741
37
null
378,668,719
803
Cheapest Flights Within K Stops
cheapest-flights-within-k-stops
There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei. You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.
Dynamic Programming,Depth-First Search,Breadth-First Search,Graph,Heap (Priority Queue),Shortest Path
Medium
36.1
631,258
227,605
4,765
212
null
568,2230
804
Rotated Digits
rotated-digits
An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone. A number is valid if each digit remains a digit after rotation. For example: Given an integer n, return the number of good integers in the range [1, n].
Math,Dynamic Programming
Medium
57.2
147,318
84,292
569
1,717
null
null
805
Escape The Ghosts
escape-the-ghosts
You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghosts on the map with their starting positions given as a 2D array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the ith ghost. All inputs are integral coordinates. Each turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west, or stay still. All actions happen simultaneously. You escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape. Return true if it is possible to escape regardless of how the ghosts move, otherwise return false.
Array,Math
Medium
60.1
34,912
20,993
96
15
null
1727
806
Domino and Tromino Tiling
domino-and-tromino-tiling
You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes. Given an integer n, return the number of ways to tile an 2 x n board. Since the answer may be very large, return it modulo 109 + 7. In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.
Dynamic Programming
Medium
47.8
96,739
46,286
1,472
572
null
null
807
Custom Sort String
custom-sort-string
You are given two strings order and s. All the words of order are unique and were sorted in some custom order previously. Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string. Return any permutation of s that satisfies this property.
Hash Table,String,Sorting
Medium
69
253,659
175,117
1,969
285
null
null
808
Number of Matching Subsequences
number-of-matching-subsequences
Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
Hash Table,String,Trie,Sorting
Medium
50.5
253,208
127,852
2,889
148
null
392,1051,2186
809
Preimage Size of Factorial Zeroes Function
preimage-size-of-factorial-zeroes-function
Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1. Given an integer k, return the number of non-negative integers x have the property that f(x) = k.
Math,Binary Search
Hard
41.6
28,933
12,050
298
68
null
172
810
Valid Tic-Tac-Toe State
valid-tic-tac-toe-state
Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game. The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square. Here are the rules of Tic-Tac-Toe:
Array,String
Medium
35.2
130,685
45,991
408
959
null
348
811
Number of Subarrays with Bounded Maximum
number-of-subarrays-with-bounded-maximum
Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right]. The test cases are generated so that the answer will fit in a 32-bit integer.
Array,Two Pointers
Medium
52.4
99,463
52,087
1,596
92
null
null
812
Rotate String
rotate-string
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position.
String,String Matching
Easy
52.1
277,996
144,895
1,783
84
null
null
813
All Paths From Source to Target
all-paths-from-source-to-target
Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order. The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).
Backtracking,Depth-First Search,Breadth-First Search,Graph
Medium
80.9
336,541
272,230
3,985
115
null
2090
814
Smallest Rotation with Highest Score
smallest-rotation-with-highest-score
You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are less than or equal to their index are worth one point. Return the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it. If there are multiple answers, return the smallest such index k.
Array,Prefix Sum
Hard
47.4
18,253
8,659
351
21
null
null
815
Champagne Tower
champagne-tower
We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.  Each glass holds one cup of champagne. Then, some champagne is poured into the first glass at the top.  When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.  When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.  (A glass at the bottom row has its excess champagne fall on the floor.) For example, after one cup of champagne is poured, the top most glass is full.  After two cups of champagne are poured, the two glasses on the second row are half full.  After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.  After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below. Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)
Dynamic Programming
Medium
51.2
146,739
75,161
2,315
128
null
1385
816
Design HashSet
design-hashset
Design a HashSet without using any built-in hash table libraries. Implement MyHashSet class:
Array,Hash Table,Linked List,Design,Hash Function
Easy
63.8
272,165
173,570
1,258
153
null
817,1337
817
Design HashMap
design-hashmap
Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class:
Array,Hash Table,Linked List,Design,Hash Function
Easy
63.8
438,707
279,868
2,553
273
null
816,1337
818
Similar RGB Color
similar-rgb-color
null
Math,String,Enumeration
Easy
63.8
19,662
12,535
79
488
null
null
819
Minimum Swaps To Make Sequences Increasing
minimum-swaps-to-make-sequences-increasing
You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i]. Return the minimum number of needed operations to make nums1 and nums2 strictly increasing. The test cases are generated so that the given input always makes it possible. An array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < ... < arr[arr.length - 1].
Array,Dynamic Programming
Hard
39.2
133,894
52,429
1,974
123
null
2234
820
Find Eventual Safe States
find-eventual-safe-states
There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i]. A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node. Return an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.
Depth-First Search,Breadth-First Search,Graph,Topological Sort
Medium
52.5
145,782
76,472
2,014
313
null
null
821
Bricks Falling When Hit
bricks-falling-when-hit
You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if: You are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location (if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks). Return an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied. Note that an erasure may refer to a location with no brick, and if it does, no bricks drop.
Array,Union Find,Matrix
Hard
33.8
72,657
24,575
787
169
null
2101,2322
822
Unique Morse Code Words
unique-morse-code-words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: For convenience, the full table for the 26 letters of the English alphabet is given below: Given an array of strings words where each word can be written as a concatenation of the Morse code of each letter. Return the number of different transformations among all words we have.
Array,Hash Table,String
Easy
80
268,477
214,725
1,205
1,020
null
null
823
Split Array With Same Average
split-array-with-same-average
You are given an integer array nums. You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B). Return true if it is possible to achieve that and false otherwise. Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.
Array,Math,Dynamic Programming,Bit Manipulation,Bitmask
Hard
26.5
95,370
25,304
804
115
null
2162
824
Number of Lines To Write String
number-of-lines-to-write-string
You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on. You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s. Return an array result of length 2 where:
Array,String
Easy
66
80,919
53,412
375
1,114
null
null
825
Max Increase to Keep City Skyline
max-increase-to-keep-city-skyline
There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of the building located in the block at row r and column c. A city's skyline is the the outer contour formed by all the building when viewing the side of the city from a distance. The skyline from each cardinal direction north, east, south, and west may be different. We are allowed to increase the height of any number of buildings by any amount (the amount can be different per building). The height of a 0-height building can also be increased. However, increasing the height of a building should not affect the city's skyline from any cardinal direction. Return the maximum total sum that the height of the buildings can be increased by without changing the city's skyline from any cardinal direction.
Array,Greedy,Matrix
Medium
85.5
143,254
122,448
1,688
413
null
null
826
Soup Servings
soup-servings
There are two types of soup: type A and type B. Initially, we have n ml of each type of soup. There are four kinds of operations: When we serve some soup, we give it to someone, and we no longer have it. Each turn, we will choose from the four operations with an equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as possible. We stop once we no longer have some quantity of both types of soup. Note that we do not have an operation where all 100 ml's of soup B are used first. Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time. Answers within 10-5 of the actual answer will be accepted.
Math,Dynamic Programming,Probability and Statistics
Medium
42.4
34,595
14,657
255
744
null
null
827
Expressive Words
expressive-words
Sometimes people repeat letters to represent extra feeling. For example: In these strings like "heeellooo", we have groups of adjacent letters that are all the same: "h", "eee", "ll", "ooo". You are given a string s and an array of query strings words. A query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is three or more. Return the number of query strings that are stretchy.
Array,Two Pointers,String
Medium
46.4
203,689
94,487
696
1,616
null
null