question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
find-minimum-time-to-reach-last-room-ii
Slight Modification from part 1 of this question
slight-modification-from-part-1-of-this-hgy21
Intuition\n Describe your first thoughts on how to solve this problem. \nIt says that you have alternating cost for between edges, so maybe keep track of a inde
yamuprajapati05
NORMAL
2024-11-04T06:40:09.576953+00:00
2024-11-04T06:40:09.576988+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt says that you have alternating cost for between edges, so maybe keep track of a index.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis will help to tell you whether this move will cost 1 or 2 based on the ind...
0
0
['C++']
0
find-minimum-time-to-reach-last-room-ii
JAVA solution | using Heap
java-solution-using-heap-by-chiranjeeb2-o2hz
The solution below is the extension of the simplified version of this problem \n\nhttps://leetcode.com/problems/find-minimum-time-to-reach-last-room-i/discuss/6
chiranjeeb2
NORMAL
2024-11-03T23:21:18.435826+00:00
2024-11-03T23:26:52.239681+00:00
12
false
The solution below is the extension of the simplified version of this problem \n\nhttps://leetcode.com/problems/find-minimum-time-to-reach-last-room-i/discuss/6003977/JAVA-Solution-or-using-heap\n\n```\npublic int minTimeToReach(int[][] moveTime) {\n int m = moveTime.length, n = moveTime[0].length;\n \n ...
0
0
['Heap (Priority Queue)', 'Java']
0
find-minimum-time-to-reach-last-room-ii
🚀 C# Priority Queue with Memory Optimization for Pathfinding
c-priority-queue-with-memory-optimizatio-ptln
\n\n\n## Intuition:\nTo find the minimum time to reach the bottom-right corner of a grid while considering movement penalties, we can apply an optimized pathfin
ivanvinogradov207
NORMAL
2024-11-03T21:26:11.918535+00:00
2024-11-04T02:02:48.419213+00:00
16
false
![image.png](https://assets.leetcode.com/users/images/c8f0ed37-c0f5-4901-b5d9-a84cc5cdb579_1730685761.0166764.png)\n\n\n## Intuition:\nTo find the minimum time to reach the bottom-right corner of a grid while considering movement penalties, we can apply an optimized pathfinding algorithm using a priority queue. The ide...
0
0
['Depth-First Search', 'Memoization', 'Queue', 'Heap (Priority Queue)', 'Shortest Path', 'C#']
0
find-minimum-time-to-reach-last-room-ii
Beats 100% ✅ ✅ | Dijkstra's | Heap 🌟 🌟
beats-100-dijkstras-heap-by-ram_tanniru-m6o2
Intuition\nThe problem resembles a shortest path problem where we need to reach the bottom-right corner of a grid with the minimum time cost. Since each cell ha
ram_tanniru
NORMAL
2024-11-03T18:23:47.871003+00:00
2024-11-03T18:23:47.871033+00:00
19
false
### Intuition\nThe problem resembles a shortest path problem where we need to reach the bottom-right corner of a grid with the minimum time cost. Since each cell has a specific time to traverse, and there\'s a toggle condition affecting the time cost, Dijkstra\'s algorithm (minimum priority queue) is well-suited. We tr...
0
0
['Heap (Priority Queue)', 'Shortest Path', 'Java', 'Python3']
0
find-minimum-time-to-reach-last-room-ii
Python solution(Dijkstra)
python-solutiondijkstra-by-tzju4iid9i-dzd4
Complexity\n- Time complexity: O(N*M(logNM))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(NM)\n Add your space complexity here, e.g. O(n)
TzjU4iID9I
NORMAL
2024-11-03T17:46:25.465639+00:00
2024-11-03T17:46:25.465666+00:00
6
false
# Complexity\n- Time complexity: O(N*M(logNM))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(NM)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n def minTimeToReach(self, moveTime: List[List[int]]) -> int:\n if not moveTime:\n...
0
0
['Python3']
0
find-minimum-time-to-reach-last-room-ii
Same code as 3341 with only 1 change | Easy and beginner friendly
same-code-as-3341-with-only-1-change-eas-i0vz
\n# Code\ncpp []\nclass Solution {\npublic:\n int minTimeToReach(vector<vector<int>>& moveTime) {\n int row = moveTime.size();\n int col = move
AMANJOTSINGH14
NORMAL
2024-11-03T16:55:42.769868+00:00
2024-11-03T16:55:42.769896+00:00
10
false
\n# Code\n```cpp []\nclass Solution {\npublic:\n int minTimeToReach(vector<vector<int>>& moveTime) {\n int row = moveTime.size();\n int col = moveTime[0].size();\n priority_queue<tuple<int, int, int,int>, vector<tuple<int, int, int,int>>,greater<tuple<int, int, int,int>>> pq;\n vector<vec...
0
0
['C++']
0
find-minimum-time-to-reach-last-room-ii
extended dijkstra
extended-dijkstra-by-joshuadlima-34r3
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
joshuadlima
NORMAL
2024-11-03T16:42:30.321768+00:00
2024-11-03T16:42:30.321788+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n * m * log(n * m))\n\n- Space complexity: O(n * m)\n\n# Code\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n vec...
0
0
['C++']
0
falling-squares
Easy Understood O(n^2) Solution with explanation
easy-understood-on2-solution-with-explan-us8x
The idea is quite simple, we use intervals to represent the square. the initial height we set to the square cur is pos[1]. That means we assume that all the squ
leuction
NORMAL
2017-10-15T03:04:30.634000+00:00
2018-10-25T01:50:26.012499+00:00
10,226
false
The idea is quite simple, we use intervals to represent the square. the initial height we set to the square `cur` is `pos[1]`. That means we assume that all the square will fall down to the land. we iterate the previous squares, check is there any square `i` beneath my `cur` square. If we found that we have squares `i`...
96
1
['Java']
16
falling-squares
Treemap solution and Segment tree (Java) solution with lazy propagation and coordinates compression
treemap-solution-and-segment-tree-java-s-pmsc
Here is the link I refer to:\nhttps://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/\nhttps://leetcode.com/articles/falling-squares/\n\nI think the fir
britishorthair
NORMAL
2018-01-28T00:42:53.703000+00:00
2018-09-30T00:24:33.983749+00:00
7,265
false
Here is the link I refer to:\nhttps://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/\nhttps://leetcode.com/articles/falling-squares/\n\nI think the first link is pretty useful to help you understand the segment tree's basic and lazy propagation. The second link I really appreciate its systematic way to define ...
70
1
[]
11
falling-squares
Easy and Concise Python Solution (97%)
easy-and-concise-python-solution-97-by-l-rx3z
I used two list to take note of the current state.\nIf you read question 218. The Skyline Problem, you will easily understand how I do this.\n\npos tracks the x
lee215
NORMAL
2017-10-15T03:18:19.858000+00:00
2018-10-12T18:03:48.384902+00:00
6,636
false
I used two list to take note of the current state.\nIf you read question **218. The Skyline Problem**, you will easily understand how I do this.\n\n```pos``` tracks the x-coordinate of start points.\n```height``` tracks the y-coordinate of lines.\n\n![0_1508239910449_skyline.png](/assets/uploads/files/1508239911437-sky...
52
2
[]
14
falling-squares
C++ O(nlogn)
c-onlogn-by-imrusty-b7lk
Similar to skyline concept, going from left to right the path is decomposed to consecutive segments, and each segment has a height. Each time we drop a new squa
imrusty
NORMAL
2017-10-16T03:07:44.821000+00:00
2018-09-18T18:17:40.831226+00:00
3,532
false
Similar to skyline concept, going from left to right the path is decomposed to consecutive segments, and each segment has a height. Each time we drop a new square, then update the level map by erasing & creating some new segments with possibly new height. There are at most 2n segments that are created / removed through...
19
0
[]
8
falling-squares
Easy Understood TreeMap Solution
easy-understood-treemap-solution-by-liuk-1180
The squares divide the number line into many segments with different heights. Therefore we can use a TreeMap to store the number line. The key is the starting p
liukx08
NORMAL
2017-10-17T01:57:35.736000+00:00
2018-10-10T06:18:27.132197+00:00
3,311
false
The squares divide the number line into many segments with different heights. Therefore we can use a TreeMap to store the number line. The key is the starting point of each segment and the value is the height of the segment. For every new falling square (s, l), we update those segments between s and s + l.\n```\nclass ...
16
0
[]
8
falling-squares
Java - keep it simple, beats 99.6%
java-keep-it-simple-beats-996-by-tsuvmxw-7pxd
So we have N squares, 2N end points, 2N-1 intervals. We want to update the heights of intervals covered by a new square. Intervals are fixed; no insertion, merg
tsuvmxwu
NORMAL
2017-10-31T19:23:29.249000+00:00
2018-10-11T01:43:09.164849+00:00
1,668
false
So we have N squares, 2N end points, 2N-1 intervals. We want to update the heights of intervals covered by a new square. Intervals are fixed; no insertion, merging etc. Sort and binary-search.\n\n```\n public List<Integer> fallingSquares(int[][] positions)\n {\n int[] ends = new int[positions.length*2];\n ...
14
0
[]
4
falling-squares
Segment tree with lazy propagation and coordinates compression
segment-tree-with-lazy-propagation-and-c-ljjo
Understand the problem first\nInput: positions = [[1, 2], [2, 3], [6, 1]]\nAnd it will look like below, so you can easily get the result: [2, 5, 5]\n\n\nWith th
suensky2014
NORMAL
2021-03-06T05:10:51.066880+00:00
2021-03-06T05:10:51.066915+00:00
1,174
false
## Understand the problem first\nInput: `positions = [[1, 2], [2, 3], [6, 1]]`\nAnd it will look like below, so you can easily get the result: `[2, 5, 5]`\n![image](https://assets.leetcode.com/users/images/01eff168-05ee-415d-9948-9d687339db9e_1615006427.5494444.png)\n\nWith that, we can come up with the straightforward...
12
0
[]
4
falling-squares
C++ Segment Tree with range compression (easy & compact)
c-segment-tree-with-range-compression-ea-im0e
It is a good practice to use lazy propagation with range updates but since this problem has lesser number of points (1000), we can normally do it with segment t
leetcode07
NORMAL
2020-07-17T13:13:44.587899+00:00
2020-07-17T13:18:27.632288+00:00
1,058
false
It is a good practice to use lazy propagation with range updates but since this problem has lesser number of points (1000), we can normally do it with segment tree and range compression (otherwise both memory and time exceeds). \n\nIf you are not good at segment trees please read the following artice: https://cp-algori...
12
0
[]
1
falling-squares
Python 3 || 9 lines, bisect || T/S: 99% / 81%
python-3-9-lines-bisect-ts-99-81-by-spau-b3kw
\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n\n def helper(box: List[int])->int:\n\n l, h = box\
Spaulding_
NORMAL
2023-09-15T21:34:52.910832+00:00
2024-05-29T18:14:17.590275+00:00
507
false
```\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n\n def helper(box: List[int])->int:\n\n l, h = box\n r = l + h\n \n i, j = bisect_right(pos, l), bisect_left (pos, r)\n\n res = h + max(hgt[i-1:j], default = 0)\n ...
11
0
['Python3']
3
falling-squares
Python with dict, O(N^2) solution with comments
python-with-dict-on2-solution-with-comme-q5ij
\nclass Solution:\n def fallingSquares(self, positions):\n """\n :type positions: List[List[int]]\n :rtype: List[int]\n """\n
codercorgi
NORMAL
2017-10-17T05:01:04.894000+00:00
2018-10-03T00:59:56.445702+00:00
1,049
false
```\nclass Solution:\n def fallingSquares(self, positions):\n """\n :type positions: List[List[int]]\n :rtype: List[int]\n """\n ans = []\n heights = {}\n for pos, side in positions:\n # finds nearby positions, if any\n left, right = pos, pos+sid...
11
0
[]
4
falling-squares
Java 14ms, beats 99.38% using interval tree
java-14ms-beats-9938-using-interval-tree-yvd2
java\nclass Solution {\n \n class Node {\n public int l;\n public int r;\n public int max;\n public int height;\n publi
zhewang711
NORMAL
2017-12-17T08:07:36.618000+00:00
2018-09-04T16:19:03.612324+00:00
1,836
false
```java\nclass Solution {\n \n class Node {\n public int l;\n public int r;\n public int max;\n public int height;\n public Node left;\n public Node right;\n \n public Node (int l, int r, int max, int height) {\n this.l = l;\n this.r = ...
11
1
[]
3
falling-squares
O(nlogn) C++ Segment Tree
onlogn-c-segment-tree-by-sean-lan-uk23
\nclass Solution {\npublic:\n int n;\n vector<int> height, lazy;\n\n void push_up(int i) {\n height[i] = max(height[i*2], height[i*2+1]);\n }\n\n void p
sean-lan
NORMAL
2017-11-08T09:56:55.190000+00:00
2017-11-08T09:56:55.190000+00:00
1,627
false
```\nclass Solution {\npublic:\n int n;\n vector<int> height, lazy;\n\n void push_up(int i) {\n height[i] = max(height[i*2], height[i*2+1]);\n }\n\n void push_down(int i) {\n if (lazy[i]) {\n lazy[i*2] = lazy[i*2+1] = lazy[i];\n height[i*2] = height[i*2+1] = lazy[i];\n lazy[i] = 0;\n ...
10
0
[]
2
falling-squares
✅✅Easy Readable c++ code || Segment Tree with lazy propagation || Cordinate Compression.
easy-readable-c-code-segment-tree-with-l-d0b5
Intuition and Approach\n Describe your first thoughts on how to solve this problem. \nFirst of all, it will feel awkard and you might not get the intution of se
anupamraZ
NORMAL
2023-06-19T13:49:06.035482+00:00
2023-06-19T13:49:06.035503+00:00
804
false
# Intuition and Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst of all, it will feel awkard and you might not get the intution of segment tree. But when you deminish 2D concept into 1D by replacing the height by values at in 1D. Then you will get idea of segment tree.\n\nFor a time ...
9
0
['Segment Tree', 'C++']
3
falling-squares
Clean And Concise Lazy Propagation Segment Tree
clean-and-concise-lazy-propagation-segme-kego
\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n SegmentNode root = new SegmentNode(0,Integer.MAX_VALUE,0);\n Li
gcl272633743
NORMAL
2020-01-31T13:31:13.961105+00:00
2020-01-31T13:31:13.961139+00:00
659
false
```\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n SegmentNode root = new SegmentNode(0,Integer.MAX_VALUE,0);\n List<Integer> ans = new ArrayList<>();\n int max = 0;\n for(int[] p : positions){\n int left = p[0], height = p[1], right = left + hei...
8
0
['Tree', 'Java']
1
falling-squares
C++, map with explanation, O(nlogn) solution 36ms
c-map-with-explanation-onlogn-solution-3-2cs5
The idea is to store all non-overlapping intervals in a tree map, and to update the new height while adding new intervals into the map.\nThe interval is represe
zestypanda
NORMAL
2017-10-15T04:29:35.357000+00:00
2017-10-15T04:29:35.357000+00:00
939
false
The idea is to store all non-overlapping intervals in a tree map, and to update the new height while adding new intervals into the map.\nThe interval is represented by left bound l, right bound r, and height h. The format in the map is \n'''\ninvals[l] = {r, h};\n'''\nThe number of intervals in the map is at most 2n. T...
7
0
[]
4
falling-squares
C++ | segment tree | lazy propagations | O(n^2) |O(nlogn) | solution with Explanation
c-segment-tree-lazy-propagations-on2-onl-2o6t
So, here the heightOfSquare[i] will be max(heightOfSquare[j] where j < i and that are overlap with square[i] via x coordinate) + sideLength[i] (i.e. positions[i
ghoshashis545
NORMAL
2021-08-04T19:25:32.378322+00:00
2021-09-05T06:45:17.531356+00:00
628
false
So, here the **heightOfSquare**[i] will be **max**(**heightOfSquare**[j] where j < i and that are overlap with **square**[i] via x coordinate) + **sideLength**[i] (i.e. **positions**[i][1]).\n\nBut, **results**[i] will be **max**(**prefixResult**,**heightOfSquare**[i]) because it may happen that tallest square is not i...
6
1
[]
3
falling-squares
c++, map based short solution
c-map-based-short-solution-by-jadenpan-0nd4
The running time complexity should be O(n\xb2), since the bottleneck is given by finding the maxHeight in certain range.\nIdea is simple, we use a map, and map[
jadenpan
NORMAL
2017-10-15T07:21:32.667000+00:00
2017-10-15T07:21:32.667000+00:00
1,702
false
The running time complexity should be O(n\xb2), since the bottleneck is given by finding the maxHeight in certain range.\nIdea is simple, we use a map, and ```map[i] = h``` means, from ```i``` to next adjacent x-coordinate, inside this range, the height is ```h```.\nTo handle edge cases like adjacent squares, I applied...
6
1
[]
2
falling-squares
Python Diffenrent Concise Solutions
python-diffenrent-concise-solutions-by-g-psez
Thanks this great work : https://leetcode.com/articles/falling-squares/ \n\n\nApproach 1 :\njust like this article said , there are two operations: \n>update, w
gyh75520
NORMAL
2019-10-20T08:29:48.747310+00:00
2019-10-20T11:14:40.157677+00:00
474
false
Thanks this great work : https://leetcode.com/articles/falling-squares/ \n\n\n**Approach 1 :**\njust like this article said , there are two operations: \n>update, which updates our notion of the board (number line) after dropping a square; \n>query, which finds the largest height in the current board on some interval.\...
4
0
['Python3']
1
falling-squares
Java segment tree O(position.length * log(max_range))
java-segment-tree-opositionlength-logmax-paf7
My first segment tree ever.\n\n\n class SegNode {\n int left, mid, right;\n int max;\n boolean modified;\n SegNode leftChild, rig
qamichaelpeng
NORMAL
2017-10-15T06:15:06.577000+00:00
2017-10-15T06:15:06.577000+00:00
1,213
false
My first segment tree ever.\n```\n\n class SegNode {\n int left, mid, right;\n int max;\n boolean modified;\n SegNode leftChild, rightChild;\n SegNode(int left, int right, int max){\n this.left=left;\n this.right=right;\n this.mid=left+(right-left)/...
4
1
[]
2
falling-squares
C++ O(n(log(n)) time O(n) space
c-onlogn-time-on-space-by-imrusty-80rj
Similar to skyline concept, going from left to right the path is decomposed to consecutive segments, and each segment has a height. Each time we drop a new squa
imrusty
NORMAL
2017-10-16T03:07:03.540000+00:00
2017-10-16T03:07:03.540000+00:00
1,281
false
Similar to skyline concept, going from left to right the path is decomposed to consecutive segments, and each segment has a height. Each time we drop a new square, then update the level map by erasing & creating some new segments with possibly new height. There are at most 2n segments that are created / removed through...
4
0
[]
4
falling-squares
C++ coordinate compression
c-coordinate-compression-by-colinyoyo26-3hnt
\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& ps) {\n set<int> sx;\n for (auto &p : ps) sx.emplace(p[0]), sx.em
colinyoyo26
NORMAL
2021-09-03T05:11:06.974756+00:00
2021-09-03T05:12:14.663191+00:00
163
false
```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& ps) {\n set<int> sx;\n for (auto &p : ps) sx.emplace(p[0]), sx.emplace(p[0] + p[1]);\n vector<int> x(sx.begin(), sx.end()), hs(x.size()), ans;\n unordered_map<int, int> idx;\n for (int i = 0; auto t : ...
3
0
[]
0
falling-squares
Segment Tree Lazy Propagation || O(nlog(n)) || C++
segment-tree-lazy-propagation-onlogn-c-b-hfia
I used an unordered map as the container of the segment tree, whose expected complexity is O(1).\n\n\nvector<int> fallingSquares(vector<vector<int>>& p) {\n
NAHDI51
NORMAL
2021-07-22T15:45:52.105682+00:00
2021-07-22T15:48:19.000690+00:00
296
false
I used an unordered map as the container of the segment tree, whose expected complexity is O(1).\n\n```\nvector<int> fallingSquares(vector<vector<int>>& p) {\n segment_tree seg((int)(1e8+1e6)+1); //Boundary position\n int mx = 0;\n vector<int> ans;\n for(int i = 0; i < p.size(); i++) {\n int h = p[...
3
0
['Tree', 'C']
0
falling-squares
[Java]Easy to understand plain segment tree
javaeasy-to-understand-plain-segment-tre-bb8i
\nclass Solution {\n class Node {\n int low, high;\n Node left, right;\n int val;\n public Node(int low, int high, int val) {\n
fang2018
NORMAL
2020-09-05T07:06:36.788386+00:00
2020-09-05T07:33:53.665661+00:00
187
false
```\nclass Solution {\n class Node {\n int low, high;\n Node left, right;\n int val;\n public Node(int low, int high, int val) {\n this.low = low;\n this.high = high;\n this.val = val;\n }\n @Override\n public String toString() {\n ...
3
0
[]
0
falling-squares
C++ O(NlogN) TreeMap
c-onlogn-treemap-by-laseinefirenze-9fmh
In this question squares are only added without being removed, so a new, higher square will cover all squares under it. These squares are no longer needed to co
laseinefirenze
NORMAL
2018-10-22T02:41:49.430750+00:00
2018-10-22T02:41:49.430832+00:00
390
false
In this question squares are only added without being removed, so a new, higher square will cover all squares under it. These squares are no longer needed to consider, so we could just remove them from our records of heights. \nI used a ```TreeMap``` to record all useful heights. Every square adds 2 points to the recor...
3
0
[]
2
falling-squares
Python binary search 44ms
python-binary-search-44ms-by-kleedy-fz1v
\nclass Solution(object):\n def fallingSquares(self, positions):\n axis = [0, float(\'inf\')]\n heights = [0, 0]\n an = [0]\n for
kleedy
NORMAL
2018-06-02T06:47:59.399013+00:00
2018-09-29T06:04:30.982828+00:00
486
false
```\nclass Solution(object):\n def fallingSquares(self, positions):\n axis = [0, float(\'inf\')]\n heights = [0, 0]\n an = [0]\n for left,length in positions:\n right = left + length\n idl = bisect.bisect_right(axis, left)\n idr = bisect.bisect_left(axis, ...
3
0
[]
1
falling-squares
Python, O(n^2) solution, with explanation
python-on2-solution-with-explanation-by-6bihn
usesq to store information of squares. sq[i][0] is left edge, sq[i][1] is length, sq[i][2] is highest point. Everytime a new square falls, check if it has overl
bigbiang
NORMAL
2017-10-15T03:34:06.529000+00:00
2017-10-15T03:34:06.529000+00:00
457
false
use```sq``` to store information of squares. ```sq[i][0]``` is left edge, ```sq[i][1]``` is length, ```sq[i][2]``` is highest point. Everytime a new square falls, check if it has overlap with previous ```sq```, if so, add the largest ```sq[i][2]``` to its height.\n```\nclass Solution(object):\n def fallingSquares(se...
3
2
[]
0
falling-squares
O(n^2) solution with explanation
on2-solution-with-explanation-by-yorkshi-57e0
The height of the base of each box is the highest top of any other box already dropped that overlaps along the x-axis.\n\nSo for each box, we iterate over all p
yorkshire
NORMAL
2017-10-15T03:43:04.449000+00:00
2017-10-15T03:43:04.449000+00:00
671
false
The height of the base of each box is the highest top of any other box already dropped that overlaps along the x-axis.\n\nSo for each box, we iterate over all previously dropped boxes to find the base_height of the new box. The default is zero (ground level) if no overlaps are found.\nIf there is no overlap between a b...
3
1
['Python']
1
falling-squares
Python Segment Tree with Lazy Propagation
python-segment-tree-with-lazy-propagatio-w01y
http://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/\n\n\nclass Solution:\n def fallingSquares(self, positions):\n """\n :type positi
notz22
NORMAL
2017-12-08T03:16:14.271000+00:00
2017-12-08T03:16:14.271000+00:00
493
false
http://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/\n\n```\nclass Solution:\n def fallingSquares(self, positions):\n """\n :type positions: List[List[int]]\n :rtype: List[int]\n """\n # compress positions into consecutive indices\n all_pos = set()\n for p i...
3
0
[]
0
falling-squares
Lazy propagation | Point compression | Python
lazy-propagation-point-compression-pytho-z093
Intuition\n Describe your first thoughts on how to solve this problem. \nRange update speaks segment tree.\n\n# Approach\n Describe your approach to solving the
tarushfx
NORMAL
2024-01-19T16:21:41.090294+00:00
2024-01-19T16:21:41.090324+00:00
109
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nRange update speaks segment tree.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Lazy propagation + Point compression**:\nUse max function instead of the regular addition function.\nAlso since the squares are go...
2
0
['Segment Tree', 'Python3']
0
falling-squares
Solution
solution-by-deleted_user-wr9k
C++ []\n#include <vector>\n#include <algorithm>\n#include <iterator>\n\nstruct SegmentTree {\n\n SegmentTree(int n) : n(n) {\n size = 1;\n whil
deleted_user
NORMAL
2023-04-20T12:29:29.066873+00:00
2023-04-20T13:48:12.825343+00:00
906
false
```C++ []\n#include <vector>\n#include <algorithm>\n#include <iterator>\n\nstruct SegmentTree {\n\n SegmentTree(int n) : n(n) {\n size = 1;\n while (size < n) {\n size <<= 1;\n }\n tree.resize(2*size);\n lazy.resize(2*size);\n }\n\n void add_range(int l, int r, int...
2
0
['C++', 'Java', 'Python3']
0
falling-squares
java solutions
java-solutions-by-infox_92-zjpg
\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n int max = 0;\n List<Integer> result = new ArrayList<>();\n
Infox_92
NORMAL
2022-11-06T16:17:40.701918+00:00
2022-11-06T16:17:40.701991+00:00
571
false
```\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n int max = 0;\n List<Integer> result = new ArrayList<>();\n TreeSet<Node> nodes = new TreeSet<>((n1, n2) -> n1.l - n2.l);\n // start position 0, height 0\n nodes.add(new Node(0, 0));\n for (int...
2
0
['Java', 'JavaScript']
1
falling-squares
c++ | easy | short
c-easy-short-by-venomhighs7-pwg0
\n# Code\n\nclass Solution {\npublic:\n unordered_map<int, int> mp; //used for compression\n int tree[8000]; //tree[i] holds the maximum height for its co
venomhighs7
NORMAL
2022-10-29T14:17:33.817598+00:00
2022-10-29T14:17:33.817641+00:00
710
false
\n# Code\n```\nclass Solution {\npublic:\n unordered_map<int, int> mp; //used for compression\n int tree[8000]; //tree[i] holds the maximum height for its corresponding range\n \n void update(int t, int low, int high, int i, int j, int h){\n if(i>j)\n return;\n if(low==high){\n ...
2
0
['C++']
0
falling-squares
Python (dynamic) segment tree with Lazy-Propagation O(NLogN)
python-dynamic-segment-tree-with-lazy-pr-6uoh
I find solution 4 a little confusing. I have implemented a dynamic segment tree with Lazy-Propagation, inspired by @luxy622:\n\nfrom collections import defaultd
ginward
NORMAL
2022-05-14T11:55:49.619008+00:00
2022-05-14T11:59:06.920429+00:00
212
false
I find solution 4 a little confusing. I have implemented a dynamic segment tree with Lazy-Propagation, inspired by [@luxy622:](https://leetcode.com/problems/my-calendar-iii/discuss/214831/Python-13-Lines-Segment-Tree-with-Lazy-Propagation-O(1)-time)\n```\nfrom collections import defaultdict\nclass Solution:\n def qu...
2
0
['Tree']
0
falling-squares
Simple bruteforce solution C++
simple-bruteforce-solution-c-by-hieudoan-0xd4
The constraint is just small, who do you bother to use overkilled weapon like segment tree (ofcouse compression in advance)\n\nclass Solution {\npublic:\n ve
hieudoan190598
NORMAL
2022-03-24T06:59:11.385202+00:00
2022-03-24T06:59:11.385245+00:00
204
false
The constraint is just small, who do you bother to use overkilled weapon like segment tree (ofcouse compression in advance)\n```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& a) {\n int n = a.size();\n vector<int> ans(n, 0);\n for(int i=0; i<n; i++) {\n ...
2
0
[]
1
falling-squares
C++ segment tree
c-segment-tree-by-vikassingh2810-ehuc
\nclass node\n{\n public:\n int hei,max_hei;\n int s,e;\n node* l;\n node* r;\n node(int s,int e):hei(0),max_hei(0),s(s),e(e),l(NULL),r(NULL)\n
vikassingh2810
NORMAL
2021-11-02T05:32:01.474714+00:00
2021-11-02T05:32:01.474741+00:00
190
false
```\nclass node\n{\n public:\n int hei,max_hei;\n int s,e;\n node* l;\n node* r;\n node(int s,int e):hei(0),max_hei(0),s(s),e(e),l(NULL),r(NULL)\n {}\n};\nclass Solution {\n \n public:\n node* build(vector<int>&nums,int s,int e)\n {\n if(s>=e)\n return NULL;\n if(...
2
0
[]
0
falling-squares
If you don't know segment trees or facing difficulty in understanding the solutions!
if-you-dont-know-segment-trees-or-facing-he3a
Being not very comfortable with advanced algorithms, I just tried to optimise my brute force solution by a method which is apparantly called \'Coordinate Compre
diggy26
NORMAL
2021-10-18T10:31:44.554865+00:00
2021-10-29T13:02:47.481027+00:00
214
false
Being not very comfortable with advanced algorithms, I just tried to optimise my brute force solution by a method which is apparantly called \'Coordinate Compression\'. This solution beats 58% of submissions. Of course, there are better methods which works in O(n log(n)) but this solution would be a decent start if you...
2
0
['C']
1
falling-squares
[Java] Simple brute force solution, beats 71.5%T and 100%S
java-simple-brute-force-solution-beats-7-c8se
Runtime: 19 ms, faster than 71.50% of Java online submissions for Falling Squares.\nMemory Usage: 39.2 MB, less than 100.00% of Java online submissions for Fall
xiaoshuixin
NORMAL
2020-11-20T09:16:50.875329+00:00
2020-11-20T09:16:50.875372+00:00
194
false
Runtime: 19 ms, faster than 71.50% of Java online submissions for Falling Squares.\nMemory Usage: 39.2 MB, less than 100.00% of Java online submissions for Falling Squares.\n```\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n int n = positions.length;\n int[] height = new...
2
0
[]
2
falling-squares
Kotlin - Segment Tree, Binary Tree Implementation, with Lazy Propagation
kotlin-segment-tree-binary-tree-implemen-0t8h
\nclass Solution {\n fun fallingSquares(positions: Array<IntArray>): List<Int> {\n val root = SegmentTree()\n \n val ans = mutableListOf
idiotleon
NORMAL
2020-11-16T03:07:44.029339+00:00
2020-11-16T03:17:58.109978+00:00
539
false
```\nclass Solution {\n fun fallingSquares(positions: Array<IntArray>): List<Int> {\n val root = SegmentTree()\n \n val ans = mutableListOf<Int>()\n var tallest = 0\n \n for((start, sideLen) in positions){\n val end = start + sideLen\n \n val...
2
0
['Kotlin']
0
falling-squares
C++ O(nlog(n)) solution beats 95%
c-onlogn-solution-beats-95-by-gooong-wq05
Hi, this is my concise and fast C++ solution based on set. We use this set to store the height of each interval and update iteratively.\n\n\nvector<int> falling
gooong
NORMAL
2020-10-09T13:48:48.009600+00:00
2020-10-09T13:48:48.009633+00:00
206
false
Hi, this is my concise and fast C++ solution based on `set`. We use this set to store the height of each interval and update iteratively.\n\n```\nvector<int> fallingSquares(vector<vector<int>>& positions) {\n\tvector<int> ret;\n\tmap<int, int> r2h; // right to height\n\tr2h[INT_MAX] = 0;\n\tint maxh = 0;\n\tfor(auto &p...
2
3
[]
0
falling-squares
[Python] Segment Tree with LP
python-segment-tree-with-lp-by-zero_to_t-do9z
Idea: Denote N = number of squares; create 2 * N lines corresponding to left and right edges of every squares. These 2 * N lines define our 2 * N segments. Segm
zero_to_twelve
NORMAL
2020-07-09T08:10:19.451681+00:00
2020-07-09T08:10:19.451718+00:00
192
false
**Idea:** Denote N = number of squares; create 2 * N lines corresponding to left and right edges of every squares. These 2 * N lines define our 2 * N segments. Segment Tree serve to provide height of each segment.\nFor each incoming square, we use binary search to find its left edge and right edge, and update the heigh...
2
0
[]
0
falling-squares
3 Clean Incrementally Difficult Recursive Segment Tree (Simple, Compressed, Lazy)
3-clean-incrementally-difficult-recursiv-iie0
I try to code recursive segment trees instead of array-based ones since they are easier to understand. Even if they are a bit slower, they still easily meet the
thaicurry
NORMAL
2020-06-10T08:00:10.681270+00:00
2020-06-10T15:05:44.035086+00:00
133
false
I try to code recursive segment trees instead of array-based ones since they are easier to understand. Even if they are a bit slower, they still easily meet the time limit for LeetCode and programming interviews.\n\nHere, I have 3 steadily harder implementations of the Segment Tree so that it is easier to understand.\n...
2
1
[]
1
falling-squares
python3 bisect solution
python3-bisect-solution-by-butterfly-777-ku7h
```\nfrom bisect import bisect_left as bl, bisect_right as br\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n
butterfly-777
NORMAL
2019-05-28T03:33:09.081574+00:00
2019-05-28T03:33:09.081626+00:00
149
false
```\nfrom bisect import bisect_left as bl, bisect_right as br\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n ans, xs, hs = [], [0], [0]\n for (x, h) in positions:\n i, j = br(xs, x), bl(xs, x+h)\n H = max(hs[max(i-1, 0):j], default = 0) + h...
2
0
[]
1
falling-squares
Java 44ms solution. Segment tree with lazy propagation
java-44ms-solution-segment-tree-with-laz-721u
\nclass Solution {\n public static class SegmentTree {\n TreeNode root;\n public class TreeNode {\n TreeNode left;\n Tree
zq670067
NORMAL
2018-10-23T18:58:11.402083+00:00
2018-10-23T18:58:11.402138+00:00
313
false
```\nclass Solution {\n public static class SegmentTree {\n TreeNode root;\n public class TreeNode {\n TreeNode left;\n TreeNode right;\n int leftBound;\n int rightBound;\n int lazy;\n int max;\n public TreeNode(int l,int r,in...
2
0
[]
1
falling-squares
Super Simple Java Solution - TreeSet with explanation
super-simple-java-solution-treeset-with-rvm45
The solution is simple as follows:\n1- We need to records 3 things of each square: {start point, end point, current height}\nstart point is given;\nend point is
bmask
NORMAL
2018-07-30T04:07:23.330291+00:00
2018-07-30T04:07:23.330291+00:00
211
false
The solution is simple as follows:\n1- We need to records 3 things of each square: {start point, end point, current height}\nstart point is given;\nend point is : start+end-1;\ncurrent height is: if it lies on any square it will be baseSquareHeight+side_length otherwise it will be side_length\n2- Whenever a new square ...
2
0
[]
0
falling-squares
Simple and Fast c++ using interval tree, beat 99.99%
simple-and-fast-c-using-interval-tree-be-7k5t
// map means current height in interval\n// update by each position\n\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<pair<int, int>>& positi
rico_cpp
NORMAL
2018-06-28T01:25:17.729488+00:00
2018-06-28T01:25:17.729488+00:00
263
false
// map <start, {end, height}> means current height in interval\n// update by each position\n```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<pair<int, int>>& positions) {\n map<int, pair<int,int>> m;\n vector<int> res;\n int maxM = 0;\n for (const auto& p:positions)\n ...
2
0
[]
0
falling-squares
Java ordered linked list, beat 100%, 11ms
java-ordered-linked-list-beat-100-11ms-b-2npu
\n class Node {\n int x, h;\n Node next;\n Node(int x, int h) {\n this.x = x;\n this.h = h;\n }\n }\n
iaming
NORMAL
2017-10-29T21:02:14.871000+00:00
2017-10-29T21:02:14.871000+00:00
255
false
```\n class Node {\n int x, h;\n Node next;\n Node(int x, int h) {\n this.x = x;\n this.h = h;\n }\n }\n public List<Integer> fallingSquares(int[][] positions) {\n int n = positions.length, max = 0;\n List<Integer> ans = new ArrayList<>();\n ...
2
0
[]
0
falling-squares
Easy AC SEGMENT TREE SOLUTION
easy-ac-segment-tree-solution-by-brutefo-q4c6
Intuitionmy first thought is using segmenttree to save the status o every position but it's to large. So I decide to use Segment Tree MapApproachFirst I use Seg
BruteForceEnjoyer
NORMAL
2025-02-18T03:45:49.600328+00:00
2025-02-18T03:45:49.600328+00:00
33
false
# Intuition my first thought is using segmenttree to save the status o every position but it's to large. So I decide to use Segment Tree Map # Approach First I use Segment Tree Map to save to height of every position we visited, i use lazy tree to make my programme faster, we just update the bigger node which include ...
1
0
['Tree', 'Segment Tree', 'Recursion', 'C++']
0
falling-squares
Iterative Segment Tree
iterative-segment-tree-by-aryashp-9y8h
Segment Tree\nI used the iterative implemnetation of segment tree instead of recursive and coordinate compression by binary search\n\n# Complexity\n- Time compl
aryashp
NORMAL
2023-04-02T19:38:51.224430+00:00
2023-04-02T19:38:51.224460+00:00
103
false
# Segment Tree\nI used the iterative implemnetation of segment tree instead of recursive and coordinate compression by binary search\n\n# Complexity\n- Time complexity:\nO(n^2) as instead of performing Lazy Propagation, we can increase the elements falling in range of square edge one by one.\n\n# Code\n```\ntypedef lon...
1
0
['Segment Tree', 'C++']
0
falling-squares
Easy Java Solution O(n^2)
easy-java-solution-on2-by-sabrinakundu77-txfe
Code\n\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n // create ans list\n List<Integer> ans = new ArrayList<>(
sabrinakundu777
NORMAL
2022-12-26T05:18:22.650551+00:00
2022-12-26T05:18:22.650596+00:00
112
false
# Code\n```\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n // create ans list\n List<Integer> ans = new ArrayList<>();\n // create list of intervals we\'ve already\n // visited\n List<int[]> checked = new ArrayList<>();\n // create 2d array of...
1
0
['Java']
0
falling-squares
C# Dynamic Segment Tree (Online search) Beats 100%
c-dynamic-segment-tree-online-search-bea-sae6
Code\n\npublic class Solution {\n public class Node{\n public int l, r, cnt, add;\n public Node(int l, int r, int cnt, int add){\n t
enze_zhang
NORMAL
2022-10-22T09:02:47.709499+00:00
2022-10-22T09:02:47.709527+00:00
45
false
# Code\n```\npublic class Solution {\n public class Node{\n public int l, r, cnt, add;\n public Node(int l, int r, int cnt, int add){\n this.l = l;\n this.r = r;\n this.cnt = cnt;\n this.add = add;\n }\n }\n\n const int N = (int)1e9 + 7, M = 1000...
1
0
['C#']
0
falling-squares
Python sorted list comments O(nlogn)
python-sorted-list-comments-onlogn-by-te-0ycn
I wrote this before looking at other people\'s solutions. It\'s definitely not the most concise, but I think it\'s logically clear what\'s happening. The commen
tet
NORMAL
2022-09-04T08:47:40.332819+00:00
2022-09-04T08:47:40.332849+00:00
134
false
I wrote this before looking at other people\'s solutions. It\'s definitely not the most concise, but I think it\'s logically clear what\'s happening. The comments explain everything but the strategy is to keep a list of ranges and find the tallest height of the ranges which intersect the shadow of the new square. While...
1
0
['Python', 'Python3']
0
falling-squares
Java Solution - Segment Tree
java-solution-segment-tree-by-yihaoye-de32
\nclass Solution {\n \n private Node root;\n \n public List<Integer> fallingSquares(int[][] positions) {\n // \u7EBF\u6BB5\u6811\n int
yihaoye
NORMAL
2022-08-16T10:46:34.784306+00:00
2022-08-16T10:46:34.784332+00:00
253
false
```\nclass Solution {\n \n private Node root;\n \n public List<Integer> fallingSquares(int[][] positions) {\n // \u7EBF\u6BB5\u6811\n int max = (int) (1e9);\n root = new Node(0, max);\n List<Integer> res = new ArrayList<>();\n for (int[] position : positions) {\n ...
1
0
[]
0
falling-squares
[C++] O(n^2) explained with picture, beats 94% memory
c-on2-explained-with-picture-beats-94-me-sy9u
\n\n\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& pos) {\n int n = pos.size(); \n vector <int> h(n); //h[i
ivan-2727
NORMAL
2022-08-11T21:13:46.515449+00:00
2022-08-11T21:15:35.198587+00:00
338
false
![image](https://assets.leetcode.com/users/images/ae0a4c08-77a3-440f-8ca1-a8cf88ddee26_1660252409.4875157.png)\n\n```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& pos) {\n int n = pos.size(); \n vector <int> h(n); //h[i] means the height at which the top surface of ...
1
0
['Dynamic Programming']
0
falling-squares
C++ | Two Methods | Segment Tree + Discretization | Map
c-two-methods-segment-tree-discretizatio-tsd6
Map: O(n^2)\nc++\nclass Solution {\n public:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n vector<int> ans;\n map<int, pair<int, int>>
xjdkc
NORMAL
2022-05-27T22:10:08.083512+00:00
2022-05-27T22:17:55.103887+00:00
616
false
* Map: O(n^2)\n```c++\nclass Solution {\n public:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n vector<int> ans;\n map<int, pair<int, int>> h;\n int max_height = 0;\n for (int i = 0; i < positions.size(); ++i) {\n int left = positions[i][0];\n int right = left + positions[i][1]...
1
0
['Tree', 'C', 'C++']
1
falling-squares
[Python3] brute-force
python3-brute-force-by-ye15-bwd4
\n\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n ans = []\n for i, (x, l) in enumerate(positions): \n
ye15
NORMAL
2021-09-30T02:08:15.929811+00:00
2021-09-30T02:08:15.929866+00:00
139
false
\n```\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n ans = []\n for i, (x, l) in enumerate(positions): \n val = 0\n for ii in range(i): \n xx, ll = positions[ii]\n if xx < x+l and x < xx+ll: val = max(val, ans[...
1
0
['Python3']
1
falling-squares
c++ map: maintain the disjoint intervals
c-map-maintain-the-disjoint-intervals-by-g5wb
\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n map<pair<int, int>, int> i2h;\n int g_max = 0;\n
zlfzeng
NORMAL
2021-07-26T01:39:33.776693+00:00
2021-08-02T02:41:35.776925+00:00
79
false
```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n map<pair<int, int>, int> i2h;\n int g_max = 0;\n vector<int> ret; \n for(auto &p: positions){\n int left = p[0];\n int size = p[1];\n int right = left + size;\...
1
0
[]
0
falling-squares
C++ easy peasy solution using unordered_map
c-easy-peasy-solution-using-unordered_ma-m0pf
Upvote if helpful :)\n\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n unordered_map<int,pair<int,int>> int
tarruuuu
NORMAL
2021-06-17T05:03:55.587195+00:00
2021-06-17T05:03:55.587228+00:00
288
false
Upvote if helpful :)\n```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n unordered_map<int,pair<int,int>> intervals;\n \n vector<int> output;\n int maxheight = 0;\n \n for(auto v:positions){\n int start = v[0];\n ...
1
0
['C', 'C++']
2
falling-squares
Python3 - beats 62.93% 296 ms - Using SortedList as BST and Defining an Ordering in Intervals
python3-beats-6293-296-ms-using-sortedli-h4ms
The approach is to maintain a sorted list of disjoint intervals, and their max height. \nTo do this I have defined an ordering in the intervals. Since brushing
ampl3t1m3
NORMAL
2021-05-06T21:13:42.411297+00:00
2021-05-06T21:13:42.411327+00:00
119
false
The approach is to maintain a sorted list of disjoint intervals, and their max height. \nTo do this I have defined an ordering in the intervals. Since brushing off square sides is not allowed,\nan interval it1 is less than it2 if it1.end <= it1.start.\n(the height is of no consequence when deciding order)\n\nWhenever w...
1
0
[]
1
falling-squares
[Java] brute force, most simple...
java-brute-force-most-simple-by-66brothe-rshq
\nclass Solution {\n public List<Integer> fallingSquares(int[][] A) {\n long max=0;\n List<Integer>res=new ArrayList<>();\n \n Lis
66brother
NORMAL
2020-09-20T23:07:50.604747+00:00
2020-09-20T23:07:50.604791+00:00
104
false
```\nclass Solution {\n public List<Integer> fallingSquares(int[][] A) {\n long max=0;\n List<Integer>res=new ArrayList<>();\n \n List<long[]>list=new ArrayList<>();\n list.add(new long[]{0,Integer.MAX_VALUE,0});\n \n //can not sort\n for(int i=0;i<A.length;i++)...
1
0
[]
0
falling-squares
C++ using map and emplace.
c-using-map-and-emplace-by-_chaitanya99-wsxt
\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n map<int,int> count = {{-1,0}};\n int n = positions
_chaitanya99
NORMAL
2020-09-08T06:16:34.294359+00:00
2020-09-08T06:16:34.294401+00:00
141
false
```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n map<int,int> count = {{-1,0}};\n int n = positions.size();\n vector<int> ans;\n int res = 0;\n for(int i=0;i<n;i++) {\n auto ed = count.emplace(positions[i][0]+positions[i][1]...
1
0
[]
0
falling-squares
Evolve from intuition
evolve-from-intuition-by-yu6-bcme
O(n^2) Store the height of fallen squares as interval heights [left, right, height]. When a new square falls, we check intersection with existing intervals and
yu6
NORMAL
2020-08-29T22:41:12.285666+00:00
2020-08-29T22:48:30.028173+00:00
77
false
1. O(n^2) Store the height of fallen squares as interval heights [left, right, height]. When a new square falls, we check intersection with existing intervals and compute the height of the new interval. Existing interval height does not need to be updated because we are only interested in the max height. Outdated lower...
1
0
[]
0
falling-squares
The Easiest Java Segmentation Tree with Lazy Propagation.
the-easiest-java-segmentation-tree-with-p13ve
\nclass Solution {\n class SegmentTree {\n Node root;\n public SegmentTree (int low, int high) {\n root = new Node(low, high);\n
fang2018
NORMAL
2020-07-29T18:26:00.618717+00:00
2020-07-29T19:29:49.551258+00:00
157
false
```\nclass Solution {\n class SegmentTree {\n Node root;\n public SegmentTree (int low, int high) {\n root = new Node(low, high);\n }\n public void update (int L, int R, Node node, int val) {\n if (L <= node.low && R >= node.high) {\n node.lazy = Math....
1
0
[]
0
falling-squares
[Python] Segment Tree with coordinate compression
python-segment-tree-with-coordinate-comp-i59l
Similar to the techniques from https://codeforces.com/blog/entry/18051\n\npython\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> L
stwind
NORMAL
2020-07-22T05:09:16.239303+00:00
2020-07-22T05:09:16.239353+00:00
181
false
Similar to the techniques from https://codeforces.com/blog/entry/18051\n\n```python\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n V = set()\n for p, w in positions:\n V.add(p)\n V.add(p + w)\n rank = {x: i for i, x in enumerate(sort...
1
0
[]
0
falling-squares
[Java] Standard TreeMap solution [Detailed]
java-standard-treemap-solution-detailed-iec5s
Save Pair(left, right) as key and height as value into TreeMap.\n\nPair start = map.lowerKey(p1);\nPair end = map.lowerKey(p2);\n\n1. Modify the end interval if
Aranne
NORMAL
2020-06-18T04:16:02.663466+00:00
2020-06-18T04:16:02.663498+00:00
122
false
Save `Pair(left, right)` as key and `height` as value into TreeMap.\n```\nPair start = map.lowerKey(p1);\nPair end = map.lowerKey(p2);\n```\n1. Modify the `end` interval if it intersects with `[left, right]`\n2. Modify the `start` interval if it intersects with `[left, right]`\n3. Seach in `subMap = map.subMap(p1, true...
1
0
[]
1
falling-squares
Accepted C# Solution with Segment Tree
accepted-c-solution-with-segment-tree-by-2xef
\n public class Solution\n {\n private class SegTree\n {\n public class Node\n {\n public readonly long
maxpushkarev
NORMAL
2020-03-29T06:49:16.800900+00:00
2020-03-29T06:49:16.800939+00:00
131
false
```\n public class Solution\n {\n private class SegTree\n {\n public class Node\n {\n public readonly long Left;\n public readonly long Right;\n\n public Node(long left, long right)\n {\n Left = left...
1
0
['Tree']
0
falling-squares
C# Solution
c-solution-by-leonhard_euler-j8do
\npublic class Solution \n{\n public IList<int> FallingSquares(int[][] positions) \n {\n var result = new List<int>();\n var intervals = new
Leonhard_Euler
NORMAL
2019-08-02T05:44:50.174374+00:00
2019-08-02T05:44:50.174420+00:00
69
false
```\npublic class Solution \n{\n public IList<int> FallingSquares(int[][] positions) \n {\n var result = new List<int>();\n var intervals = new List<Interval>();\n int max = 0;\n foreach(var p in positions)\n {\n var interval = new Interval(p[0], p[0] + p[1] - 1, p[1]...
1
0
[]
0
falling-squares
python bisect, beat 82%, very similar to Calendar Three
python-bisect-beat-82-very-similar-to-ca-87qj
\n\n\nimport bisect\nimport collections\n\nclass Solution(object):\n def fallingSquares(self, positions):\n """\n :type positions: List[List[in
yjiang01
NORMAL
2019-06-04T08:23:11.988493+00:00
2019-06-04T08:23:11.988546+00:00
174
false
\n\n```\nimport bisect\nimport collections\n\nclass Solution(object):\n def fallingSquares(self, positions):\n """\n :type positions: List[List[int]]\n :rtype: List[int]\n """\n \n max_height = collections.defaultdict(int)\n square_endpoints = []\n \n an...
1
0
[]
0
falling-squares
short python with bisect
short-python-with-bisect-by-horizon1006-elak
```\nclass Solution:\n def fallingSquares(self, positions):\n g ,MAX, ans= [(0,0),(1e9,0)], 0, []\n for i,side in positions:\n l = b
horizon1006
NORMAL
2019-01-14T12:00:34.929780+00:00
2019-01-14T12:00:34.929836+00:00
201
false
```\nclass Solution:\n def fallingSquares(self, positions):\n g ,MAX, ans= [(0,0),(1e9,0)], 0, []\n for i,side in positions:\n l = bisect.bisect(g,(i,0)) \n r = bisect.bisect_left(g,(i+side,0)) \n curr = max(g[k][1] for k in range(l-1,r))+side\n MAX = max(MAX...
1
0
[]
0
falling-squares
TreeMap solution
treemap-solution-by-maot1991-gy9p
TreeMap functions as the sorted map.\n\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n TreeMap<Integer, Integer> map =
maot1991
NORMAL
2018-09-21T21:14:41.383434+00:00
2018-09-21T21:14:41.383495+00:00
173
false
TreeMap functions as the sorted map.\n```\nclass Solution {\n public List<Integer> fallingSquares(int[][] positions) {\n TreeMap<Integer, Integer> map = new TreeMap();\n map.put(0, 0);\n List<Integer> res = new ArrayList<Integer>();\n int heighest = 0;\n for (int i = 0; i < positio...
1
0
[]
0
falling-squares
Short Java solution !!!
short-java-solution-by-kylewzk-bf6w
\n int max = Integer.MIN_VALUE;\n\t\t\n public List<Integer> fallingSquares(int[][] p) {\n List<int[]> list = new ArrayList<>();\n List<Inte
kylewzk
NORMAL
2018-06-27T11:00:30.679334+00:00
2018-10-10T03:14:56.629909+00:00
272
false
```\n int max = Integer.MIN_VALUE;\n\t\t\n public List<Integer> fallingSquares(int[][] p) {\n List<int[]> list = new ArrayList<>();\n List<Integer> ans = new ArrayList<>();\n for (int[] s : p) {\n int[] node = new int[]{s[0], s[0] + s[1], s[1]};\n ans.add(getMax(list, no...
1
0
[]
1
falling-squares
Java BST O(nlogn)
java-bst-onlogn-by-octavila-e043
``` static class Segment{ int start, end, height; Segment(int s, int e, int h) { start = s; end = e; height = h; } } p
octavila
NORMAL
2018-02-17T06:50:07.358275+00:00
2018-02-17T06:50:07.358275+00:00
180
false
``` static class Segment{ int start, end, height; Segment(int s, int e, int h) { start = s; end = e; height = h; } } public List<Integer> fallingSquares(int[][] positions) { List<Integer> res = new ArrayList<>(); ...
1
0
[]
0
falling-squares
Discretization and ZKW segment tree(iterative segment tree)
discretization-and-zkw-segment-treeitera-vfkv
\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<pair<int, int>>& positions) {\n //Discretization \n map<int,vector<int> >hash;\
1179729428
NORMAL
2018-02-04T03:39:30.595000+00:00
2018-02-04T03:39:30.595000+00:00
328
false
```\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<pair<int, int>>& positions) {\n //Discretization \n map<int,vector<int> >hash;\n vector<vector<int> >pos(positions.size(),vector<int>{0,-1,-1});//pos is the discretization of positions,pos[0] is the height of positions[i], [pos[1...
1
3
[]
0
falling-squares
C++ discretization + Segment Tree O(nlog(n)) time 29ms
c-discretization-segment-tree-onlogn-tim-gomj
\nclass Solution {\n vector<int> vec;\n int getId(int x) {\n return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;\n }\n int m;\n
szfck
NORMAL
2017-10-15T15:11:28.659000+00:00
2017-10-15T15:11:28.659000+00:00
323
false
```\nclass Solution {\n vector<int> vec;\n int getId(int x) {\n return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;\n }\n int m;\n int seg[2005 * 4], lazy[2005 * 4];\n \n void build(int rt, int left, int right) {\n seg[rt] = 0, lazy[rt] = -1;\n if (left == right) r...
1
0
[]
0
falling-squares
[699. Falling Squares] C++ AC with brief explanation
699-falling-squares-c-ac-with-brief-expl-j9xr
We should divide the whole interval of the positions into different pieces. Because if we directly consider each whole interval, like:\n\nfor this test case:
jasonshieh
NORMAL
2017-10-16T00:39:18.618000+00:00
2017-10-16T00:39:18.618000+00:00
276
false
We should divide the whole interval of the positions into different pieces. Because if we directly consider each whole interval, like:\n\nfor this test case: [[50,47],[95,48],[88,77],[84,3],[53,87],[98,79],[88,28],[13,22],[53,73],[85,55]], when we add [84,3] into our graph, the heigh is changed from 47 to 50 only for...
1
0
[]
0
falling-squares
98% beat using Segment Tree
98-beat-using-segment-tree-by-aviadblume-kj6j
IntuitionStore in a segment tree heights of left edges of each cube. when adding a cube to the board, update all cubes in the x-range of the cube.ApproachComple
aviadblumen
NORMAL
2025-03-20T20:16:52.887378+00:00
2025-03-20T20:16:52.887378+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Store in a segment tree heights of left edges of each cube. when adding a cube to the board, update all cubes in the x-range of the cube. # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: $$...
0
0
['C++']
0
falling-squares
Easy to understand Segment Tree Code!
easy-to-understand-segment-tree-code-by-xcbvv
IntuitionIf you know about Segment Tree then the question is not hard at all. The challenge is to create the range with the commpresed indexes for the sqaures.A
Deepansh_1912
NORMAL
2025-03-13T07:51:03.220126+00:00
2025-03-13T07:51:03.220126+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> If you know about Segment Tree then the question is not hard at all. The challenge is to create the range with the commpresed indexes for the sqaures. # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time ...
0
0
['Segment Tree', 'Ordered Set', 'C++']
0
falling-squares
🔷 Coordinate Compression for Falling Squares 🎯 | Beats 88% - Efficient Height Tracking
coordinate-compression-for-falling-squar-4480
IntuitionThe problem requires tracking the maximum height of stacked squares at each step. My initial insight was that we only need to track height changes at t
holdmypotion
NORMAL
2025-02-24T18:23:08.855194+00:00
2025-02-24T18:23:08.855194+00:00
6
false
# Intuition The problem requires tracking the maximum height of stacked squares at each step. My initial insight was that we only need to track height changes at the specific coordinates where squares begin and end. Since the actual positions can range up to 10^8, we can use coordinate compression to map these position...
0
0
['Ordered Set', 'Python3']
0
falling-squares
O(n*n) calculate height of each square
onn-calculate-height-of-each-square-by-l-wohu
Intuition Calculate height of each square Compare and get result of "height of the current tallest stack of squares." ???? why this problem is hardComplexity T
luudanhhieu
NORMAL
2025-02-20T03:40:43.782453+00:00
2025-02-20T03:40:43.782453+00:00
2
false
# Intuition - Calculate height of each square - Compare and get result of "height of the current tallest stack of squares." ???? why this problem is hard # Complexity - Time complexity: O(n*n) - Space complexity:O(n) # Code ```golang [] func fallingSquares(positions [][]int) []int { rs := make([]int, 1) rs[0] = ...
0
0
['Go']
0
falling-squares
Rust Solution | Beats 100% | Segment Tree
rust-solution-beats-100-segment-tree-by-x7r94
Approach Build hashmap of actual position into index from left and right positions of every building. For easy calculation, x inidx_to_x[idx] = xstands for[x, x
skygazer227
NORMAL
2025-02-20T03:32:37.181865+00:00
2025-02-20T03:32:37.181865+00:00
4
false
# Approach - Build hashmap of actual position into index from left and right positions of every building. - For easy calculation, x in `idx_to_x[idx] = x` stands for `[x, x + 1]` line segment. - For every iteration over buildings: 1. Query maximum height within range 2. Update height to `side_length + max_heigh...
0
0
['Segment Tree', 'Rust']
0
falling-squares
Python Hard
python-hard-by-lucasschnee-xp7i
null
lucasschnee
NORMAL
2025-02-11T17:38:53.288556+00:00
2025-02-11T17:38:53.288556+00:00
4
false
```python3 [] class Solution: def fallingSquares(self, positions: List[List[int]]) -> List[int]: prev = [] def overlap(l, r, left, right): return not (r <= left or right <= l) ans = [] mx = 0 for left, sideLength in positions: ri...
0
0
['Python3']
0
falling-squares
Segment Tree || Lazy Propagation || Coordinate Compression
segment-tree-lazy-propagation-coordinate-3hc6
IntuitionSince the problem is kind of rnage update and query. It is very intuitive to think of Segment tree with Lazy propagation.ApproachBasically what we are
Mainamanhoon
NORMAL
2025-01-15T10:15:09.214756+00:00
2025-01-15T10:15:09.214756+00:00
12
false
# Intuition Since the problem is kind of rnage update and query. It is very intuitive to think of Segment tree with Lazy propagation. # Approach Basically what we are doing is updating a range in every step. Along with the update we need to check is the square was already present the range we are about/going to update...
0
0
['Segment Tree', 'C++']
0
falling-squares
699. Falling Squares
699-falling-squares-by-g8xd0qpqty-t5zj
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2024-12-29T06:38:54.989258+00:00
2024-12-29T06:38:54.989258+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
falling-squares
Easy Soln
easy-soln-by-dicusa-zsbl
Intuition\nFor each square:\na. Find the maximum height of intersecting squares\nb. Calculate the height of the new square based on intersections\nc. Track the
dicusa
NORMAL
2024-12-01T18:58:24.037633+00:00
2024-12-01T18:58:24.037681+00:00
8
false
# Intuition\nFor each square:\na. Find the maximum height of intersecting squares\nb. Calculate the height of the new square based on intersections\nc. Track the overall maximum height\n\n# Approach\n1. Tracking intersections by checking x-coordinate ranges.\n2. Dynamically updating maximum height.\n3. Using set to sto...
0
0
['Python3']
0
falling-squares
Breaking 2D into 1D Problem || Step by Step Lazy Propogation and Coordinate Compression
breaking-2d-into-1d-problem-step-by-step-oy2a
\n# Approach\nInstead of thinking of squares as $2-D$ figures, we can treat them as a line segment flattened into a $1-D$ plane holding a value which is equal t
math_pi
NORMAL
2024-11-22T11:57:06.332605+00:00
2024-11-22T11:57:52.391931+00:00
12
false
\n# Approach\nInstead of thinking of squares as $2-D$ figures, we can treat them as a line segment flattened into a $1-D$ plane holding a value which is equal to the side of the sqaure. *[See below image.]*\n![image.png](https://assets.leetcode.com/users/images/8e6b5353-17d6-4465-ae5a-c07cc46eef48_1732276148.0156393.pn...
0
0
['Hash Table', 'Segment Tree', 'Ordered Set', 'C++']
0
falling-squares
Simple python3 solution with comments
simple-python3-solution-with-comments-by-cbbc
Complexity\n- Time complexity: O(n \cdot \log(n)) \n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n) \n Add your space complexity here, e.
tigprog
NORMAL
2024-11-05T13:38:01.265726+00:00
2024-11-05T13:38:01.265772+00:00
12
false
# Complexity\n- Time complexity: $$O(n \\cdot \\log(n))$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nfrom sortedcontainers import SortedList\n\nclass Solution:\n def fallingSquares(self, po...
0
0
['Greedy', 'Ordered Set', 'Python3']
0
falling-squares
TreeMap
treemap-by-sav20011962-7p1a
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTreeMap: key - right border, value - pair(width, full height)\n# Complexi
sav20011962
NORMAL
2024-09-23T13:23:11.920299+00:00
2024-09-23T13:24:15.387949+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTreeMap: key - right border, value - pair(width, full height)\n# Complexity\n![image.png](https://assets.leetcode.com/users/images/d2462a6e-8eab-423a-8e77-cfd8d48ab506_1727097539.4853752.png)\n# Code\n```kotlin []\nclass Sol...
0
0
['Kotlin']
0
falling-squares
Optimized Approach with Binary Search
optimized-approach-with-binary-search-by-de93
Intuition\nwe can use a greedy approach. Each square\'s height will depend on the heights of the squares already placed on the line. We maintain a list of the c
orel12
NORMAL
2024-09-02T20:09:31.133779+00:00
2024-09-02T20:09:31.133798+00:00
15
false
# Intuition\nwe can use a greedy approach. Each square\'s height will depend on the heights of the squares already placed on the line. We maintain a list of the current heights and use binary search to efficiently find where each new square starts and ends relative to the squares already placed.\n\n# Approach\nWe maint...
0
0
['Python3']
0
falling-squares
Simple and short version of segment tree with lazy update
simple-and-short-version-of-segment-tree-eyem
Intuition\n Describe your first thoughts on how to solve this problem. \nI found the segment tree in the solutions are very long so that I update one with short
jesselee_leetcode
NORMAL
2024-08-30T08:47:12.445478+00:00
2024-08-30T08:47:12.445512+00:00
26
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI found the segment tree in the solutions are very long so that I update one with short version. you can also change my segment tree code into template (I did so, lol).\n\nNOTE: when you want to use segment tree to solve other questions, ...
0
0
['Segment Tree', 'Python3']
0
falling-squares
✅A COMMON IDEA,🧐 O(n^2) where n is critical points
a-common-idea-on2-where-n-is-critical-po-ye02
Intuition\n Describe your first thoughts on how to solve this problem. \nwe will store height of every critical points of our block except at end ,this way we w
sameonall
NORMAL
2024-08-15T18:21:19.945734+00:00
2024-08-15T18:21:19.945764+00:00
4
false
### Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe will store height of every critical points of our block except at end ,this way we will always have height of every block with aleast one critical point and we can update height changes due to new blocks except by it end points.\n# A...
0
0
['C++']
0
falling-squares
C++ BST Solution detailed with comments
c-bst-solution-detailed-with-comments-by-7e8w
Approach\nWe can store closed-open intervals $[i,~j)$ in a BST such that\n\n a < b $\Leftrightarrow$ the whole a interval is to the left of b\n a > b $\Leftrigh
diegood12
NORMAL
2024-08-07T12:50:21.927929+00:00
2024-08-07T12:50:21.927961+00:00
15
false
# Approach\nWe can store closed-open intervals $[i,~j)$ in a BST such that\n\n* `a < b` $\\Leftrightarrow$ the whole `a` interval is to the left of `b`\n* `a > b` $\\Leftrightarrow$ the whole `a` interval is to the right of `b`\n* `a == b` $\\Leftrightarrow$ `a` intercepts `b`\n\nDetails on how to do that are in the co...
0
0
['Binary Search Tree', 'Ordered Set', 'C++']
0
falling-squares
simplfy check every previous square, O(n^2)
simplfy-check-every-previous-square-on2-lbfhy
\n\nimpl Solution {\n pub fn falling_squares(xs: Vec<Vec<i32>>) -> Vec<i32> {\n let n = xs.len();\n let mut h = vec![0; n];\n let mut hh
user5285Zn
NORMAL
2024-07-23T13:03:32.027918+00:00
2024-07-23T13:03:32.027964+00:00
2
false
\n```\nimpl Solution {\n pub fn falling_squares(xs: Vec<Vec<i32>>) -> Vec<i32> {\n let n = xs.len();\n let mut h = vec![0; n];\n let mut hh = 0; \n let mut r = Vec::with_capacity(n);\n hh = 0;\n for i in 0..n {\n let x = xs[i][0];\n let s = xs[i][1];\n ...
0
0
['Rust']
0
falling-squares
Beating 100% users in Runtime & Memory using PHP
beating-100-users-in-runtime-memory-usin-5qoh
Code\n\nclass Solution {\n function fallingSquares($positions) {\n $hgt = [0];\n $pos = [0];\n $res = [];\n $mx = 0;\n\n f
nishk2
NORMAL
2024-07-17T08:26:22.238615+00:00
2024-07-17T08:26:22.238644+00:00
1
false
# Code\n```\nclass Solution {\n function fallingSquares($positions) {\n $hgt = [0];\n $pos = [0];\n $res = [];\n $mx = 0;\n\n foreach ($positions as $box) {\n $mx = max($mx, self::helper($box, $pos, $hgt));\n $res[] = $mx;\n }\n\n return $res;\n ...
0
0
['PHP']
0
falling-squares
C++ Clean Solution | Easy O(N^2)
c-clean-solution-easy-on2-by-mhasan01-1thg
Approach\n\nThe idea is that when we are putting the $i$-th square, we need to know the "highest" square that it will be put into.\n\nLet $h[i]$ be the height o
mhasan01
NORMAL
2024-07-02T18:34:15.936378+00:00
2024-07-02T18:34:15.936452+00:00
67
false
# Approach\n\nThe idea is that when we are putting the $i$-th square, we need to know the "highest" square that it will be put into.\n\nLet $h[i]$ be the height of putting the $i$-th square, then initially $h[i]=p[i][1]$ which is the size of the square.\n\nNow we can find all $j < i$ such that $i-$th square overlaps wi...
0
0
['C++']
0