Hello Everyone, Day 13 / #100DaysOfCode LeetCode 3453 — Separate Squares I (Medium) Problem: Given multiple axis-aligned squares on a 2D plane, find the minimum y-coordinate of a horizontal line such that the total area above the line equals the total area below it. Overlapping areas are counted multiple times. Approach: - Observed that the area difference (above − below) changes monotonically as the line moves up - Applied binary search on the y-coordinate - For each candidate height, computed how much area of every square lies below the line and compared it with the total area Key insight: Once the monotonic behavior is identified, the problem reduces to a clean binary search on the answer space. #LeetCode #DSA #Java
LeetCode 3453: Separate Squares with Binary Search
More Relevant Posts
-
LeetCode POTD #1292 - Maximum Side Length of a Square with Sum <= Threshold Solved this one the right way, no brute force, no guesswork. Used 2D prefix sums to compute submatrix sums in O(1), then applied binary search on the square size to keep the overall complexity tight. Approach in short: Build a prefix sum matrix to query any square’s sum instantly Binary search on possible side lengths Validate each candidate square efficiently Track the maximum valid side length This keeps the logic clean and the time complexity under control, even for larger grids. Problems like these are a good reminder that knowing when to combine techniques (prefix sums + binary search) matters more than just knowing them individually. On to the next one. #LeetCode #POTD #DSA #Java #ProblemSolving
To view or add a comment, sign in
-
-
✅Day 58/75 – Bit Manipulation | Single Number Problem 📌 Problem Statement Given a non-empty integer array where every element appears twice except one, find that single element. 💡 Key Insight 💠 Using the XOR (^) operator: 🔺 a ^ a = 0 🔺a ^ 0 = a 💠XOR is commutative & associative 💠So, when we XOR all elements together, duplicate values cancel out, leaving only the unique number. 🧠 Approach 🔺Initialize the result with the first element 🔺XOR it with every other element 🔺Final result is the single number 📈 Complexity Analysis 🔺Time: O(n) 🔺Space: O(1) #Day58 #75DaysOfCode #DSA #Java #BitManipulation #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
📘 LeetCode Daily — Balanced Binary Tree Checked tree balance by recursively comparing left and right subtree heights at every node. The solution worked, but it clearly showed how repeated height calculations increase time complexity—an important reminder that correct logic isn’t always optimal logic. Solid recursion practice and a good lead-in to optimization. #LeetCode #BinaryTree #Recursion #DSA #Java
To view or add a comment, sign in
-
-
📝 Day 15/30 – LeetCode #209 (Minimum Size Subarray Sum) | Java The brute-force approach checks all possible subarrays, which leads to O(n²) time complexity. The key observation here is that all numbers are positive, allowing us to use a sliding window efficiently. By expanding the window to reach the target sum and shrinking it to find the minimum length, each element is visited at most twice. This results in an O(n) time solution with constant space. This problem strengthened my understanding of when sliding window techniques are applicable and why input constraints matter. #LeetCode #Java #DSA #SlidingWindow #Arrays #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
📝 Day 17/30 – LeetCode #238 (Product of Array Except Self) | Java The straightforward solution using division fails due to edge cases involving zeros and is explicitly disallowed. A brute-force approach would also be inefficient with O(n²) time complexity. By computing prefix products and suffix products, I was able to calculate the result for each index without using division. Each element in the output array represents the product of all numbers before and after it, resulting in an O(n) time solution with constant extra space. This problem highlighted how breaking a problem into directional passes can simplify complex constraints. #LeetCode #Java #DSA #Arrays #PrefixSum #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 2 – LeetCode 2461 | Sliding Window + HashSet Description: Solved LeetCode 2461: Maximum Sum of Distinct Subarrays With Length K. This problem is a solid test of sliding window fundamentals. What I learned: How to maintain a fixed-size window efficiently Handling duplicates using a HashSet instead of restarting the window Updating the window sum in O(1) time Achieving O(n) time complexity instead of brute force Key insight: When a duplicate appears, shrink the window from the left until all elements are unique, then continue expanding. Day 2 completed. Consistency continues. Tags: #LeetCode #DSA #SlidingWindow #Java #ProblemSolving #CodingJourney #SoftwareDeveloper #InterviewPreparation
To view or add a comment, sign in
-
#200DaysOfCode – Day 117 Subsets (Power Set) using Bit Manipulation Problem: LeetCode 78 – Subsets Task:- Given an integer array of unique elements, return all possible subsets (the power set). Example: Input: nums = [1, 2, 3] Output: [[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]] My Approach (Bit Manipulation): Observed that for an array of size n, total subsets = 2^n. Used numbers from 0 to (2^n - 1) as binary masks. Each bit position represents whether an element is included (1) or excluded (0) in the subset. Iterated through each mask and built subsets accordingly. Complexity: Time Complexity: O(n * 2^n) Space Complexity: O(2^n) Bit manipulation is not just about low-level tricks it can provide elegant and efficient solutions to problems like generating subsets. Once you see the binary pattern, the solution becomes surprisingly intuitive. #LeetCode #Java #BitManipulation #DSA #ProblemSolving #TakeUForward #CodingJourney #200DaysOfCode #PowerSet #CleanCode
To view or add a comment, sign in
-
-
Hello Everyone, Day 15 / #100DaysOfCode LeetCode 2943 — Maximize Area of Square Hole in Grid (Medium) Problem: You are given a grid formed by horizontal and vertical bars. Some bars can be removed. After removing any number of bars, you must form the largest possible square-shaped hole and return its area. The challenge is to determine how many consecutive bars can be removed horizontally and vertically to create the maximum square. Approach: Observation + Sorting - A square hole is formed by removing consecutive bars - The side of the square depends on: - Maximum consecutive removable horizontal bars - Maximum consecutive removable vertical bars - The side length is the minimum of the two Steps: - Sort hBars and vBars - Find the longest streak of consecutive numbers in each array - Add +1 because bars define lines, and the gap is between them - Take side = min(maxHGap, maxVGap) - Return side × side Why this works: The largest square is bounded by the smallest dimension where continuous space exists. Extra space in one direction cannot compensate for lack in the other. Complexity: - Time: O(n log n) due to sorting - Space: O(1) extra space (ignoring sort) #Leetcode #DSA #Java
To view or add a comment, sign in
-
-
🚀 Day 22 – LeetCode 3 Longest Substring Without Repeating Characters Solved using Sliding Window + HashMap. Instead of checking all substrings (O(n²) ❌), I maintained a window of unique characters and jumped the left pointer whenever a duplicate appeared. Time Complexity: O(n) Space Complexity: O(1) Key takeaway: Most substring problems are solved using sliding window patterns, not brute force. Day 22/90 consistency streak continues 🔥 #leetcode #dsa #slidingwindow #java #softwareengineering
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Keep it up 👍