How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Difficulty: 🔴 Hard
Topics: Geometry, Sweep Line, Binary Search
You are given a 2D integer array squares.
Each square is represented as:
squares[i] = [xᵢ, yᵢ, lᵢ]
(xᵢ, yᵢ) → bottom-left corner of the squarelᵢ → side lengthFind the minimum y-coordinate of a horizontal line such that:
🟢 Total area of squares above the line = 🔵 Total area of squares below the line
| Feature | Separate Squares I | Separate Squares II |
|---|---|---|
| Overlaps | Counted multiple times | Counted once |
| Area Calculation | Simple sum | Union area |
| Geometry Handling | Independent squares | Interacting squares |
| Main Technique | Binary search | Binary search + sweep line |
| Data Structures | None | TreeMap / interval merging |
| Difficulty | Medium | Hard |
| Time Complexity | (O(N log Y)) | (O(N log N log Y)) |
N = number of squares | Y = range of possible y-values
squares = [[0,0,1],[2,2,1]]
1.00000
Any horizontal line between y = 1 and y = 2 divides the total area equally:
✅ Minimum valid y-coordinate is 1
squares = [[0,0,2],[1,1,1]]
1.00000
The smaller square overlaps with the larger one.
Since overlapping areas are not double-counted, the horizontal line:
1 ≤ squares.length ≤ 5 × 10⁴0 ≤ xᵢ, yᵢ ≤ 10⁹1 ≤ lᵢ ≤ 10⁹🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.