🗓 Day 10 / 100 — #100DaysOfLeetCode 🔍 Problem 1437: Check If All 1's Are at Least Length K Places Away Given a binary array nums and an integer k, the goal is to check whether every pair of 1s in the array is separated by at least k zeros. 🧠 My Approach I traversed the array while keeping track of the last index where a 1 appeared. When encountering a new 1: If it’s the first 1, just store its index. Otherwise, check the distance from the previous 1. If the gap is less than k, return false. If no violations are found, return true ⏱ Time Complexity O(n) – Only a single pass through the array. 💾 Space Complexity O(1) – Uses only constant extra space. #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Solved LeetCode problem 1437 in Java with O(n) time and O(1) space complexity.
More Relevant Posts
-
📅 Day 43 of #100DaysOfLeetCode 🧩 Problem: 944. Delete Columns to Make Sorted ⚡ Difficulty: Easy 🚀 What I learned today: Visualized the input as a grid of characters (row-wise strings, column-wise comparison) Iterated column by column and checked if characters are lexicographically sorted top to bottom As soon as a column violates sorting (strs[i][j] < strs[i-1][j]), it must be deleted Early break optimization avoids unnecessary comparisons 🧠 Approach: Loop through each column Compare adjacent rows in that column Count columns where the order is not non-decreasing ⏱️ Complexity: Time: O(n × m) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
📅 Day 41 of #100DaysOfLeetCode 🧩 Problem: 300. Longest Increasing Subsequence Difficulty: Medium 🚀 What I learned today: Used the Patience Sorting technique to solve LIS in O(n log n) time Maintained an auxiliary array where each index represents the minimum possible tail of an increasing subsequence of that length Applied binary search (lower bound / ceil) to efficiently replace elements Important insight: Using >= ensures the subsequence remains strictly increasing 🧠 Key Takeaway: Even though the auxiliary array doesn’t store the actual subsequence, its length always equals the LIS length — a powerful optimization over the classic DP O(n²) approach. 💡 Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🔥 Day 62 — Common Elements in Three Sorted Arrays | Triple Pointer Logic! 🔥✨ Today’s GFG challenge was Common Elements, where the goal is to find all elements that appear in all three sorted arrays using an efficient pointer-based approach. 📌 Today’s Highlights ✨ Used three pointers to traverse all arrays simultaneously ✨ Compared values smartly to move the right pointer at the right time ✨ Added results only when all three matched and avoided duplicates using a last tracker ✨ Passed 1215/1215 test cases on first attempt — 100% accuracy 🚀 ✨ Runtime: Smooth and efficient with clean logic This problem is a solid exercise in pointer movement, sorted array traversal, and handling duplicates carefully. Another step forward in strengthening multi-array + two/three-pointer techniques! 💻🔥 #Day62 #GeeksforGeeks #Java #DSA #ThreePointers #ProblemSolving #CodingJourney 🚀💯
To view or add a comment, sign in
-
-
🌟 Day 4/30 – Contains Duplicate Approach: Used hashing to detect repeated values in a single pass. As we traverse the array, every number is checked against a HashSet to see if it has appeared before. The moment a repeat is found, we return true. This avoids nested loops and keeps the scan efficient. Complexity: Time: O(n) Space: O(n) Key takeaway: Hash-based lookups allow constant-time checks, making duplicate detection fast, clean, and optimal for large inputs. #LeetCode #DSA #Java #ProblemSolving #30DayChallenge
To view or add a comment, sign in
-
-
Day 86 | LeetCode #1790 – Check if One String Swap Can Make Strings Equal 🔹 Problem: Given two strings s1 and s2 of equal length, determine if you can make them equal by swapping exactly one pair of characters in s1. 🔹 Approach: • Traverse both strings and track the indices where characters differ. • If there are exactly two differences, check if swapping those characters in s1 makes the strings equal. • If the strings are already equal, return true. If differences are more than two or only one, return false. 🔹 Complexity Analysis: • Time: O(n) — single pass through the strings • Space: O(1) — only two integer variables used to store indices 🔹 Key Learning: Handling differences systematically and validating the swap condition ensures correctness efficiently. #LeetCode #CodingChallenge #Java #ProblemSolving #InterviewPrep #Algorithms #DataStructures #Day86 #100DaysOfCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 17 of DSA Series Two Sum II – Input Array Is Sorted Today I worked on a classic and very important DSA problem that helped me understand the Two Pointer Technique more clearly. Problem Overview: Given a sorted array, find two numbers such that their sum equals a given target and return their 1-based indices. Key Learning Instead of using brute force, we can optimize the solution using two pointers: Start one pointer from the beginning Another pointer from the end Adjust pointers based on the comparison between current sum and target 🧠 Why Two Pointers? Reduces time complexity from O(n²) to O(n) Efficient and clean approach for sorted arrays. #DSA #Day17 #TwoPointers #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 94 of #100DaysOfCode 💻 📌 LeetCode Problem 500 – Keyboard Row Today’s problem was a fun string-based challenge that tested character mapping and validation logic. 🔹 The task is to find words that can be typed using letters from only one row of the keyboard. 🔹 Key learnings: Efficient string traversal Comparing characters against predefined sets Writing clean conditional logic in Java 🔹 Approach: Define all three keyboard rows Convert words to lowercase Check if every character belongs to the same row 📚 Language: Java 🧠 Concepts: Strings, Arrays, Conditional Logic 94 days in, discipline still strong — onward to Day 95! 💪🔥 #Day94 #LeetCode #Java #DSA #100DaysChallenge #CodingPractice #KeepGoing
To view or add a comment, sign in
-
-
#Day_59 Problem: 4Sum (LeetCode 18) Day 57 pushed the limits with 4Sum — finding all unique quadruplets equal to a target! 💥 🧠 Key Takeaways: This is an extension of 3Sum → fix two elements + two pointers. Sorting is the backbone. Duplicate skipping at both outer and inner levels is critical. Use long for sum to avoid overflow. ⚙️ Optimized Approach: Sort the array. Fix i and j. Apply two pointers for remaining part. Carefully skip duplicates. ⏱️ Complexity: O(n³), but still efficient compared to brute force. 📌 This problem taught me: How patterns scale from 2Sum → 3Sum → 4Sum. Writing clean, duplicate-free logic. Consistency + patterns = confidence! 💪 #Day57 #4Sum #LeetCode #Java #DSA #CodingPractice #LearnByDoing
To view or add a comment, sign in
-
-
Day 45/100 – #100DaysOfCode 🚀 Solved Remove All Adjacent Duplicates in String (LeetCode) using a Stack. Approach : -> Traverse the string character by character. -> If the stack is not empty and the top character is the same as the current one → pop it (remove the duplicate). -> Otherwise, push the current character onto the stack. -> After processing the full string, the stack contains the final characters (in reverse order). -> Build the result by popping from the stack and reversing it. This approach works in O(n) time and avoids unnecessary comparisons. #DSA #Stacks #LeetCode #ProblemSolving #Java #LearningEveryday #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 30 of #100DaysOfLeetCode Problem: 1523. Count Odd Numbers in an Interval Range Difficulty: Easy 🔍 Concept: Given two integers low and high, count how many odd numbers exist in the inclusive range. The trick is to use math instead of looping through all values. ✨ Key Insight: If the range length is even → exactly half are odd. If the range length is odd → result depends on whether both ends are odd. 🧠 Time Complexity: O(1) ⚡ Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
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