🌟 Day 84 of #100DaysOfCode 🌟 🔹 Problem Solved: Check If All 1's Are at Least K Places Away – LeetCode Today’s challenge was all about precision, pattern detection, and distance validation within a binary array. The goal? Ensure every 1 is properly spaced and respects the minimum distance k. ✨ Approach: I iterated through the array, tracked the position of each 1, and checked the gap before encountering the next one. A simple but effective two-pointer style logic! 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — single pass through the array 💾 Space Complexity: O(1) — constant extra memory 🚀 Performance: ✔ Runtime: 1 ms (Beats 99.71%) ✔ Memory: 65.68 MB 🔑 Key Insight: Even a straightforward problem can sharpen your ability to detect patterns and handle constraints efficiently. Small details—like distances between bits—can make or break logic. #LeetCode #DSA #CodingChallenge #100DaysOfCode #ProblemSolving #BinaryArray #Algorithms #TechJourney #CodeEveryday #JavaCoding
Solved LeetCode challenge: Check if all 1's are at least K places away
More Relevant Posts
-
While finding all unique combinations from a set of distinct elements (LeetCode – Combination Sum), one question naturally comes up: What if we first generate combinations with duplicates, and then remove the duplicates? That’s where backtracking becomes really effective. The requirement of unique combinations tells us how we should explore the solution space. I’ve explained: -> how backtracking works here -> and how it helps us get only unique combinations in my blog. Read it here: https://lnkd.in/gv9jpheg #leetcode #datastructures #algorithms #backtracking #coding #dsa
To view or add a comment, sign in
-
🛣️ Day 148 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Dijkstra Algorithm 🟡 Difficulty: Medium 🧠 Approach: Today’s challenge focused on finding the shortest path from a source node to all other vertices in a weighted graph using Dijkstra’s Algorithm. 🔍 Key Ideas: The graph is undirected and weighted, with no negative edge weights. Use a Min Priority Queue (Heap) to always process the node with the smallest known distance. Maintain a dist[] array to store the shortest distance from the source to every node. 🛠️ Steps Followed: 1. Build an adjacency list from the given edges. 2. Initialize all distances as infinity, except the source node (0). 3. Push the source into a min-heap. 4. Repeatedly extract the node with minimum distance. 5. Relax all its adjacent edges and update distances if a shorter path is found. 6. Continue until the heap is empty. This greedy strategy guarantees the shortest paths efficiently. ⚡ Complexity: ⏱ Time Complexity: O((V + E) log V) (due to priority queue operations) 💾 Space Complexity: O(V + E) (for adjacency list, distance array, and heap) 📊 Results: ✔️ 1113 / 1113 test cases passed 🎯 Accuracy: 100% 🚀 Efficient shortest-path computation using heaps Mastering graph algorithms one step closer—shortest paths unlocked! 🧭📈 #Day148 #gfg160 #GeeksforGeeks #Dijkstra #GraphAlgorithms #ShortestPath #PriorityQueue #GreedyAlgorithm #DSA #ProblemSolving #CodingChallenge #DailyCoding #TechJourney #SoftwareEngineering #Consistency
To view or add a comment, sign in
-
-
🧮 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐃𝐚𝐢𝐥𝐲 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 #𝟓𝟗 – 𝐒𝐩𝐢𝐫𝐚𝐥 𝐌𝐚𝐭𝐫𝐢𝐱 𝐈𝐈 ⏺ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐃𝐞𝐟𝐢𝐧𝐢𝐭𝐢𝐨𝐧 (𝐟𝐫𝐨𝐦 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞): Given an integer n, generate an n × n matrix filled with numbers 1 to n² in spiral order. 📖 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: n = 3 → [[1,2,3],[8,9,4],[7,6,5]] 💡𝐄𝐚𝐬𝐲 𝐰𝐚𝐲 𝐭𝐨 𝐮𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝: Fill the matrix like a spiral path: ➡️ top row → ⬇️ right column → ⬅️ bottom row → ⬆️ left column, then shrink the boundaries and repeat. ✨ 𝐊𝐞𝐲 𝐈𝐝𝐞𝐚: Use 4 boundaries (top, bottom, left, right) and keep moving them inward after each direction. 📝 𝐂# 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧: The complete code with comments is shown in the attached image 👇 📌 Tomorrow: 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 #𝟔𝟎 – 𝐏𝐞𝐫𝐦𝐮𝐭𝐚𝐭𝐢𝐨𝐧 𝐒𝐞𝐪𝐮𝐞𝐧𝐜𝐞 (C#). Stay tuned! #LeetCode #CSharp #CodingChallenge #ProblemSolving #Algorithms #Matrix
To view or add a comment, sign in
-
-
🔥 Day 264 - Daily DSA Challenge! 🔥 Problem: 🔍 Single Number II Given an integer array where every element appears exactly three times except for one, find that single unique element. 💡 Key Insights: 🔹 Brute force or sorting works, but not optimal. 🔹 This is a bit manipulation problem with a clever state-tracking trick. 🔹 Use two variables (ones, twos) to track bits seen once and twice. 🔹 When a bit appears the third time, it gets cleared from both. ⚡ Optimized Plan: 1️⃣ Iterate through each number n. 2️⃣ Update: • ones → bits seen once • twos → bits seen twice 3️⃣ Use bitwise logic to clear bits that appear three times: ones = (ones ^ n) & ~twos twos = (twos ^ n) & ~ones 4️⃣ At the end, ones holds the unique number. 🔥 Elegant bitmasking that simulates modulo-3 counting at the bit level. ✅ Time Complexity: O(n) — single pass ✅ Space Complexity: O(1) — constant extra space 💬 Challenge for you: 1️⃣ Can you generalize this for numbers appearing k times except one? 2️⃣ How would you solve this if two numbers appeared once? #DSA #BitManipulation #LeetCode #Arrays #CodingChallenge #ProblemSolving #KeepCoding #100DaysOfCode
To view or add a comment, sign in
-
-
#Day432 of #500DaysOfDSA Topics and Learnings: #BinarySearch Problems Re-revised: 52. #LeetCode #774 : Minimize Max Distance to Gas Station Approach: Used Binary Search to solve this Complexity Analysis: TC: O(N*log(Len)) + O(N) SC: O(1) #500DaysLeetCodeChallenge #500DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
🚀LeetCode Daily Challenge 🧩 Problem: Plus One You are given a non-empty array digits, where each element represents a single digit of a non-negative integer. The digits are stored such that the most significant digit comes first. 🎯 Goal: Increment the integer by one and return the resulting digits as an array. 🧠 Key Intuition Adding 1 is straightforward unless there is a carry. If the last digit is less than 9 → just increment it. If the last digit is 9 → it becomes 0 and produces a carry. This carry may propagate to the left. In the special case where all digits are 9 (e.g., 999), we need to add a new digit at the front. So the problem boils down to: ✔ Handle carry propagation correctly ✔ Build the result safely without integer overflow 🛠 Approach Start from the last digit and add 1. Compute the carry and propagate it toward the most significant digit. Store digits in a result array while moving left. If a carry remains after processing all digits, append it. Reverse the result to restore correct order. This ensures correctness for all edge cases. 📈 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem https://lnkd.in/dy3GT279 💻 Solution https://lnkd.in/dYJKPB6m #LeetCode #Cpp #DSA #Arrays #Math #ProblemSolving #CodingChallenge #LeetCodeDailyChallenge #Algorithms
To view or add a comment, sign in
-
🚀LeetCode Daily Challenge 🧩 Problem: Count Negative Numbers in a Sorted Matrix You are given an m × n matrix where: Each row is sorted in non-increasing order Each column is also sorted in non-increasing order 🎯 Goal: Count the total number of negative numbers in the matrix efficiently. 🧠 Key Intuition A brute-force approach would scan every element → O(m·n), which is not optimal. Because the matrix is sorted both row-wise and column-wise, we can do much better: Start from the top-right corner If the current element is negative: ✔ All elements below it in the same column are also negative If the current element is non-negative: ✔ Move down to the next row This allows us to eliminate entire sections of the matrix at once. 🛠 Approach (Two-Pointer Technique) Initialize: row = 0 (top row) col = n - 1 (last column) While row < m and col >= 0: If grid[row][col] < 0: Add (m - row) to the count Move left (col--) Else: Move down (row++) Return the total count This strategy ensures we never revisit any cell. 📈 Complexity Analysis Time Complexity: O(m + n) Space Complexity: O(1) 🔗 Problem https://lnkd.in/dY9jsTkg 💻 Solution https://lnkd.in/daQrMf4A #LeetCode #Cpp #DSA #TwoPointers #Matrices #Arrays #ProblemSolving #CodingChallenge #LeetCodeDailyChallenge #Algorithms
To view or add a comment, sign in
-
LeetCode Problem #83: Remove Duplicates from a Sorted Linked List 📘🔗 Today I worked through a classic linked list problem that demonstrates the Two Pointer Pattern and how efficient simple pointer manipulation can be. Problem Summary Given a sorted linked list, the goal is to remove duplicate values so each number appears only once. Since the list is already sorted, duplicates appear next to each other, meaning we can solve the problem in O(n) time and O(1) space without using extra memory. Approach - Use a pointer (current) to walk through the list - Compare current.val with current.next.val - If they match, skip the duplicate by adjusting current.next - Otherwise, move to the next node - Repeat until the end of the list This problem is a great example of how linked lists allow constant-time deletions by simply adjusting pointers. No shifting elements like in arrays. I’ve included a screenshot of my solution below. If you enjoyed this breakdown, let me know. I’m planning to share more LeetCode explanations as I continue my study. #LeetCode #Algorithms #TwoPointerPattern #ComputerScience
To view or add a comment, sign in
-
-
🧩 PATTERN #3 — Slow and Fast Pointer 🎯 Day 18/45 – DSA Challenge! 🔍 Problem (287 Find the Duplicate Number) You are given an array containing n + 1 integers, where each integer is between 1 and n (inclusive). There is only one duplicate number, but it may be repeated more than once. Your task is to find the duplicate number without modifying the array and using constant extra space. 🧠 My Approach (Floyd’s Cycle Detection Algorithm) • Step 1 — Treat the array as a Linked List: • Each value points to the next index • This forms a cycle due to the duplicate number • Step 2 — Detect the cycle using Slow & Fast pointers: • slow moves one step • fast moves two steps • When slow == fast → cycle detected • Step 3 — Find the entry point of the cycle: • Reset one pointer to the start • Move both one step at a time • The meeting point is the duplicate number ⏱ Time Complexity :O(n) — each pointer traverses the array at most once. 📦 Space Complexity :O(1) — no extra memory used. #Algorithms #DataStructures #SlidingWindow #CodingChallenge #LeetCode #ProblemSolving #TechInterview #Programming #CompetitiveProgramming
To view or add a comment, sign in
-
-
⚡ Day 110 of My LeetCode Journey — Problem 1922: Count Good Numbers 💡 Problem Insight: Given an integer n, count how many length-n digit strings (leading zeros allowed) are good — digits at even indices (0-based) must be even {0,2,4,6,8} and digits at odd indices must be prime {2,3,5,7}. Return the count modulo 10^9 + 7. LeetCode +1 🧠 Concept Highlight: Every position is independent: each even index has 5 choices, each odd index has 4 choices. So the total count is 5^(⌈n/2⌉) × 4^(⌊n/2⌋) (mod 10^9 + 7). For large n use fast modular exponentiation to keep it O(log n). AlgoMonster +1 💪 Key Takeaway: This one’s pure combinatorics — recognize independence and stop overthinking. When choices per slot don’t interact, multiply and optimize the exponentiation. Efficient math > brute force. designgurus.io ✨ Daily Reflection: Nice reminder that many problems are about modeling the right math first — code becomes a formality after that. Short, clean thinking wins. #Day110 #LeetCode #CountGoodNumbers #MathLogic #ModularArithmetic #ProblemSolving #100DaysOfCode #DSA #CodingJourney #LearnByDoing
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