🚀 Day 43 of #100DaysOfCode – Striver’s DSA Sheet 🚀 ✅ Topic Covered Today: Queue – Basic Implementation Using Java JCF 💡 Lesson of the Day (Approach-Focused): 🧠 Basic Queue Implementation (Java JCF) Today, I revised how queues work internally and how Java’s Queue interface helps implement FIFO operations efficiently using LinkedList. 🔹 Operations Covered: add() → Insert element at the rear poll() → Remove element from the front peek() → Access the front element isEmpty() → Check if the queue is empty size() → Get current size of queue All operations follow the FIFO Principle (First In, First Out). 🔹 Approach & Understanding: Queue does not support indexing → traversal happens sequentially. LinkedList is commonly used because insertion and deletion at ends are O(1). Helps build intuition for problems like sliding window, BFS, task scheduling, and producer-consumer logic. 🧮 Time Complexity: Enqueue (add): O(1) Dequeue (poll): O(1) Peek: O(1) Traversal: O(n) 💾 Space Complexity: O(n) for storing elements in queue. 💭 Learning: Revisiting how Queue works through JCF helped reinforce the fundamentals of FIFO behavior, which is essential before diving into advanced queue-based problems. #100DaysOfCode #DSA #StriversSheet #Java #Queue #JCF #ProblemSolving #CodingJourney #LogicBuilding #Consistency
"Day 43 of #100DaysOfCode: Queue Implementation in Java JCF"
More Relevant Posts
-
#100DaysOfCode – Day 80 Reverse Linked List Problem: Given the head of a singly linked list, reverse the list and return the reversed version. Example: Input: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] My Approach: Used an iterative method to reverse the list efficiently by manipulating pointers. Initialized three pointers prev, temp, and front. Iteratively reversed each node’s direction until the end of the list was reached. Returned prev as the new head of the reversed list. Time Complexity: O(N) Space Complexity: O(1) Reversing a linked list might look tricky at first, but once you understand pointer manipulation it’s pure logic and flow. #takeUforward #100DaysOfCode #DSA #Java #ProblemSolving #LeetCode #LinkedList #Pointers #CodeNewbie
To view or add a comment, sign in
-
-
📌 Day 20/100 – Add Binary (LeetCode 67) Today’s challenge was about adding two binary strings and returning the result in binary format — just like simulating manual binary addition with carry logic. 🔹 Problem: Given two binary strings a and b, return their sum as a binary string without converting them into decimal. 🔹 Approach: Start from the end of both strings (like column-wise addition). Use a carry variable to handle overflow (0 or 1). Keep appending the result (sum % 2) to a StringBuilder. Reverse the string at the end since we append from LSB to MSB. 🔹 Key Learnings: StringBuilder is more efficient than string concatenation in Java. Handling indices carefully avoids edge-case bugs. Binary addition logic is similar to decimal addition — just base changes, logic stays. #100DaysOfCode #Day20 #LeetCode #Java #BinaryMath #DSA #ProblemSolving #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
🌟 Day 94 of 100 Days of Code 🌟 Today’s challenge: Maximum Number of Operations to Move Ones to the End (LeetCode 3228) 💡 🧠 Problem: Given a binary string, you can repeatedly move '1' to the right (until it meets another '1' or the end). The goal is to find the maximum number of such operations possible. ⚙️ Approach: Traverse the string once. Track the count of '1's and increment operations based on '10' patterns. Efficient O(n) solution using simple logic and character comparisons. ✅ Result: ✔️ All test cases passed ⚡ Runtime: 7 ms — Beats 78.52% of Java submissions #100DaysOfCode #Day94 #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms #CodeEveryday
To view or add a comment, sign in
-
-
🚀Day 22/100 - Problem of the day:- Check if digits are equal in string after operation. 🎯 Goal: Solve the “Has Same Digits” problem efficiently by checking if repeatedly transforming a numeric string results in a pattern with identical digits. 💡 Core Idea: Use iterative transformations — in each step, replace every adjacent pair of digits with their modular sum ((a + b) % 10). Continue until only two digits remain, and check if both are the same. 🧠 Key Takeaway: String manipulation combined with modular arithmetic can simplify complex iterative problems. Efficiently using StringBuilder in Java avoids costly string concatenation and boosts performance. 💾 Space Complexity: O(n) — for storing intermediate string transformations. ⏱️ Time Complexity: O(n²) — due to repeated string transformations in each iteration. #100DaysChallenge #java #DSA #LeetCode #Day22 #ProblemSolving
To view or add a comment, sign in
-
-
#Day-69) LeetCode 2536: Increment Submatrices by One using a 2D difference array technique in Java — a powerful approach for handling multiple range updates efficiently. 🔧 Instead of brute-force iteration over each query, I used a prefix sum strategy to apply all updates in constant time per query, followed by a cumulative pass to build the final matrix. 🧠 Highlights: Efficient submatrix updates using difference matrix Prefix sum accumulation for final values Clean, scalable Java implementation 📌 This kind of problem is a great reminder: smart preprocessing beats brute force. Let’s connect if you’ve explored similar matrix tricks or want to brainstorm more Java optimizations! #Java #LeetCode #DSA #MatrixOptimization #CodingInPublic #ProblemSolving #TechJourney #LinkedInTech
To view or add a comment, sign in
-
-
DSA Practice – Day 68 🚀 Problem: Subsets II (LeetCode 90) ✨ Brute Force Approach 1. Generate all possible subsets using recursion (like Subsets I). 2. Use a Set or HashSet to store unique subsets and avoid duplicates. 3. Convert the set back to a list before returning the result. Time Complexity: O(2ⁿ × n) (to generate all subsets) Space Complexity: O(2ⁿ × n) (storing all subsets) ✨ Optimal Approach (Backtracking with Duplicate Handling) We use backtracking, but with a twist — handle duplicates smartly. Steps: 1. Sort the array so duplicates come together. 2. Use a loop with a check if(i != ind && nums[i] == nums[i - 1]) continue; to skip duplicates. 3. Recursively generate subsets and backtrack after each recursive call. Time Complexity: O(2ⁿ × n) Space Complexity: O(n) 🌟 Key Idea Sorting + Skipping duplicates ensures we only generate unique subsets efficiently. #Day68 #Backtracking #DSA #Java #LeetCode #Placements
To view or add a comment, sign in
-
-
DSA Practice – Day 57 🚀 Problem: Delete the Middle Node of a Linked List (LeetCode 2095) Problem Statement: Given the head of a linked list, delete its middle node, and return the modified list. If there’s only one node, return null. ⚡ Brute Force Approach: Traverse the list once to count the total nodes. Find the middle index using count / 2. Traverse again to reach the node just before the middle. Delete the middle node by updating the links. Time Complexity: O(2n) ≈ O(n) Space Complexity: O(1) ⚡ Optimal Approach (Two Pointers): Use slow and fast pointers. Move fast twice as fast as slow. When fast reaches the end, slow will be at the middle. Delete the middle node by linking prev.next = slow.next. Time Complexity: O(n) Space Complexity: O(1) ✨ What I Learned: Two-pointer technique makes linked list problems efficient and elegant. Traversal count helps understand index-based operations clearly. #Day57 #DSA #Java #LinkedList #LeetCode #ProblemSolving #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
-
🔥 #100DaysOfDSA — Day 30/100 Topic: Reverse an Array in Java 🔁 💡 What I Did Today: Today, I explored how to reverse an array manually using the two-pointer approach. Instead of relying on built-in methods, I learned how to swap elements from both ends until the array is completely reversed. 🧠 Logic Used: Initialize two pointers: start = 0 (beginning of array) end = numbers.length - 1 (end of array) While start < end: Swap numbers[start] and numbers[end] Move pointers inward → start++ and end-- 📊 Example: Input → {2, 4, 6, 8, 10} Output → {10, 8, 6, 4, 2} ⚙️ Time Complexity: O(n) — each element is swapped once. O(1) space — done in-place without using extra arrays. ✨ Takeaway: Learning to reverse an array manually helps strengthen the concept of pointers, loops, and in-place operations. Sometimes the simplest logic gives the biggest "aha!" moment 💡 #100DaysOfCode #Day30 #Java #DSA #Arrays #ProblemSolving #CodingJourney #LearnInPublic #DeveloperLife #CodeNewbie #LogicBuilding
To view or add a comment, sign in
-
-
💡 LeetCode #2824 — Count Pairs Whose Sum Is Less Than Target Today I solved LeetCode Problem 2824: Count Pairs Whose Sum Is Less Than Target 🔢 Problem Summary: Given an integer array nums and a number target, return the number of pairs (i, j) where i < j and nums[i] + nums[j] < target Key Idea: Use the two-pointer technique after sorting the array. Sort the array to make pair checking efficient. Keep one pointer at the start (i) and one at the end (j). If nums[i] + nums[j] is less than target, then all pairs between i and j are valid → add (j - i) to the count. Otherwise, move the right pointer left. This gives an O(n log n) solution due to sorting. #LeetCode #Java #DSA #TwoPointers #Sorting #ProblemSolving #CodingChallenge
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