Day 13/90 DSA Journey Today I worked on an interesting problem where each bulb toggles between ON and OFF based on its occurrences in the input list. ->Key Idea: If a number appears odd number of times → bulb remains ON If it appears even number of times → bulb turns OFF -> Approach: Used a List-based toggle logic Add element if not present Remove element if already present Finally, sort the result -> Time Complexity: O(n²) using List (due to contains & remove) -> Optimized Insight: This problem can be solved more efficiently using a HashSet in O(n) time. -> Takeaway: Understanding frequency and toggling patterns is very useful in solving real-world and DSA problems. #LeetCode #DSA #Java #Coding #ProblemSolving #Learning #TechJourney
Optimizing Bulb Toggle Logic with HashSets in Java
More Relevant Posts
-
🚀 Day 61 of my DSA Journey Today’s problem: Reverse Linked List 🔁 This is one of those classic problems that really tests your understanding of pointers and how data structures work internally. 💡 What I learned: How to reverse links instead of values Importance of using prev, curr, and next pointers How in-place algorithms help optimize space ⚡ Approach in short: Traverse the list once, and keep reversing the direction of each node step by step. 📊 Complexity: Time: O(n) Space: O(1) 🧠 Takeaway: DSA is not about memorizing solutions, it’s about understanding patterns. Every problem adds a new piece to the puzzle. Consistency > Motivation 💯 #DSAJourney #100DaysOfCode #Java #LeetCode #Coding #ProblemSolving #LinkedList #KeepLearning
To view or add a comment, sign in
-
-
=> Day 20/90 DSA Journey Solved: Count Odd Numbers in an Interval (LeetCode 1523) Instead of using loops, I applied a simple mathematical formula to achieve an O(1) solution. 🔹 Key Idea: Count of odd numbers between low and high can be calculated directly using: -> ((high + 1) / 2) - (low / 2) 🔹 Why this works: -> It efficiently counts odds up to high and subtracts odds before low. 🔹 Example: Input: low = 3, high = 7 Output: 3 (Odd numbers → 3, 5, 7) -> Time Complexity: O(1) -> Space Complexity: O(1) #Java #DSA #LeetCode #ProblemSolving #Coding #Optimization
To view or add a comment, sign in
-
-
🚀 DSA Series #1 — Closest Target in Circular Array Today I solved an interesting problem involving circular arrays + shortest distance logic. 🧠 Key Insight: Instead of simulating movement, we can compute distance using modulo. 👉 Forward distance: (i - start + n) % n 👉 Backward distance: (start - i + n) % n Take the minimum of both — done in O(n) time ⚡ 📌 Complexity: O(n) time | O(1) space 💡 Learning: Circular problems often look tricky, but math simplifies everything. 🔥 Building consistency with: #DSA #Java #Coding #PlacementPreparation #100DaysOfCode If you’re on the same path, let’s connect and grow 🤝
To view or add a comment, sign in
-
-
𝗦𝗼𝗺𝗲 𝗮𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺𝘀 𝗱𝗼𝗻’𝘁 𝗷𝘂𝘀𝘁 𝘀𝗼𝗿𝘁 𝗻𝘂𝗺𝗯𝗲𝗿𝘀. They rank futures. 🎓 Today I built Smart Exam Result Ranker using Counting Sort in Java Swing GUI. 📌 Real-world idea: When marks fall within a known range (0–100), instead of comparing every student one by one, the system: ✔ counts score frequencies ✔ rebuilds rankings quickly ✔ identifies toppers instantly ✔ sorts highest to lowest efficiently That is exactly how Counting Sort works. 🚀 Today’s Build: Smart Exam Result Ranker – Counting Sort in Real Life Because DSA becomes powerful when it solves everyday systems people already understand. I’m continuing my mission to turn algorithms into practical products, one project at a time. Which algorithm should I transform next? #Java #DSA #CountingSort #Algorithms #JavaSwing #CodingProjects #Programming #SoftwareEngineer #EducationTech #StudentResults #LearnCoding #DataStructures #BuildInPublic #KapilNarula #TechProjects
To view or add a comment, sign in
-
🚀 Day 62 of My DSA Journey Today I worked on Factorial Trailing Zeroes (LeetCode 172) 💡 Initially, I thought of calculating the full factorial, but that approach quickly becomes inefficient for large inputs ❌ 🧠 Key Insight: Trailing zeros are formed by multiples of 10 (2 × 5). Since factors of 2 are already abundant, the real task is to count how many times 5 appears in numbers up to n. 📌 Example: For n = 25 → multiples of 5 contribute extra factors → result = 6 trailing zeros ✅ 💭 What I learned today: Don’t always go with brute force Look for hidden mathematical patterns Optimization often comes from changing perspective Staying consistent and learning something new every day 🙌 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved an interesting Array traversal problem by iterating from right to left. Learned how to efficiently track the maximum element on the right side without extra space 🔥 🧠 Problem 🔎 Replace Elements with Greatest Element on Right Side Given an array arr, replace every element with the greatest element among the elements to its right. 👉 The last element should be replaced with -1 (since no elements exist on its right). 👉 Return the modified array. Example Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Input: arr = [400] Output: [-1] ⚡ Key Learning 📌 Traverse from right to left to keep track of maximum 📌 Update elements in-place for better efficiency 📌 Avoid extra arrays by maintaining a running max 📌 Time Complexity: O(n) → single pass through the array 📌 Space Complexity: O(1) → no extra space used (in-place update) Improving DSA with smart array techniques 🚀 #DSA #LeetCode #Arrays #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 75 of My DSA Journey Today’s problem: Reverse Bits (LeetCode 190) At first glance, it looks simple—but it really tests your understanding of bit manipulation 🔹 What I learned today: • How to extract the last bit using n & 1 • Building a reversed number using left shift • Importance of running exactly 32 iterations (handling leading zeros!) • Thinking in terms of binary, not decimal 🔹 Key Idea: Take bits from right to left and rebuild the number from left to right. 💡 This problem helped me get more comfortable with low-level operations—something that’s super useful for writing efficient code. 📈 Progress Update: 75 days of consistency! Small steps every day are building strong problem-solving skills #DSA #100DaysOfCode #Java #CodingJourney #LeetCode #BitManipulation #Consistency #Learning
To view or add a comment, sign in
-
-
🚀 Day 99 of DSA Problem Solving Today’s problem: Word Pattern (LeetCode 290) At first glance, this problem looked simple — just matching characters with words. But the real challenge was ensuring a bijective mapping (one-to-one relationship) between pattern characters and words. 🔍 Problem Idea: We need to check if each character in the pattern maps to exactly one word in the string, and each word maps back to only one character. 💡 Key Learning: One-directional mapping is NOT enough We must ensure two-way consistency (character → word AND word → character) HashMaps are powerful for maintaining this mapping efficiently 🧠 Concepts Practiced: HashMap usage String manipulation (split) Bijective mapping logic ⏱ Time Complexity: O(n), where n = number of words 💭 Real Journey Behind the Solution: Initially, I thought using just one HashMap would work, but that led to incorrect mappings. Then I realized the importance of maintaining two HashMaps to ensure no duplication from either side. This problem strengthened my understanding of mapping relationships — a small concept but very powerful in many DSA problems. 🔥 Slowly getting better every day… consistency is the real game. #Day99 #DSA #LeetCode #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Journey Update: 7/75 Solved another problem today: Product of Array Except Self 💡 Key Idea: Used prefix (left) and suffix (right) products to build the answer without using division and in O(n) time. 🔍 Example: Input: [1,2,3,4] Output: [24,12,8,6] ⚡ Learning: Optimized approach using two passes Space optimization by reusing the same array Stronger understanding of prefix/suffix patterns Step by step progress… consistency matters more than speed 🔥 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Practice — Getting Better Step by Step! 📅 Today’s Problem: Find Square Root of a Number (Floor Value) Solved using TakeUForward platform 💻 Today’s problem was a great example of applying Binary Search beyond just searching elements. 🔹 Approach Used: Binary Search on Answer Instead of checking every number, I used binary search to efficiently find the square root by narrowing down the range. ⏱ Time Complexity: O(log n) 💾 Space Complexity: O(1) 💡 Key Learning: Binary Search is not limited to sorted arrays — it can be applied to optimize problems where the answer lies within a range. This problem helped me understand how to reduce time complexity from O(n) to O(log n) by thinking in terms of search space rather than brute force. 🔥 Consistency continues — learning something new every day! takeUforward Striver #BinarySearch #takeUforwardtakeUforward #DSA #Algorithms #Coding #Java #ProblemSolving #SoftwareEngineering #Consistency
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