Headline: Day 10/100: The Multiplier Effect 🍫✂️ Double digits! Today I tackled the "Minimum Cost to Cut a Board" problem—a classic Greedy challenge that taught me a valuable lesson about timing. The Problem: You have a board and a set of costs for horizontal and vertical cuts. How do you cut it into 1x1 squares for the lowest price? The Logic: It’s all about the "multiplier." Every cut you make increases the number of pieces for the opposite direction. The Greedy choice? Always make the most expensive cuts first. By doing the big-budget cuts while the board is still in fewer pieces, you prevent those costs from being multiplied later on. Key Technical Takeaways: ✅ Sorting primitive arrays in descending order in Java. ✅ Managing "piece counters" for horizontal and vertical segments. ✅ Understanding why the order of operations changes the total cost from $O(1)$ to $O(N)$. 10 days down, 90 to go. The logic is getting sharper every day! 🚀 #100DaysOfCode #GreedyAlgorithms #Java #CodingChallenge #ProblemSolving
Greedy Algorithms: Minimum Cost to Cut Board
More Relevant Posts
-
Day 38: Efficiency through String Balancing! ⚖️ Problem 1653: Minimum Deletions to Make String Balanced Today’s challenge was to find the minimum deletions needed to ensure no 'b' comes before an 'a' in a string. It’s a classic problem that tests your ability to think about state transitions across a sequence. I implemented a prefix/suffix counting strategy. Instead of brute-forcing every deletion possibility, I pre-calculated the total count of 'a's and then iterated through the string while keeping a running count of 'b's. At each position, the sum of 'b's seen so far (to be deleted if they stay) and 'a's remaining (to be deleted if they appear later) gave me the cost to balance at that specific "split point." By tracking the minimum sum across all possible split points, I achieved a clean O(n) solution with just two passes. It’s a great reminder that sometimes "balancing" a problem is just about counting what’s on either side of the fence! #LeetCode #Java #StringAlgorithms #Optimization #CodingChallenge #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 80 of #100DaysOfCode Solved LeetCode Problem #1653 – Minimum Deletions to Make String Balanced ✅ A clean greedy + DP-style problem that looks simple but really tests decision-making at each step. The trick is choosing whether to delete a character now or rely on previous counts to minimize total deletions. Key Takeaways: -> Greedy decisions can be optimized with running state -> Tracking counts (bCount) simplifies future choices -> Sometimes the best DP is just two variables -> Elegant logic beats complex data structures Language: Java -> Runtime: 19 ms (Beats 93.09%) ⚡ -> Memory: 47.80 MB Showing up daily, sharpening logic, and trusting the process. 💻🔥 #LeetCode #Java #Greedy #DynamicProgramming #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
day 7: (first week completed) LeetCode 26. Remove Duplicates from Sorted Array Key note -> since array is sorted , we know the duplicates will exist adjacent (neighbours) i = scan head , uniquePtr = write head So we only check neighbours nums[i] != nums[i-1] ---> unique element found write it down in array using uniquePtr (write head) increment it use i for scanning , uniquePtr for writehead (writing) why no set? set compromises space to o(n)since we are given a sorted array we get that adjacency for free , no need of set why both write head and scanner head starts at 1 and not at 0? simply the array is sorted , so whatsoever element is at nums[0] position their is no element beyond it to violate the no duplicacy rule , so we do not touch 0th position of array since its already unique. #day7of150daysofcode #week1of22weeksofcode #150daysofcode #Java #leetcode #dailycode
To view or add a comment, sign in
-
-
Day 2/100 – LeetCode Challenge 🚀 Problem: #48 Rotate Image Difficulty: Medium Language: Java Approach: In-Place Rotation using Transpose + Row Reversal Time Complexity: O(n²) Space Complexity: O(1) 🔍 Key Insight: To rotate a matrix 90° clockwise without extra space: 1️⃣ First transpose the matrix (swap across diagonal). 2️⃣ Then reverse each row. This avoids creating a new matrix and satisfies the in-place constraint. 🧠 Solution Brief: Used nested loops to transpose the matrix by swapping arr[i][j] and arr[j][i]. Then reversed each row using two pointers (start and end). Combined both operations inside a rotate() method. Achieved full rotation with constant extra space. 📌 What I Learned: Matrix problems are more about pattern recognition than brute force. Understanding transformations (transpose + reverse) makes complex problems simple. Starting my 100 Days of LeetCode journey today 💪 Consistency > Motivation. #LeetCode #Day2 #100DaysOfCode #Java #DSA #Matrix #ProblemSolving #CodingJourney #MediumProblem
To view or add a comment, sign in
-
-
🚀 Day 88 of #100DaysOfCode | LeetCode Daily Solved LeetCode Problem #67 – Add Binary ➕💻✅ A clean fundamentals problem that reinforces how low-level operations really work under the hood. Simulating binary addition digit by digit with carry is simple, efficient, and elegant. Key Takeaways: -> Binary addition using carry logic -> Traversing strings from right to left -> Using StringBuilder for efficient string construction -> Handling edge cases when carry remains at the end Language: Java -> Runtime: 1 ms (Beats 99.65%) -> Memory: 43.90 MB Strong basics make complex problems easier. One day, one win. 🔥💻 #LeetCode #Java #Binary #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
✅ Day 33 – LeetCode Practice Problem: Rotate String (LeetCode 796 | Easy) Today I worked on string manipulation and pattern recognition by solving LeetCode 796: Rotate String. 🔍 Key Insight: To check if goal is a rotation of s, I learned that if goal is found inside (s + s), then s can be rotated to become goal! This simple trick avoids brute force and makes the solution clean and efficient. 💡 What I practiced: • String concatenation • Pattern matching • Efficient problem approach 📌 Time Complexity: O(n) 📌 Space Complexity: O(n) 🚀 Feeling good about strengthening my string problem skills today! #100DaysOfCode #LeetCode #CodingPractice #Java #StringAlgorithms
To view or add a comment, sign in
-
-
Day 44: Avoiding the O(n²) Trap 🔍 Problem 3714: Longest Balanced Substring II Today’s goal: find the longest substring where all present characters appear equally. Since we only had 'a', 'b', and 'c' to deal with, I split the logic into three cases (1, 2, or 3 unique characters). Pro tip: I almost nuked my runtime by using map.clear() inside a loop. Since clear() iterates over the map to nullify entries, it’s O(n). Switching to new HashMap<>() kept the complexity at a clean O(1) reset and a total O(n) pass. Don't let built-in methods turn your linear solution into a nested nightmare. Complexity matters. 🧗♂️ #LeetCode #Java #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 513 of #750DaysofCode 🔥 LeetCode 1461 | Check If a String Contains All Binary Codes of Size K Today’s problem was a really interesting mix of strings + hashing + sliding window + bit manipulation. 🧠 Problem Summary: Given a binary string s and an integer k, return true if every possible binary code of length k exists as a substring of s. For example: Input: s = "00110110", k = 2 All possible binary codes of size 2 → "00", "01", "10", "11" Since all exist → ✅ true 💡 Key Insight For length k, total possible binary codes = 2^k So instead of generating all binary codes explicitly, we: Slide a window of size k across the string Store each substring in a HashSet If set.size() == 2^k, we return true ⚡ Optimized Thinking Since: k <= 20 2^20 = 1,048,576 We can also use: Rolling hash Bitmask technique Integer encoding instead of substring creation 🎯 What I Learned Today ✔ Instead of generating all combinations, track what appears ✔ Bitmasking can optimize substring problems ✔ Sliding window + hashing is powerful for pattern coverage problems ✔ Always check constraints before choosing brute force Consistency > Motivation 💪 Onwards to Day 514 🚀 #750DaysOfCode #LeetCode #Java #DSA #CodingJourney #BitManipulation #SlidingWindow
To view or add a comment, sign in
-
-
#Day32 of #365DaysOfCode Today’s LeetCode Practice: 🔹 Container With Most Water (LeetCode 11) Solved a classic two-pointer optimization problem where the goal is to find two lines that together form a container holding the maximum water. 💡 Key Insight: Start with two pointers at both ends. Calculate area using: width × min(height[left], height[right]) Move the pointer with the smaller height inward, because the smaller height limits the water capacity. This guarantees exploring better possibilities efficiently. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Consistency > Motivation. Day by day, improving problem-solving and logical thinking skills #LeetCode #ProblemSolving #Java #CodingJourney #FutureEngineer #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
Day 29 – DSA Journey 🚀 | Strings As part of my daily DSA practice, I worked on a simple yet important string problem from LeetCode that helped me understand how strings can be represented and compared in different forms. 📌 Problem Practiced: Check If Two String Arrays Are Equivalent 🔍 Core Idea: Each array represents a string formed by concatenating its elements in order. By joining all strings from both arrays and comparing the final results, we can easily determine whether they represent the same string. 📌 Concepts Applied: • String concatenation using StringBuilder • Iterating through string arrays • Understanding string immutability in Java • Comparing strings using .equals() • Writing clean and readable code 💡 Key Insight: Using StringBuilder makes string concatenation efficient and avoids unnecessary overhead caused by repeated string creation in loops. ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) Practicing such foundational string problems is helping me gain confidence in handling input transformations and choosing the right tools for the job. One step at a time, staying consistent 🚀 #Day29 #DSAJourney #LeetCode #Strings #Java #ProblemSolving #LogicBuilding #LearningInPublic #Consistency
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