🚀 Day 8 of DSA Practice – Small Problem, Big Learning! Today I worked on a classic sorted array problem that looks simple… but has a powerful optimization behind it 👇 🔍 Problem: Count how many times a number appears in a sorted array 👉 Example: [1,1,2,2,2,2,3] → target = 2 → Output = 4 💭 How I approached it: ✅ Started with a Linear Scan (O(n)) – straightforward and reliable 🚀 Then optimized using Binary Search (O(log n)) → Found the first and last occurrence → Calculated frequency efficiently 🧠 Key Takeaway: Whenever you see a sorted array, think beyond brute force. 👉 Binary Search can turn an average solution into an optimized one. 💻 Code available here: 🔗 https://lnkd.in/g2wdfYzZ 📈 Consistency Check: Day 8 ✅ Learning something new every day and getting closer to stronger problem-solving skills 💪 #DSA #100DaysOfCode #JavaScript #CodingJourney #BinarySearch #LearnInPublic #TechGrowth
Counting Frequency in Sorted Array with Binary Search
More Relevant Posts
-
Today I solved a classic DSA problem Find the 2nd largest element in an array. The naive approach most beginners take: sort the array and pick the second last element. That works, but it costs you O(n log n). A better way one loop, two variables. Track greatest and secondGreatest simultaneously. Every time you find a new greatest, the old one becomes the secondGreatest. That is it. Time complexity: O(n). Single pass. No sorting. Edge cases I made sure to handle: - Empty array - Array where no distinct second element exists Both return -1. Small problem, but it taught me to think beyond the obvious solution. Code in the image above. If you are also learning DSA or building in public, let us connect. Drop a comment on where you are in your journey. #buildinpublic #DSA #JavaScript #LearnInPublic #EngineeringStudent #buildinginpublic.
To view or add a comment, sign in
-
-
🚀 Day 6 of My LeetCode Journey — Search Like a Pro Today was all about mastering the fundamentals of searching: 🔹 Linear Search 🔹 Binary Search (LeetCode 704) 💡 Problem 1: Linear Search The most straightforward approach: 👉 Traverse each element 👉 Compare until you find the target Simple, but important to understand its limitation: ⏱️ Time Complexity: O(n) 💡 Problem 2: Binary Search This is where things get interesting 🔥 👉 Works only on sorted arrays 👉 Divide the search space in half every step Result: ⏱️ Time Complexity: O(log n) 🚀 This problem really helped me understand how powerful optimization can be when the data is structured correctly. 🔥 Key Takeaways: Always check if the array is sorted → you might use Binary Search Optimization often comes from reducing the search space Fundamentals like searching form the base of everything in DSA Grateful for the learning journey with Namaste DSA and Akshay Saini 🚀 Day 7 coming up 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #BinarySearch #LinearSearch #NamasteDSA
To view or add a comment, sign in
-
“I thought I understood backtracking… until I tried to optimize it.” 🔁🔥 Today’s focus: deep DSA revision + sharper problem-solving I revisited Backtracking and challenged myself with: 👉 LeetCode 46 – Permutations 💥 Result: ✔️ Accepted (26/26 test cases) ✔️ 0 ms runtime (100% beat) ✔️ Optimized recursive approach But the real win wasn’t the stats. It was understanding how to: Systematically explore all possibilities Prune unnecessary paths Think in terms of decision trees, not loops Key Insight: Backtracking trains you to think like a problem solver, not just a coder. And that’s where real growth happens. 💡 Tech Stack & Concepts: JavaScript • Recursion • Backtracking • DSA Patterns Grateful to AlmaBetter for structured learning and consistent support. 🙌 🚀 Focused on writing efficient, scalable logic and improving problem-solving depth. #DSA #Backtracking #LeetCode #JavaScript #ProblemSolving #SoftwareEngineer #CodingJourney
To view or add a comment, sign in
-
-
This one DSA trick changed how I solve interval problems forever Most people struggle with Merge Intervals not because it's hard… but because they overthink it. Let’s simplify it 👇 Problem: You’re given intervals like [1,3] [2,6] [8,10] [15,18] and asked to merge overlaps. The mistake most people make: They try to compare every interval with every other interval → messy and slow. The game-changing insight: 👉 Sort first. Then merge. Once sorted, overlapping intervals come next to each other, and the problem becomes simple. How it works: • Start with the first interval • Compare with the next • If they overlap → merge • Else → move forward Core logic: if(interval[0] <= current[1]) { current[1] = Math.max(current[1], interval[1]); } Why this matters: This pattern shows up in real problems like scheduling, meetings, and range merging. Master this once → unlock multiple questions. Connect with me for more learning. #DSA #CodingInterview #JavaScript #LeetCode #Programming
To view or add a comment, sign in
-
-
🚀 Day 7 of my DSA journey Making real progress! Today was all about moving beyond the 'for' loop and diving deep into the fundamentals of Recursion. 💻 Recursion is a technique where a function calls itself to solve a problem by breaking it down into smaller, identical sub-problems. ✅ The Anatomy of Recursion: 🔹 Base Case: Your exit strategy. The mandatory condition that stops the cycle once the goal is reached. 🔹 Recursive Step: The logic where the function calls itself with a modified input, moving closer to the base case. 🔹 The Call Stack: The memory’s "waiting room." Every call sits on top of the previous one until the base case is hit and the stack "unwinds." ⚠️ Where It Goes Wrong: Stack Overflow: When the "waiting room" gets too full; too many calls without an exit will crash the memory. Infinite Loops: The result of a missing or unreachable base case, causing the program to hang. Excited to start solving recursion problems from tomorrow! 🚀 The goal has evolved: From simple loops to recursive logic, keeping the complexity low. On to Day 8! ➡️ #Day7 #JavaScript #DSA #LeetCode #Recursion #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
Most CS students finish tutorials. I'm trying to finish products. Currently building a Certificate Generator a tool that eliminates the manual work of creating certificates for events, hackathons, and workshops. Still in development. Not deployed yet. But here's what the build looks like: 𝗧𝗲𝗰𝗵 𝗦𝘁𝗮𝗰𝗸: → Flask (Python) for the backend → PyMuPDF for PDF rendering → Pillow for image/signature processing → Vanilla JS for a fully custom drag-and-drop editor → CSV input for bulk generation, JSON for template config 𝗪𝗵𝗮𝘁 𝗶𝘁 𝗱𝗼𝗲𝘀: → Generate single or bulk certificates from a CSV → Live preview before PDF export → Drag-and-drop text/signature positioning → ZIP download for bulk batches → Full font, color & signature customization The hardest part wasn't the PDF generation. It was building the interactive template editor from scratch no React, no libraries, just the browser's native APIs. That constraint made me a better developer. Deployment coming soon. Will post the link when it's live. If you're building something similar or have feedback on this project, drop it below. 🚀 #Python #Flask #WebDev #BuildInPublic #CSStudent #FullStackDevelopment #ProjectBuild
To view or add a comment, sign in
-
-
Someone was stuck on a DSA problem for hours. I explained it in 5 minutes. That gap is exactly why I write. The question was simple on the surface: "Why does the loop run range(M-N+1) instead of range(P+1)?" But the confusion behind it was real. Here is the actual logic nobody explains clearly: When you pick P elements from a list of size M — you are not just counting P. You are sliding a window of size P across M total elements. # What beginners think for i in range(P+1) # only depends on P — WRONG # What actually works for i in range(M-N+1) # depends on both M and P — CORRECT ``` The window starts at index `i` and ends at `i+N-1`. For the last index to stay inside the list: ``` i + N - 1 < M i < M - N + 1 That is why range(M-N+1) — not range(P+1). Using range(P+1) completely ignores M. Which means you will either miss valid groups or go out of bounds. The real insight here: Sliding window problems are not about the window size. They are about where the window can legally start. Once that clicks — an entire category of DSA problems becomes obvious. The best way to know if you truly understand something — Write it down for someone who doesn't. If you can't explain it simply, you don't understand it yet. Stack Overflow has 58 million unanswered or poorly answered questions. If you understand something — write it down. It costs you 10 minutes. It saves someone else 3 hours. ◆ What DSA concept took you the longest to actually understand? #StackOverflow #DSA #Python #SlidingWindow #Developer #LearningInPublic #Programming #CareerGrowth #100DaysOfCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 7 of My LeetCode Journey — Sorting Fundamentals Today I focused on two classic sorting algorithms: 🔹 Bubble Sort 🔹 Selection Sort 💡 Bubble Sort The idea is simple: 👉 Compare adjacent elements 👉 Swap if they are in the wrong order 👉 Repeat until the array is sorted It’s easy to understand, but not efficient for large datasets. ⏱️ Time Complexity: O(n²) 💡 Selection Sort A slightly different approach: 👉 Find the minimum element 👉 Place it at the correct position 👉 Repeat for the rest of the array Also simple, but still not optimal for big inputs. ⏱️ Time Complexity: O(n²) 🔥 Key Takeaways: These algorithms may not be optimal, but they build strong fundamentals Understanding how sorting works internally is more important than memorizing Optimization comes later — basics come first Big thanks to Namaste DSA and Akshay Saini 🚀 for guiding this journey Consistency is the real win — Day 8 loading 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #Sorting #BubbleSort #SelectionSort #NamasteDSA
To view or add a comment, sign in
-
🚀 Day 10 of My LeetCode Journey — Mastering Linked Lists Today’s problems: 🔹 Middle of the Linked List (LeetCode 876) 🔹 Reverse Linked List (LeetCode 206) 💡 Problem 1: Middle of the Linked List Used the classic slow & fast pointer approach: 👉 Slow moves 1 step 👉 Fast moves 2 steps 👉 When fast reaches the end → slow is at the middle 🎯 Such a simple trick, yet super powerful! 💡 Problem 2: Reverse Linked List This one is a must-know 🔥 👉 Iteratively reverse pointers 👉 Keep track of prev, current, and next 👉 Flip links step by step Also explored how this can be done using recursion 🧠 What I Learned: Two-pointer techniques are extremely useful Pointer manipulation builds real confidence in DSA Linked Lists are all about careful handling of references 🔥 Key Takeaways: Small tricks (like slow/fast pointers) can simplify problems a lot Practicing core problems like reversing a linked list is essential for interviews Understanding the logic > memorizing code Grateful for the learning journey with Namaste DSA and Akshay Saini 🚀 🙌 Day 11 loading… 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #LinkedList #ReverseLinkedList #TwoPointers #NamasteDSA
To view or add a comment, sign in
-
I started learning DSA this week. No fancy roadmap, no 6-month plan — just me, JavaScript, and a lot of wrong answers on GFG. Here's what week 1 actually looked like: 🔍 Subset of an array — looks simple until it isn't I thought using a Set was the smart move. Turns out Set only tells you IF a value exists, not HOW MANY times. So when b had duplicate elements that a couldn't cover, my code happily returned true. Wrong. Switched to a frequency map — count occurrences in a, then consume them while checking b. That fixed it. 🐛 The bug that made me stare at my screen for 20 minutes Wrote j > a.length instead of j < a.length in my inner for loop. One character. The loop never ran even once. found stayed false. Everything returned false. I thought my whole logic was broken — it was just a >. 💡 Why does the `found` variable even exist? I kept wondering why I couldn't just check the condition after the inner loop. Then it clicked — the inner loop runs many times, but the outer loop needs one final answer: did we find it or not? found is just a message passed from the inner loop to the outer loop. Simple, but it took me a while. 🔄 Array rotation Left rotation — save first element, shift everything left, place it at the end. Right rotation — save last element, shift everything right, place it at the start. Looks obvious now. Wasn't at first. 📌 1-based vs 0-based indexing on GFG Spent way too long wondering why my correct logic was giving wrong answers. GFG arrays start at index 1, not 0. So instead of arr[i] === i, you need arr[i] === i + 1. One line change, completely different results. 📦 Queue using an array Front pointer, rear pointer, size counter. enqueue moves rear forward, dequeue moves front forward. When size hits 0 — reset both to -1. It finally makes sense why we need all three. None of this came easy. But every bug I fixed actually taught me something. If you're also starting DSA and feeling lost — that's normal. The bugs are part of it. What was the first DSA bug that made you question everything? 👇 #DSA #JavaScript #CodingJourney #LearnToCode #DataStructures #Algorithms #GeeksForGeeks #100DaysOfCode #ProgrammingLife #BeginnerCoder #WebDevelopment #CodeNewbie #ProblemSolving #TechLearning
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