🚀 Day-75 of #100DaysCodeOfChallenge 💡 LeetCode Problem: 1526. Minimum Number of Increments on Subarrays to Form a Target Array (Hard) 🧠 Concepts Practiced: Greedy Algorithms | Array Manipulation | Difference Computation Today’s challenge was a Hard-level problem, focusing on finding the minimum number of operations required to transform an initial array of zeros into a given target array — using only subarray increments. The key insight here was realizing that each increase in value from one element to the next represents a required new operation on LeetCode. Instead of simulating every subarray operation, we can simply sum up the positive differences between consecutive elements — a great example of mathematical optimization through observation 💭 🔹 Intuition: Only when a number increases compared to the previous one, a new increment operation is needed. ⚙️ Language: Java ⚡ Runtime: 3 ms (Beats 100%) 💾 Memory: 56.82 MB (Beats 61.41%) ✅ Result: 129 / 129 test cases passed — Accepted! 🎯 Each “hard” problem solved adds one more layer of confidence — and reminds me that persistence pays off 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #CodingChallenge #GreedyAlgorithm #LearningJourney #TechMindset #KeepCoding #SoftwareEngineering #DeveloperLife #LogicBuilding
Solved LeetCode Hard problem 1526 with Java, beats 100% runtime
More Relevant Posts
-
#Day_27 Today’s problem was an interesting twist on binary search — “Find Peak Element” 🔍 Given an array of numbers, the task is to find an index i such that nums[i] is greater than its neighbors — basically, a peak element. At first glance, it seems like a simple linear scan could solve it in O(n). But I wanted to do better — and that’s where binary search comes in 💡 🧠 Approach We observe that: If nums[mid] > nums[mid + 1], it means we are on a descending slope, so the peak lies on the left side (including mid). Otherwise, we’re on an ascending slope, so the peak lies on the right side (after mid). Using this logic, we can shrink our search space by half in every iteration — a classic divide and conquer move 🔥 ⏱ Complexity Time: O(log n) Space: O(1) This is a great example of how binary search isn’t just for sorted arrays — it can also be applied to problems involving patterns or directional decisions. 💬 Every day of this challenge reinforces that problem-solving isn’t just about writing code — it’s about recognizing patterns, making logical deductions, and applying optimized thinking. #CodingJourney #LeetCode #BinarySearch #ProblemSolving #100DaysOfCode #Java #LearnByDoing
To view or add a comment, sign in
-
-
🚀 Day 146 / 180 of #180DaysOfCode ✅ Today’s Highlight: Revisited LeetCode 3234 — “Count the Number of Substrings With Dominant Ones.” 🧩 Problem Summary: Given a binary string s, the task is to count how many of its substrings have dominant ones. A substring is considered dominant if: number of 1s ≥ (number of 0s)² This creates an interesting balance check between zeros and ones, pushing you to think about substring ranges, prefix behavior, and efficient counting techniques. 💡 Core Takeaways: Great exercise in string analysis and prefix-based reasoning Highlights how mathematical conditions influence algorithm design Reinforces handling frequency relationships inside a sliding or expanding window Efficient counting becomes essential due to potential O(n²) substrings 💻 Tech Stack: Java ⏱ Runtime: 115 ms (Beats 84.11%) 💾 Memory: 47 MB 🧠 Learnings: Strengthened understanding of substring behavior under unique constraints Refined thinking around optimizing brute-force patterns A good reminder of how theoretical conditions (like squaring zeros) change practical implementation choices 📈 Progress: Today’s problem significantly improved my intuition around constraint-based substring evaluation—valuable for more advanced algorithmic challenges ahead. #LeetCode #Java #Algorithms #SubstringProblems #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #180DaysOfCode #LogicBuilding #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 52 of #100DaysOfCode 🚀 Today I solved LeetCode Problem #389 – Find the Difference 🧩 This problem is a great example of using ASCII value manipulation to solve what seems like a string comparison challenge. 💡 Key Learnings: Strengthened understanding of character encoding (ASCII values) and how they can simplify logic. Learned how summing character values can help detect differences efficiently without extra data structures. Reinforced the value of O(n) solutions for string-based problems. 💻 Language: Java ⚡ Runtime: 1 ms — Beats 99.32% 🚀 📉 Memory: 41.9 MB — Beats 65.84% 🧠 Approach: 1️⃣ Convert both strings to character arrays. 2️⃣ Compute the sum of ASCII values of both. 3️⃣ The difference between sums gives the ASCII value of the extra character in t. Simple, elegant, and efficient! ⚙️ Sometimes, a clever use of ASCII arithmetic can replace complex logic — efficiency lies in simplicity. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingChallenge #Algorithms #DataStructures #SoftwareDevelopment #LearningEveryday #CleanCode
To view or add a comment, sign in
-
-
🗓 Day 8/ 100 – #100DaysOfLeetCode 📌 Problem 3234: Count the Number of Substrings With Dominant Ones A substring is said to have dominant ones if: 👉 #1s ≥ (#0s)² The task is to count how many substrings in the binary string satisfy this condition. 🧠 My Approach: 🔹 Iterated through substrings while maintaining counts of zeros and ones. 🔹 Used the condition ones ≥ zeros² to determine whether a substring is valid. 🔹 Applied early stopping when the zero count became too large, since the quadratic requirement makes dominance increasingly difficult to achieve. 🔹 This pruning significantly reduced unnecessary checks and improved the overall efficiency. ⏱ Time & Space Complexity Time Complexity: O(n · √n) Because for each starting index, we only explore substrings until the zero count reaches ~√n (beyond which zeros² becomes too large to satisfy). This is a major improvement over the brute-force O(n²). Space Complexity: O(1) Only uses a few counters (ones, zeros, indices). 💡 Key Learning: This problem beautifully shows how mathematical constraints can simplify substring evaluation. Recognizing that zeros affect the condition quadratically helped guide a smarter pruning strategy, turning an expensive brute-force check into something efficient and elegant. #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Problem 2: Reverse Integer 💡 Leetcode Problem No: 7 Today, I solved an interesting Leetcode-style problem that involves reversing an integer — while handling tricky cases like integer overflow 🔄 ✨ Challenge: Given an integer x, reverse its digits and return the reversed number. If reversing x causes the value to go outside the signed 32-bit integer range, return 0. 💻 Key Learnings: 🔹 Used Math.abs(x) to handle negatives elegantly 🔹 Applied overflow check using: if (rev > (Integer.MAX_VALUE - d) / 10) 🔹 Mastered modulus (%) and division (/) logic for digit extraction 🔹 Ensured both positive and negative numbers are correctly reversed 💙 Tip: Always consider edge cases and overflow conditions when working with integer manipulation problems. #Java #Coding #LeetCode #ProblemSolving #JavaDeveloper #ProgrammingChallenge #LeetcodeCoding
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #852 – Peak Index in a Mountain Array 🏔️ 📘 Problem Statement: Given an integer array that first increases and then decreases (a “mountain array”), find the index of the peak element — the point where the sequence changes from increasing to decreasing. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% ⚡ 📉 Memory: 56.29 MB — Beats 60.76% 🧠 Concept Used: 🔹 Binary Search Optimization – Instead of linearly scanning the array, I applied binary search to achieve O(log n) time complexity. 🔹 This approach identifies the peak by checking midpoints and adjusting the search range efficiently. 🧩 Approach: 1️⃣ Initialize low = 0 and high = arr.length - 1. 2️⃣ Use binary search: ➡️ If arr[mid] < arr[mid + 1], the peak lies to the right → move low = mid + 1. ➡️ Else, the peak is at mid or to the left → move high = mid. 3️⃣ Return low when low == high — the index of the peak. ✅ Complexity: Time: O(log n) Space: O(1) ✨ Takeaway: Binary Search isn’t just for finding numbers — it’s a pattern for optimizing any “search in sorted behavior” scenario. Learning to spot monotonic trends in problems can turn O(n) solutions into O(log n) ones! #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #BinarySearch #DataStructures #CodingChallenge #CleanCode #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
🚩 Problem: 78. Subsets 🔥 Day 56 of #100DaysOfLeetCode 🔍 Problem Summary: Given an integer array nums, return all possible subsets (the power set). The solution set must not contain duplicates, and the order does not matter. 🧠 Intuition: This is one of the simplest and cleanest backtracking problems. At each index, you have only two choices: Include the current element Exclude the current element This naturally builds the entire power set. Alternatively, you can also build subsets by expanding a list from left to right. ✅ Backtracking Approach: Start with an empty subset Recursively explore adding each number After each choice, backtrack and remove it Add all generated combinations into the result Super clean and beginner-friendly. ⚙️ Performance: ⏱️ Runtime: 1 ms 🚀 💪 Beats: 97% of Java solutions 💾 Memory: 43 MB ⚡ (Beats ~90% of users) 📊 Complexity: Time Complexity: O(n × 2ᶰ) Space Complexity: O(n) (recursion + temp list) ✨ Key Takeaway: This problem teaches the classic recursive structure used for: Subsets Combinations Nested choices Decision-tree exploration It's the perfect stepping stone to more advanced backtracking problems. Link:[https://lnkd.in/gfQV_8w4] #100DaysOfLeetCode #Day56 #Problem78 #Subsets #Backtracking #Recursion #Algorithms #DSA #Java #ProblemSolving #LeetCode #CodingChallenge #CodingCommunity #InterviewPreparation #CrackingTheCodingInterview #SoftwareEngineering #DataStructures #ArjunInfoSolution #DeveloperJourney #LearnToCode #TechCareers #CareerGrowth #CodeNewbie #ZeroToHero #CodingIsFun #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
-
🚩 Problem: 41. First Missing Positive 🔥 Day 54 of #100DaysOfLeetCode 🔍 Problem Summary: Given an unsorted integer array nums, return the smallest positive integer that is missing. You must solve it in O(n) time and O(1) extra space. This is one of the most elegant and clever array manipulation problems. 🧠 Intuition: Key observations: The answer must be in the range [1, n+1] We want each number x (1 ≤ x ≤ n) to be placed at index x - 1 This leads to the index marking / cyclic placement trick: Iterate through the array Place each number x into its correct position: At index x - 1 By swapping until the number is either out of range or already in correct place After rearrangement, the first index i where nums[i] != i + 1 gives the answer If all numbers are in correct places → answer is n + 1 Simple idea, extremely powerful.⚙️ Performance: ⏱️ Runtime: 2 ms 🚀 💪 Beats: 99.8% of Java solutions 💾 Memory: 56 MB ⚡ (Beats 95% of users) 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ✨ Key Takeaway: This problem teaches the Cyclic Sort pattern — an essential technique for problems involving: Missing numbers Duplicates Correct placement In-place array rearrangement Mastering this trick gives you an edge in advanced array manipulation question Link:[https://lnkd.in/gV8y8dhc] #100DaysOfLeetCode #Day54 #Problem41 #FirstMissingPositive #CyclicSort #IndexMapping #Algorithms #DSA #Java #LeetCode #ProblemSolving #CodingChallenge #InterviewPreparation #CrackingTheCodingInterview #SoftwareEngineering #CodingCommunity #DataStructures #DeveloperJourney #ArjunInfoSolution #TechCareers #CareerGrowth #Programming #CodeNewbie #ComputerScience #LearnToCode #ZeroToHero #CodingIsFun #CodeLife #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
-
✅ Just solved LeetCode #654 — Maximum Binary Tree 📘 Problem: Given an integer array without duplicates, the task is to build a maximum binary tree. The construction rules are: 1️⃣ The root is the maximum element in the array. 2️⃣ The left subtree is built recursively from elements to the left of the maximum. 3️⃣ The right subtree is built recursively from elements to the right of the maximum. Example: Input → [3,2,1,6,0,5] Output → [6,3,5,null,2,0,null,null,1] 🧠 My Approach: I solved this problem using a recursive divide-and-conquer approach. 1️⃣ Find the index of the maximum element in the given range — this becomes the root. 2️⃣ Recursively build the left subtree from the subarray before the maximum element. 3️⃣ Recursively build the right subtree from the subarray after the maximum element. 💡 What I Learned: ✅ How recursion naturally fits into tree construction problems ✅ The concept of divide and conquer applied to array-based tree building ✅ How to translate problem definitions into direct recursive structure #LeetCode #Java #DSA #BinaryTree #CodingUpdate #LearningByDoing
To view or add a comment, sign in
-
-
🗓 Day 6 / 100 – #100DaysOfLeetCode 📌 Problem 2169: Count Operations to Obtain Zero The goal was to determine how many operations are needed to make both numbers zero by repeatedly subtracting the smaller one from the larger. 🧠 My Approach: Implemented the Euclidean Algorithm to optimize repeated subtraction. Instead of subtracting multiple times, used the modulus operator (%) to reduce steps efficiently. Counted the total number of operations until one of the numbers reached zero. ⏱ Time Complexity: O(log(min(a, b))) 💾 Space Complexity: O(1) 💡 Key Learning: This problem reinforced how mathematical insights like the Euclidean Algorithm can transform a brute-force approach into an elegant, optimized solution. It also reminded me of how language syntax (like Java’s integer operations) shapes the implementation of algorithmic logic. Each day brings a small improvement — and that’s what makes this journey meaningful 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Java #ProblemSolving #Algorithms #EuclideanAlgorithm #MathInCoding #DataStructures #DSA #CodingJourney #CompetitiveProgramming #SoftwareEngineering #CodeEveryday #LearningInPublic #DeveloperJourney #TechStudent #CodingCommunity #CareerGrowth #Programming #LogicBuilding #Optimization #KeepLearning
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