📅 Day 90 of #100DaysOfLeetCode Problem: 3634. Minimum Removals to Balance Array Difficulty: Medium Key Insight: Instead of deciding which elements to remove, focus on keeping the largest possible balanced subarray where max ≤ min × k. Minimum removals = total elements − size of this subarray. Approach: Sort the array to make min/max tracking easy Use a sliding window Expand the right pointer Shrink the left pointer whenever nums[j] > k × nums[i] Track the maximum valid window length Complexity: Time: O(n log n) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Min Removals to Balance Array: LeetCode Challenge
More Relevant Posts
-
Day 37 of DSA – Linked List Cycle Today I solved Linked List Cycle using the Two Pointer technique (Floyd’s Algorithm). Instead of using extra space (like a HashSet), I learned how to: Use a slow pointer (moves 1 step) Use a fast pointer (moves 2 steps) Detect a cycle when both pointers meet 💡 Key Insight: If there is no cycle → fast pointer reaches null. If there is a cycle → fast eventually catches slow. Time Complexity: O(n) Space Complexity: O(1) This problem strengthened my understanding of pointer movement and loop detection in linked lists. #100DaysOfCode #DSA #Java #LinkedList #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
#day328 of #1001daysofcode problem statement (1758): Minimum Changes To Make Alternating Binary String An alternating binary string can only follow two patterns: "010101..." or "101010...". I counted the number of changes required to convert the string into both patterns and returned the minimum of the two. ⏱Time Complexity: O(n) 🧠Space Complexity: O(1) Consistency check ✅ One LeetCode problem a day to sharpen problem-solving skills. #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
🚀 Day 25 of #100DaysOfCode Solved 24. Swap Nodes in Pairs on LeetCode 🔗🔄 🧠 Key insight: Swapping nodes in a linked list doesn’t require extra memory—careful pointer updates are enough to reverse every adjacent pair. ⚙️ Approach: 🔹Traverse the list two nodes at a time 🔹Reverse links between each adjacent pair 🔹Maintain connections with the previous pair to keep the list intact 🔹Handle edge cases for odd-length lists ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 32 of DSA 🚀 | Check If a String Contains All Binary Codes of Size K Today’s problem looked straightforward but tested how well I understand constraints and coverage. 🔹 Task: Check whether a binary string contains every possible binary code of length k as a substring. 🔹 Key realization: This is not about generating binary codes. It’s about verifying coverage using a sliding window. 💡 What I learned: Total binary codes of size k = 2^k Sliding window helps examine substrings efficiently HashSet tracks unique patterns automatically Correct boundary (s.length() - k) avoids runtime errors ⏱ Time Complexity: O(n × k) 📦 Space Complexity: O(2^k) 📌 Example: "00110110", k = 2 → all patterns {00, 01, 10, 11} exist → ✅ true This problem reinforced how small details in problem statements can completely change the approach. #DSA #SlidingWindow #Strings #Java #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 7/100 – LeetCode Challenge Problem: Palindrome Number Today’s problem focused on number manipulation without converting the integer into a string. Approach: If number is negative → return false Reverse the digits using modulo (% 10) and division (/ 10) Compare reversed number with original number Logic Used: Extract last digit: rem = x % 10 Build reversed number: rev = rev * 10 + rem Remove last digit: x = x / 10 Complexity: Time: O(log₁₀ n) Space: O(1) Key takeaway: Problems involving digits can often be solved mathematically without string conversion. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 42 of DSA 🚀 | Alternating Binary String Today’s problem: Minimum Changes To Make Alternating Binary String 🔹 Task: Convert a binary string into an alternating string (0101... or 1010...) using the minimum number of flips. 💡 Key Insight: Only two valid patterns exist: 010101... 101010... Count mismatches with one pattern and compute the other using: min(count, n - count) 📌 Example s = "0100" → Output = 1 ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) Small problem, but a great reminder that recognizing patterns can simplify the solution drastically. #DSA #Java #LeetCode #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 15 of #100DaysOfCode Solved Reverse Linked List on LeetCode 🔄🔗 🧠 Key insight: Reversing a linked list is all about careful pointer manipulation. By tracking prev, current, and next, we can reverse links in-place without extra memory. ⚙️ Approach: 🔹Initialize prev = null, current = head 🔹Store next node before breaking the link 🔹Reverse current.next to point to prev 🔹Move pointers forward until the list ends ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
#day329 of #1001daysofcode problem statement (1784): Check if Binary String Has at Most One Segment of Ones Approach 1: If the pattern "01" appears in the string, it means the sequence of '1's was broken Approach 2: Traverse the string and count segments of consecutive '1's. Whenever a '1' is found, skip the entire sequence of continuous '1's and increase the segment count. If the number of segments of '1's is exactly one, the condition is satisfied. --both approaches have same time and space complexity. ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(1) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
🚀 Day 100 of #100DaysOfLeetCode Problem: 127. Word Ladder Difficulty: Hard Key Insight: This is a shortest-path problem where each valid word transformation is an unweighted edge — BFS guarantees the minimum sequence length. Approach: Used BFS starting from beginWord. At each step, generated all possible words by changing one character (a–z). Used a HashSet for O(1) lookup and removed visited words to avoid revisits. Complexity: Time: O(N × L × 26) Space: O(N) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 18 of #100DaysOfCode Solved Remove Duplicates from Sorted List II on LeetCode 🔗 🧠 Key insight: When duplicates appear in a sorted linked list, we need to remove all occurrences, not just one. Using a dummy (sentinel) node makes it easier to handle cases where duplicates start at the head. ⚙️ Approach: 🔹Create a dummy node pointing to the head 🔹Traverse the list with two pointers 🔹If a duplicate sequence is found, skip the entire block 🔹Otherwise, move forward normally ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
Explore related topics
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