Day 472 of my #500DaysOfCode challenge 🚀 ✅ LeetCode 3453: Separate Squares I (Medium) 📌 Problem Summary: We are given multiple squares on a 2D plane, each defined by bottom-left coordinate (x, y) and side length (l). The task is to find the minimum y-coordinate of a horizontal line such that: ✅ Total area above the line = Total area below the line ⚠️ Important note: Squares may overlap, and overlapping area should be counted multiple times (each square contributes independently). 💡 Key Insight: For any horizontal line y = mid, each square contributes to the area below based on how much of its height lies below the line: If the line is below the square → contributes 0 If the line is above the square → contributes full area l² If the line cuts the square → contributes l * (mid - y) Since the area below increases monotonically as the line moves upward, we can apply: ✅ Binary Search on the y-coordinate 🎯 Goal: Find smallest y where areaBelow(y) ≥ totalArea / 2. ⚡ Complexity: ✅ Time: O(n log range) (binary search iterations × n squares) ✅ Space: O(1) This was a great problem to reinforce how binary search can be used beyond arrays, especially when the function is monotonic 📈. #leetcode #dsa #java #binarysearch #programming #problemsolving #500daysofcode #consistency #learning
LeetCode 3453: Separate Squares I Binary Search Solution
More Relevant Posts
-
Day 13 Problem Statement: You’re given an array squares where each element is: [some x‑coordinate, some y‑coordinate, side length l] Each triple describes an axis‑aligned square on the 2D plane. The goal is to find the lowest possible y‑value of a horizontal line such that: The total area above the line equals The total area below the line Important rule: Overlapping areas are counted multiple times — i.e., if two squares overlap, the overlapped region contributes to the total for each square individually. Approach : The problem is to find a horizontal line that splits all squares into equal areas above and below. To solve it: Calculate the total area of all squares. Use binary search on y-coordinate to find the line. For each candidate y, sum the area below the line for all squares (full square if below, 0 if above, partial if intersecting). Move the line up or down depending on whether the area below is less or more than half the total. Stop when the areas are balanced — that y is the answer. #HappyCoding #LeetCode #Coding #ProblemSolving #Programming #Java #SoftwareEngineering #DSA #DataStructures #Algorithms #CompetitiveProgramming #CodeNewbie #TechLearning #DailyCodingChallenge #BinarySearch #LearnToCode #DeveloperCommunity
To view or add a comment, sign in
-
🚀 Day 47 | LeetCode Medium 🟩 Set Matrix Zeroes Today’s problem focused on matrix traversal + space trade-offs, and it was a great reminder that clarity beats complexity. 🧠 Core Idea If any cell in the matrix is 0, then its entire row and column must be set to 0. Instead of modifying the matrix immediately (which can break logic), I used an auxiliary tracking approach. 🛠️ Approach Used Traverse the matrix once Mark affected rows and columns using helper arrays Traverse again and update cells based on these markers This avoids incorrect cascading zeros and keeps the logic clean. ⚡ Why this works Separation of detection and update No accidental overwrites Easy to reason and debug ⏱️ Complexity Time: O(m × n) Space: O(m + n) 🔗 Code on GitHub 👉 https://lnkd.in/g-zxCztf 💡 Key Learning In matrix problems, when you update is just as important as what you update. 🔥 Consistency > Speed Another step forward in my daily DSA journey 🚀 #LeetCode #LeetCodeDailyProblem #SetMatrixZeroes #DSA #Java #Arrays #Matrix #ProblemSolving #CodingJourney #100DaysOfCode #TechCommunity
To view or add a comment, sign in
-
-
Solved the Ugly Number problem using a simple and efficient approach 💡 🔹 Approach: An ugly number is a number whose prime factors are only 2, 3, and 5. So instead of checking all factors, I used a reduction method: If the number is ≤ 0 → not ugly. Keep dividing the number by 2, 3, and 5 as long as it is divisible. If after removing all these factors the number becomes 1, then it is an ugly number. If something else remains, it means another prime factor exists → not ugly. This approach works because ugly numbers are made only by multiplying 2, 3, and 5. Removing these factors should eventually reduce the number to 1. 🔹 Why this approach? Avoids factorization of all numbers. Directly removes allowed prime factors. Simple, clean, and optimal logic. 🔹 Time Complexity: O(log n) Each division reduces the number significantly. 🔹 Space Complexity: O(1) No extra space used, only variable updates. #Java #Coding #ProblemSolving #DSA #LeetCode #Programming #LogicBuilding #DataStructures #Algorithms #JavaDeveloper #CodingJourney #LearnToCode #TechSkills #ComputerScience #CodeDaily #DeveloperLife #PlacementPreparation #CodingPractice #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 57 of #100DaysOfCode Today’s problem was a clean and classic two-pointer exercise — 🔁 LeetCode 344: Reverse String Simple on the surface, but a great reminder of in-place algorithms and pointer manipulation. 📌 Problem Summary You’re given a character array s. Your task is to reverse the array in-place, using O(1) extra space. 🧠 Approach Used: Two Pointers ✔️ Initialize: left = 0 right = s.length - 1 ✔️ Swap characters while left < right, then move pointers inward. This ensures: No extra memory Linear traversal Clean and readable logic ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (in-place) ✔️ 477 / 477 test cases passed 🚀 Runtime: 0 ms (Beats 100%) 🔥 Key Learning Even the simplest problems reinforce core fundamentals: Two-pointer technique In-place operations Space optimization Mastering basics = dominating harder problems later 💪 Onward to Day 58 🚀 #100DaysOfCode #LeetCode #ReverseString #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 21/30 – Coding Challenge 📌 Problem: Valid Perfect Square (LeetCode – 367) Given a positive integer, determine whether it is a perfect square without using any built-in functions like sqrt(). 🧠 Approach Used: Applied Newton’s Method (Binary-like approximation) Start with the number itself Repeatedly update the value using: x = (x + num / x) / 2 Stop when x * x ≤ num Finally, check if x * x == num ⚙️ Why this works: Efficient and avoids built-in math functions Handles large numbers safely using long Time Complexity: O(log n) ✅ Result: Solution accepted with 0 ms runtime 🎯 📈 One step closer every day — consistency over perfection! #Day21 #30DaysCodingChallenge #Java #LeetCode #DSA #ProblemSolving #NewtonMethod #CodingJourney
To view or add a comment, sign in
-
-
Array Balance with a Two-Pointer Approach in TypeScript 👉 Day 84 / Day 93👈 33 🔥 - Sort the array - Use two pointer check either balenced or not - nums[j] > nums[i] * k - if this true skip one level - maxLen = Math.max(maxLen, (j - i + 1)) check this maxLen; - Return arrLength - maxLen Input: nums = [2,1,5], k = 2 Output: 1 #TypeScript #CodingChallenge #Algorithms #DataStructures #ProblemSolving #LeetCode #Programming #Tech
To view or add a comment, sign in
-
-
📐 Jagged Arrays. A jagged array means: ✅ Different rows can have different number of columns ✅ int[][] arr = new int[rows][]; → only rows fixed ✅ each row can have different columns ✅ arr[i].length will be different for different rows GitHub Link: https://lnkd.in/g6JtkYCA 🔖Frontlines EduTech (FLM) #Java #Arrays #DeepCopy #ShallowCopy #2DArray #JavaProgramming #Coding #DSA #ProgrammingBasics #LearnJava #CodeSnippet
To view or add a comment, sign in
-
-
🚀 Day 50 of #100DaysOfCode 🎯 (Halfway there! 🔥) Today’s challenge was an array + dynamic programming twist problem — 📊 LeetCode: Maximum Product Subarray 📌 Problem Summary Given an integer array, find the contiguous subarray (containing at least one number) that has the largest product. At first glance, it looks similar to maximum subarray sum… but the presence of negative numbers changes everything ⚠️ 🧠 My Approach: Tracking Max & Min Products The key insight 👇 A negative number can turn the smallest product into the largest. So instead of tracking only the maximum, I tracked: ✅ max product ending at current index ✅ min product ending at current index At each step: Compute new max using (current, max*current, min*current) Compute new min similarly Update the global result This keeps everything in one pass 🚀 ⚙️ Complexity Analysis ⏱ Time: O(n) 💾 Space: O(1) Efficient and clean ✨ 🔥 Key Learning Negative numbers can flip the problem logic Some DP problems don’t need arrays — just smart state tracking Always think in terms of states, not just values ✅ Solution accepted with strong runtime performance Another powerful array pattern mastered 💪 Onward from Day 50 — the grind continues 🚀🔥 #100DaysOfCode #LeetCode #Java #DynamicProgramming #Arrays #ProblemSolving #CodingJourney #DSA
To view or add a comment, sign in
-
-
Why take the easy road when you can manage the registers yourself? 💻 I’m excited to share my latest project: A fully functional Tic-Tac-Toe game written entirely in Assembly Language. In a world of Python and JavaScript, going back to low-level programming was an eye-opening challenge. Building this wasn't just about coding a game; it was about understanding the architecture of the machine. Key takeaways from this build: Memory Management: Manually handling data allocation and the stack. Logic Flow: Implementing game rules (win conditions/draws) using direct branching and jumps. Optimization: Writing efficient, stripped-back code without the safety net of high-level abstractions. It was a rigorous exercise in patience and precision, but seeing the logic work byte-by-byte is incredibly satisfying. Check out the demo/code below! 👇 https://lnkd.in/d3WhvmR4 #AssemblyLanguage #LowLevelProgramming #ComputerArchitecture #CodingChallenge #SoftwareEngineering #x86 #GameDev
To view or add a comment, sign in
-
When we drive, we don’t care about the engine and wires. We only use steering, brake, and accelerator. -Same in programming: Abstraction hides complex details and shows only what we need. That makes code simple, clean, and easy to maintain. With Abstraction: ✔ Easy to use ✔ Clean and readable code ✔ Faster development ✔ Less bugs ✔ Easy maintenance ❌ Without Abstraction: ⚠ Code becomes messy ⚠ Hard to understand ⚠ Hard to fix and update ⚠ More chances of errors 📌 Lesson: Always hide complexity from users and expose only what they need. That’s how real-world software becomes scalable and maintainable. #Abstraction #OOP #Java #Programming #Coding #SoftwareDevelopment
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