699. Falling Squares Hard
1/**
2 * [699] Falling Squares
3 *
4 * There are several squares being dropped onto the X-axis of a 2D plane.
5 * You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the i^th square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti.
6 * Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.
7 * After each square is dropped, you must record the height of the current tallest stack of squares.
8 * Return an integer array ans where ans[i] represents the height described above after dropping the i^th square.
9 *
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/28/fallingsq1-plane.jpg" style="width: 500px; height: 505px;" />
12 * Input: positions = [[1,2],[2,3],[6,1]]
13 * Output: [2,5,5]
14 * Explanation:
15 * After the first drop, the tallest stack is square 1 with a height of 2.
16 * After the second drop, the tallest stack is squares 1 and 2 with a height of 5.
17 * After the third drop, the tallest stack is still squares 1 and 2 with a height of 5.
18 * Thus, we return an answer of [2, 5, 5].
19 *
20 * Example 2:
21 *
22 * Input: positions = [[100,100],[200,100]]
23 * Output: [100,100]
24 * Explanation:
25 * After the first drop, the tallest stack is square 1 with a height of 100.
26 * After the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.
27 * Thus, we return an answer of [100, 100].
28 * Note that square 2 only brushes the right side of square 1, which does not count as landing on it.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= positions.length <= 1000
34 * 1 <= lefti <= 10^8
35 * 1 <= sideLengthi <= 10^6
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/falling-squares/
41// discuss: https://leetcode.com/problems/falling-squares/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn falling_squares(positions: Vec<Vec<i32>>) -> Vec<i32> {
47 vec![]
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_699() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.