🚀 Day 27 of #75DaysofLeetCode Solved LeetCode 933 — Number of Recent Calls Today I worked on a simple yet powerful problem that teaches an important concept used in real-world systems: sliding window over streaming data. 💡 Problem Insight: We need to count how many requests happened in the last 3000 milliseconds for every new request. 📌 Instead of checking all past requests every time (which is inefficient), we use a Queue to maintain only relevant data. ⚡ Approach: Store incoming timestamps in a queue Remove all outdated timestamps (< t - 3000) The remaining size of the queue gives the answer 🧠 This is a perfect example of: Sliding Window Technique Real-time Data Processing Efficient Queue Usage 💻 Java Code: class RecentCounter { Queue<Integer> queue = new LinkedList<>(); public int ping(int t) { queue.offer(t); while (queue.peek() < t - 3000) { queue.poll(); } return queue.size(); } } 📊 Complexity: Time: O(1) amortized Space: O(N) 🔥 Real-world connection: This concept is widely used in: API rate limiting Server request monitoring Streaming analytics ✅ Small problems like this build strong intuition for handling large-scale systems. #LeetCode #DataStructures #Java #Coding #100DaysOfCode #SoftwareEngineering #ProblemSolving
Implementing Sliding Window Technique for Real-time Data Processing
More Relevant Posts
-
🚀 Day 44 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Find the Least Frequent Digit Problem Insight: Find the digit (0–9) that appears the least number of times in a given number. Approach: • Used a frequency array of size 10 to store digit counts • Extracted digits using modulo and division • Traversed the frequency array to find the minimum occurring digit • Returned the smallest digit in case of tie Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array of 10) Key Learnings: • Arrays are more efficient than HashMap when range is limited • Digit extraction using % 10 is very useful in number problems • Keeping track of minimum efficiently avoids extra passes Takeaway: Simple logic + right data structure = clean and optimal solution #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Journey | Day 4 — Majority Element (LeetCode) Today, I solved the Majority Element problem and focused on improving my approach from a brute force solution to an optimized one. 🔹 🧠 Problem Understanding Given an integer array, the task is to find the element that appears more than ⌊n/2⌋ times. ✔ The problem guarantees that a majority element always exists ✔ Focus is on optimizing the approach efficiently 🔹 ⚙️ Approach 1: Brute Force For each element, I traversed the entire array again to count its frequency If the frequency exceeded n/2, I returned that element ❌ Time Complexity: O(n²) 👉 Works fine but not scalable for large inputs 🔹 ⚡ Approach 2: Optimized (Using HashMap) Stored frequency of elements using a HashMap Identified the element with count greater than n/2 ✔ Time Complexity: O(n) ✔ Space Complexity: O(n) 💡 Significant improvement compared to brute force 🔹 💡 Key Learnings ✔ How to optimize from O(n²) → O(n) ✔ Importance of choosing the right data structure ✔ Better understanding of frequency-based problems #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Day4 #Learning #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 43 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sum of Unique Elements Problem Insight: Find elements in an array that appear exactly once and calculate their total sum. Approach: • Used a frequency array to count occurrences of each number • Traversed the array to build frequency • Added only those elements to sum whose frequency is exactly 1 Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array used for constraints) Key Learnings: • Frequency array is faster than HashMap when range is fixed • Two-pass approach makes logic clear and simple • Always check constraints before choosing data structure Takeaway: Right data structure makes the solution simple and efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 37 Today’s focus: Binary Search with APIs / decision functions. Problems solved: • Guess Number Higher or Lower (LeetCode 374) • First Bad Version (LeetCode 278) Concepts used: • Binary Search • Decision-based search (using API feedback) • Search space reduction Key takeaway: Both problems are classic examples of binary search on answers using an external API. In Guess Number Higher or Lower, we use the guess() API: • If guess is too high → move left • If too low → move right • If correct → return mid In First Bad Version, we use the isBadVersion() API: • If current version is bad → search left to find the first occurrence • Else → search right The key idea is: We don’t know the exact value, but we can narrow down the search space based on feedback. This pattern is useful in problems where: • A condition is monotonic (false → true transition) • We need to find the first/last occurrence of a condition Time complexity remains O(log n). Continuing to strengthen binary search intuition and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
📌 Median of Two Sorted Arrays Platform: LeetCode #4 Difficulty: Hard ⚙️ Approach • Apply binary search on the smaller array for efficiency • Define search space from 0 to n1 • Partition both arrays such that: – Left half contains (n1 + n2 + 1) / 2 elements – Right half contains remaining elements • Identify boundary elements: – l1, l2 → left side elements – r1, r2 → right side elements • Check valid partition: – l1 <= r2 and l2 <= r1 • If valid: – For even length → median = average of max(left) and min(right) – For odd length → median = max(left) • If not valid: – If l1 > r2, move left – Else move right 🧠 Logic Used • Binary Search on partition index • Dividing arrays into balanced halves • Handling edge cases using boundary values • Achieving optimal O(log(min(n1, n2))) time complexity 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 36 Completed – Revised advanced binary search and partition-based problem. #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #Algorithms #DataStructures #LeetCode #CodingPractice #CodeEveryDay #BinarySearch #ArrayProblems
To view or add a comment, sign in
-
-
Day 30/100: Making Software Robust with Error Handling & JSON! Today was all about building resilient applications. I moved beyond simple text files and dived into structured data management and exception handling. Key Technical Takeaways: Exception Handling: Mastering try, except, else, and finally blocks to prevent the app from crashing when unexpected errors occur. JSON Data Management: Transitioning from .txt to .json for a more structured, nested data format. Learned how to write, update, and read JSON using the json library. Search Functionality: Added a "Search" feature to the Password Manager, allowing the app to find and display stored credentials with a single click. User Experience: Handling cases where a user searches for a website that doesn't exist in the database yet. Handling errors and structured data is what separates a "script" from a "professional application." Feeling more confident in building production-ready code! Check out my upgraded Password Manager here: https://lnkd.in/ghRt6Gtk #Python #JSON #ErrorHandling #SoftwareEngineering #100DaysOfCode #VSCode #CleanCode
To view or add a comment, sign in
-
🚀 Day 15 of LeetCode Problem Solving Solved today’s problem — LeetCode #49: Group Anagrams 💻🔥 ✅ Approach: HashMap + Sorting ⚡ Time Complexity: O(n * k log k) 📊 Space Complexity: O(n * k) The task was to group strings that are anagrams of each other. 👉 I used a HashMap where: Key = sorted version of string Value = list of anagrams 💡 Key Idea: If two strings are anagrams, their sorted form will be the same. 👉 Core Logic: Convert string → char array Sort the array Use sorted string as key Store original string in map 💡 Key Learning: Transforming data (like sorting strings) can help in identifying patterns and grouping efficiently. Consistency is the key — learning something new every day 🚀 #Day15 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 60 / 100 – LeetCode Challenge ✅ Solved: 160. Intersection of Two Linked Lists Today’s problem was all about understanding pointer behavior and memory references in linked lists. 💡 Key Insight: Instead of comparing values, we compare node references. If two linked lists intersect, they will share the same tail nodes. 🚀 Approach Used (Optimal): Two pointers (pA, pB) Traverse both lists When one reaches the end, switch to the other list They eventually meet at the intersection node (or null) 🧠 Why it works: Both pointers travel equal distance → LengthA + LengthB, aligning perfectly without extra space. ⏱ Complexity: Time: O(m + n) Space: O(1) 💻 Result: ✔️ Accepted (41/41 test cases) ⚡ Runtime: 1 ms (Beats 99.94%) 📌 Takeaway: Sometimes the smartest solution is not about extra data structures, but about clever traversal. #Day60 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
Day 71/100 Completed ✅ 🚀 Solved LeetCode – Reshape the Matrix (Java) ⚡ Implemented an efficient matrix transformation approach by mapping elements from the original matrix to the reshaped matrix using a single traversal. Instead of creating intermediate structures, used index manipulation (count / c, count % c) to place elements correctly while maintaining row-wise order. 🧠 Key Learnings: • Understanding how to map 2D indices into a linear traversal • Efficiently converting between different matrix dimensions • Handling edge cases where reshape is not possible • Writing clean and optimized nested loop logic 💯 This problem strengthened my understanding of matrix traversal and index mapping techniques, which are very useful in array and grid-based problems. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #arrays #problemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🔥 Day 59/100 – LeetCode Challenge 📌 Problem Solved: Remove Duplicates from Sorted Array II (Medium) Today’s problem was a great exercise in in-place array manipulation and two-pointer technique. 💡 Key Idea: Since the array is already sorted, duplicates are adjacent. Instead of removing all duplicates, we allow each element to appear at most twice. 👉 The trick is to compare the current element with the element at index k-2. If they are the same → skip ❌ If different → keep it ✅ ⚙️ Approach: Initialize pointer k = 2 Traverse from index 2 Copy valid elements forward Maintain order without extra space 🧠 What I learned: How to efficiently handle constraints like “at most twice” Importance of thinking in terms of index relationships (k-2) Writing optimal O(n) solutions with O(1) space 📊 Performance: ⚡ Runtime: 0 ms (100%) 💾 Memory: 48.46 MB 💻 Tech Used: Java Consistency is key 🔑 — 59 days done, 41 more to go! #100DaysOfCode #LeetCode #Java #DataStructures #CodingChallenge #ProblemSolving #TechJourney
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