✅Day 83 of #100DaysOfLeetCode 📌Problem: Given a binary array and an integer k, return true if all 1's are at least k places away from each other, otherwise return false. 🟢 Difficulty: Easy 📍Topic: Array 🎯 Goal: Check if all 1's in the array are at least k positions apart. 🧠 Key idea: Approach 1: Iterate through the array, track the position of the previous 1, and for each new 1, calculate the distance from the previous 1. If the distance is less than k at any point, return false. Otherwise, return true after the loop ends. #LeetCode #CodingChallenge #100DaysOfCode #DataStructures #Algorithms #Array #Java #CodingInterview #Programmers #DailyCoding #CodeNewbie #TechCareers #ProblemSolving #CodeChallenge
#100DaysOfLeetCode: Check if 1's in binary array are k positions apart
More Relevant Posts
-
🚀 Efficient Coding Spotlight: Counting Negatives in a Grid with Binary Search! Recently, I tackled an interesting problem: Count the number of negative numbers in a sorted 2D grid. While a brute-force approach works, I wanted something faster and more elegant. Here’s how I combined the power of binary search with 2D arrays in Java: Leetcode problem: https://lnkd.in/gcfH37k2 What’s cool about this approach? ⚡ Optimized Performance: By leveraging binary search on each row, the time complexity is reduced from O(mn) to O(mlog n). 🤖 Algorithmic Thinking: Instead of scanning every cell, find the first negative in each row and quickly calculate the count. 💡 Scalable: Perfect for large datasets where efficiency is key. Takeaway: Sometimes, a classic algorithm like binary search can offer a huge speed boost in unexpected places. #Java #Algorithms #Coding #BinarySearch #Programming #TechTips
To view or add a comment, sign in
-
-
🚀 Day 48 of My Daily Coding Challenge 🚀 Today I implemented In-Place Merge Sort using Recursion — focusing on sorting the array without creating new subarrays. 📌 What I worked on: • Dividing the array using start, mid, and end indices • Recursively sorting left and right halves • Merging both halves back within the same array using a temporary buffer • Careful index handling to avoid extra space overhead 💡 Key Learning: Understanding how indices flow in recursion is crucial for writing efficient, in-place algorithms. This approach strengthened my grasp of divide-and-conquer logic and memory handling. 🔗 Solution (Java):[https://lnkd.in/dBM-nBCC] #100DaysOfCode #Day48 #Java #DSA #MergeSort #InPlaceAlgorithm #Recursion #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
Solved using the two-pointer technique by scanning from both ends, skipping non-alphanumeric characters, and comparing characters case-insensitively. 💡 Key ideas used: -> Two pointers (left & right) -> Character.isLetterOrDigit() for filtering -> Character.toLowerCase() for clean comparison -> O(n) time | O(1) space Sometimes, the trick isn’t reversing the string — it’s knowing what to ignore. #DSA #Java #TwoPointers #ProblemSolving #LeetCode #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
🔥 Day 85 of Posting on LinkedIn 📌 LeetCode 399 — Evaluate Division (Java Solution) Today’s challenge was Evaluate Division, a graph-based problem where we’re given equations like: a / b = 2.0 and must evaluate queries such as a / c or x / y. 🧠 Key Idea Model the equations as a graph, where: Each variable is a node Each division equation creates two edges: a → b with weight k b → a with weight 1/k Then, for each query, perform DFS/BFS to find the product along the path. 🚀 Takeaway This problem is a great demonstration of how graphs + DFS can solve real-world relationship queries. #leetcode #leetcodechallenge #dsa #java #graphs #coding #programming #100daysofcode #learningeveryday #womenwhocode
To view or add a comment, sign in
-
-
DAY 29 – Invert Tree + Symmetric Tree You’ll learn: ✔ Swapping left & right children ✔ Mirror comparison logic ✔ Simple & elegant recursion patterns 🌳 Problem 1: Invert Binary Tree Level: Easy Platform: LeetCode 226 Invert means: 4 4 / \ --> / \ 2 7 7 2 / \ / \ / \ / \ 1 3 6 9 9 6 3 1 🔹 Java Code class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) return null; // swap children TreeNode temp = root.left; root.left = root.right; root.right = temp; // recurse on both subtrees invertTree(root.left); invertTree(root.right); return root; } } 🔹 Explanation Swap left & right children at every node Then recursively invert subtrees Simple top-down recursion Time: O(n) Space: O(h) recursion #DSA #DataStructuresAndAlgorithms #Coding #Programmer #LeetCode #CodeEveryday #JavaDSA #CodingPractice #ProblemSolving #CP #CompetitiveProgramming #DailyCoding #TechJourney #CodingCommunity #DeveloperLife #100DaysOfCode #CodeWithMe #LearnToCode #GeekForGeeks #CodingMotivation
To view or add a comment, sign in
-
• Day 93 – LeetCode #389: Find the Difference • Problem: Given two strings s and t, where t is s with one extra character added at a random position, find that extra character. • Approach: – Created a HashMap to store the frequency of each character in t. – Iterated through s and decreased the corresponding counts in the map. – The character with a remaining count of 1 is the extra character. – Used getOrDefault() to simplify frequency counting. • Key Insight / Learning: Frequency maps are a versatile tool for string problems involving counts or differences. Using HashMap efficiently handles character counting and helps solve problems in linear time. • Complexity: – Time: O(n + m) where n = s.length(), m = t.length() – Space: O(k) where k = number of unique characters (≤ 26 for lowercase letters) • Solution Link: https://lnkd.in/gtvv5CDd #LeetCode #Java #Coding #ProblemSolving #HashMap #DataStructures #CompetitiveProgramming #Programming #DailyCoding #CodeDaily #SoftwareEngineer #LearnToCode
To view or add a comment, sign in
-
-
BloodCode 3.0 | Ep-2 Problem 961 – N-Repeated Element in Size 2N Array No hype. No shortcuts. Just pure discipline. BloodCode 3.0 continues—and this time, the problem looks simple enough to trick you. That’s where most people fail. The Problem: You’re given an array of size 2N. One element repeats N times. Sounds obvious? It isn’t about finding it—it’s about how fast, how clean, and how efficiently you do it. Brute force is lazy. Overthinking is deadly. This problem tests pattern recognition, optimal logic, and your ability to see through noise. What this episode stands for: • Thinking before coding • Minimal logic, maximum impact • Training the brain to spot repetition instantly I failed BloodCode 2.0 because consistency cracked. BloodCode 3.0 exists to fix that mistake. 30 problems. 30 days. No mercy. This isn’t content. This is a public commitment. Stay sharp. Stay ruthless. #BloodCode #BloodCode3 #LeetCode #LeetCodeDaily #LeetCodeChallenge #DSA #DSAProblems #CodingDiscipline #CodeEveryday #30DaysOfCode #ProblemSolving #AlgorithmThinking #CodingMindset #DeveloperLife #SoftwareEngineer #TechGrind #CodingMotivation #NoExcuses #ConsistencyIsKey #Java #Python #Cplusplus #ArrayProblems #InterviewPrep
To view or add a comment, sign in
-
-
Day 3/100 – LeetCode Challenge ✅ Problem: #115 Distinct Subsequences Difficulty: Hard Language: Java Approach: Dynamic Programming (Space-Optimized 1D DP) Time Complexity: O(n × m) Space Complexity: O(m) Key Insight: Count how many times string t appears as a subsequence in string s. If characters match: dp[j] += dp[j-1] (use current char + skip it) Iterate j backwards to prevent overwriting previous states Solution Brief: Used a 1D DP array where prev[j] represents ways to form t[0...j-1] from s. Base case: prev[0] = 1 (empty subsequence). When characters match, combine previous results smartly in reverse order. Mastering space optimization in DP 🔥 #LeetCode #Day3 #100DaysOfCode #DynamicProgramming #Java #Algorithm #CodingChallenge #ProblemSolving #DistinctSubsequences #HardProblem #SpaceOptimization #DSA #Programming #Tech #CodeOptimization
To view or add a comment, sign in
-
-
🚀 Day 47 of My Daily Coding Challenge 🚀 Today I implemented Merge Sort using a recursive divide-and-conquer approach with array slicing. 📌 How I solved it: • Recursively divided the array into two halves • Used Arrays.copyOfRange() to create left and right subarrays • Sorted each half recursively • Merged the sorted halves using a separate merge logic 💡 Key Learning: Breaking the array using recursive splitting + subarray copying makes the Merge Sort logic very clear and easy to understand, while maintaining an efficient O(n log n) time complexity. This approach helped me strengthen my understanding of recursion and sorting fundamentals. 🚀 🔗 Code (Java): [https://lnkd.in/dFTeCEcB] #100DaysOfCode #Day47 #Java #DSA #MergeSort #Recursion #DivideAndConquer #SortingAlgorithms #ProblemSolving #CodingJourney #SoftwareDeveloper #LearningInPublic
To view or add a comment, sign in
-
🚀 Algorithm Challenge: Plus One, the Elegant Way! 🚀 Ever faced the classic coding problem: “Given a number represented as an array of digits, add one to it?” 💡 Leetcode problem link: https://lnkd.in/gXqPqG7f I recently revisited this challenge and wanted to share a concise, efficient solution in Java. The key is to work directly with the digits array—no integer conversions, no risk of overflow, just pure logic! How does it work? We iterate from the end, adding 1 to each digit. If a digit becomes 10, we roll it over to 0 and continue the carry. If all digits were 9, we simply add a new digit at the start! ✨ This solution is efficient, clean, and scales beautifully—even for very large arrays. #Java #Coding #Algorithms #ProblemSolving #CleanCode #TechCommunity
To view or add a comment, sign in
-
More from this author
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