LeetCode 1011 — Capacity To Ship Packages Within D Days Worked on determining the minimum ship capacity required to transport all packages within a fixed number of days while preserving the given order. Approach — Binary Search on Capacity + Feasibility Check - Observed that ship capacity must lie between: - Maximum single package weight (lower bound) - Sum of all weights (upper bound) - Applied binary search within this capacity range - For each candidate capacity: - Simulated the shipping process day by day - Counted how many days were required without exceeding capacity - If shipping finished within the allowed days → tried a smaller capacity - Otherwise → increased the capacity This reduced the problem to O(n log(sum of weights)), a classic example of binary search on the answer space rather than the array itself. A strong reminder that many optimization problems are really about searching the minimum feasible value, not brute-forcing combinations. #leetcode #binarysearch #dsa #algorithms #codingjourney #problemsolving #javaprogramming #learninpublic #techskills #placements #codingpractice
LeetCode 1011: Minimum Ship Capacity for Package Delivery
More Relevant Posts
-
LeetCode 78 — Subsets Worked on generating all possible subsets (power set) of a given array of unique elements. Approach — Backtracking (Inclusion / Exclusion) - For every element, there are two choices: include it or exclude it - Used recursion to explore both branches at each index - Base case: when index reaches the array length → store the current subset - Maintained state using add → recurse → remove (backtracking step) - Total subsets formed = 2ⁿ Key learning: - This problem made the recursion tree very clear. - Every element doubles the number of possibilities. Once the inclusion/exclusion pattern is understood, many subset and combination problems follow the same structure. #leetcode #recursion #backtracking #dsa #algorithms #codingjourney #problemSolving
To view or add a comment, sign in
-
-
LeetCode 90 — Subsets II Worked on generating all possible subsets of an array that may contain duplicates. This is an extension of the Subsets problem, but duplicates add a small twist. If handled carelessly, duplicate subsets get generated. Approach — Backtracking + Duplicate Skipping - Sorted the array first to group duplicates together - At each index, made the usual include / exclude decision - While skipping (not taking), moved the index forward past duplicate values - Ensured that identical elements don’t start identical branches Core idea :- Instead of filtering duplicates at the end, avoid creating them during recursion itself. Key learning: - Handling duplicates is usually about controlling the starting point of recursion branches. - Small adjustments in index movement can prevent large amounts of redundant work. This felt like a refined version of the basic subsets pattern. #leetcode #recursion #backtracking #dsa #algorithms #problemSolving #codingjourney
To view or add a comment, sign in
-
-
LeetCode 2643 — Row With Maximum Ones Worked on identifying the row containing the highest number of 1s in a binary matrix, along with the total count of ones in that row. Approach — Row-wise Counting with Maximum Tracking - Traversed each row of the matrix sequentially - Counted the number of 1s present in the current row - Maintained two variables to track: - The maximum count of ones seen so far - The row index where this maximum occurs - Updated the result whenever a row exceeded the previous maximum - Returned both the row index and the corresponding count This straightforward traversal runs in O(m × n) time and reinforces a key idea - not every problem needs complex optimization, sometimes a clear linear scan with proper state tracking is the most reliable solution. A reminder that strong problem solving is about choosing the simplest correct approach first, then optimizing only if required. #leetcode #arrays #matrix #dsa #algorithms #codingjourney #problemsolving #javaprogramming #learninpublic #techskills #placements #codingpractice
To view or add a comment, sign in
-
-
Day 13 | LeetCode Learning Journal 🚀 Today I solved Maximum Depth of Binary Tree on LeetCode. This problem helped me understand how to find the maximum depth (height) of a binary tree, which represents the longest path from the root node to a leaf node. 🔑 Key Points: • Uses Depth-First Search (DFS) with recursion • Recursively explore the left and right subtrees • The depth of a tree is calculated as 1 + max(left depth, right depth) • Base case: if the node is null, return 0 • Continue the process until all nodes are visited 🌱 What I Learned: • How recursion works in tree problems • Understanding the concept of height or depth of a binary tree • Practical use of DFS traversal • Improved problem-solving skills in binary tree structures • Strengthened my understanding of recursive algorithms #LeetCode #100DaysOfCode #DSA #BinaryTree #DFS #TreeDepth #Day13 🚀
To view or add a comment, sign in
-
-
🚀 Day 64 of LeetCode Problem Solving Journey — 100 Days LeetCode Challenge Today, I solved LeetCode #215 — Kth Largest Element in an Array using C++, under the guidance of Trainer NEKAL SINGH SALARIA Singh at REGex Software Services. 🔍 Problem Summary: Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest in sorted order, not the kth distinct element. 🧠 Approach Used (Sorting Method): I used the sorting approach to solve the problem: Sort the array in ascending order Traverse the array from the end (largest elements) Decrease k until reaching the kth largest element Return that value This approach is straightforward and easy to implement. 📚 Key Learnings of the Day ✔ Sorting helps quickly access ranked elements ✔ Traversing from the end simplifies finding largest values ✔ Always understand whether the problem requires distinct or non-distinct elements ✔ Simple approaches are good starting points before optimization ⏱ Complexity • Time Complexity: O(n log n) • Space Complexity: O(1) (ignoring sorting internals) 💡 Optimization Insight: The problem asks if we can solve it without sorting. A more optimal solution uses Quick Select or a Min Heap, which can reduce the time complexity to O(n) on average. Learning continues — see you on Day 65 🚀 #Day64 #100DaysLeetCodeChallenge #LeetCode #RegexSoftwareServices #NekalSingh #ProblemSolving #DSA #CPlusPlus #CodingChallenge #ProgrammingJourney #Arrays #KeepGrowing
To view or add a comment, sign in
-
-
⚡ Binary Logic at Scale: 0ms Performance Win! 🚀 I'm excited to share my latest solution for today's LeetCode challenge! I tackled the "Number of Steps to Reduce a Number in Binary Representation to One" and achieved a perfect 0 ms runtime, beating 100.00% of C++ submissions. 💡 The Strategy: Single-Pass Greedy Simulation Instead of performing heavy big-integer arithmetic, I simulated the reduction process by traversing the binary string from right to left (least significant to most significant bit): Handling Odds and Evens: For each bit, I considered the current carry. If the combined value (bit + carry) was 1, it represented an odd number requiring two steps (add 1 and then divide by 2). If it was 0 or 2, it required only one step. Carry Propagation: I maintained a carry variable to manage the "+1" operations across the string, ensuring the entire process remained O(N). Efficiency: This greedy approach avoids unnecessary string manipulations or divisions, resulting in the top-tier 0 ms execution time. 📊 Consistency Milestone: This win adds to my ongoing streak of high-performance solutions across: Bitwise Mastery: Reverse Bits, Alternating Bits, and Binary Gaps (all 0ms). Recursive Structures: 0ms wins in Binary Tree Traversals and Symmetry checks. Advanced Patterns: Custom sorting by bit counts and Segment Trees. Focusing on writing clean, compiler-friendly C++ is making these complex optimizations feel like second nature. 📈 . Check out the full implementation and my daily progress on GitHub: 📂 Repository: https://lnkd.in/gZ2v73xh . . . . #LeetCode #DSA #CPP #BinaryRepresentation #BitManipulation #Algorithms #ProblemSolving #SoftwareEngineering #CleanCode #Efficiency
To view or add a comment, sign in
-
-
LeetCode 70 — Climbing Stairs Worked on finding the number of distinct ways to reach the top when you can climb either 1 or 2 steps at a time. Initially, it looks like a simple counting problem. But structurally, it follows a clear recurrence pattern. Approach — Recurrence Relation - If n ≤ 1 → only one possible way - From step n, you can: - Take 1 step → reduce to (n - 1) - Take 2 steps → reduce to (n - 2) - Total ways = ways(n - 1) + ways(n - 2) This is essentially the Fibonacci pattern in a different form. While testing with small inputs, the recursive solution worked correctly. However, on submission it resulted in Time Limit Exceeded for larger inputs. That made one thing very clear :- The logic is correct, but overlapping subproblems make the pure recursive approach inefficient. Key learning :- Correct logic is not enough. Efficiency matters. Recognizing when recursion needs optimization (memoization / DP) is just as important as writing it. #leetcode #recursion #dynamicprogramming #dsa #algorithms #problemSolving #codingjourney
To view or add a comment, sign in
-
-
🚀 5 Array Patterns I Learned from Solving LeetCode Problems While practicing array problems on LeetCode, I started noticing something interesting. Many problems look different on the surface, but the underlying patterns are often the same. Instead of memorizing solutions, I began focusing on understanding the pattern behind each problem. 5 important array patterns I discovered while practicing: 1. Maximum Difference Pattern Example: Best Time to Buy and Sell Stock Concept: Track the minimum price seen so far and calculate the maximum profit at each step. 2. Candidate Elimination Pattern Example: Majority Element Concept: Use the Boyer–Moore Voting Algorithm to find the element that appears more than n/2 times. 3. Prefix & Suffix Product Pattern Example: Product of Array Except Self Concept: Compute results using left and right product traversal without using division. 4. Prefix Sum + HashMap Pattern Example: Subarray Sum Equals K Concept: Use a prefix sum with a frequency map to count valid subarrays. 5. Running Sum for Balanced Subarrays Example: Contiguous Array Concept: Track a running sum and store the first occurrence using a HashMap to detect balanced subarrays. 💡 What I learned ✔ Many DSA problems become easier once we recognize the pattern ✔ Understanding the intuition behind the algorithm is more important than memorizing code ✔ Consistent practice gradually builds problem-solving confidence Still learning. Still exploring patterns. And continuing the DSA journey step by step 🚀 #DSA #HareeshRajendran #Arrays #ProblemSolving #CodingJourney #Patterns #VanakkamDSA
To view or add a comment, sign in
-
-
Day 51/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 137 – Single Number II (Medium) 🧠 Approach: Use a hash map to count the frequency of each number. Since every element appears three times except one, return the number whose frequency is 1. 💻 Solution: class Solution: def singleNumber(self, nums: List[int]) -> int: count = {} for num in nums: count[num] = count.get(num, 0) + 1 for num in count: if count[num] == 1: return num ⏱ Time | Space: O(n) | O(n) 📌 Key Takeaway: Frequency counting is a simple and reliable approach when the problem involves repeated elements with a single unique value. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 15/50 – LeetCode Challenge 🧩 Problem: Plus One Today I solved the “Plus One” problem on LeetCode, which focuses on array manipulation and handling carry operations, similar to how addition works in mathematics. 📌 Problem Summary: You are given an array of digits representing a non-negative integer. The task is to add one to the number and return the resulting array of digits. Example: Input → [1,2,3] Output → [1,2,4] The challenge appears when digits contain 9, such as [9,9,9], where adding one creates a carry that propagates through the entire array. 🔍 Approach Used ✔ Traverse the array from right to left ✔ Add 1 to the last digit ✔ If the digit becomes 10, change it to 0 and carry forward ✔ If all digits become 0, add 1 at the beginning ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 Key Learning ✔ Understanding carry propagation ✔ Efficient array traversal ✔ Handling edge cases in numeric problems Each problem helps strengthen my DSA fundamentals and problem-solving skills. Consistency builds mastery 🚀 🔗 Problem Link: https://lnkd.in/gZuu2Vxi #DayXof50 #LeetCode #DSA #ProblemSolving #Arrays #CodingJourney #FutureAIEngineer #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