🚀 Day 54 | LeetCode Learning Journal Today I solved Range Sum Query Immutable using C++. This problem was a great introduction to optimizing repeated queries using preprocessing! 🔑 Key Points: • Used Prefix Sum Array to store cumulative sums • Precomputed values to avoid recalculating sums every time • Answered each query in O(1) time • Focused on reducing time complexity from brute force O(n) to optimal 🌱 What I Learned: • How preprocessing can drastically improve performance • Concept of prefix sums and their real-world use • Trade-off between space and time complexity • Writing cleaner and efficient query-based logic #LeetCode #100DaysOfCode #DSA #CodingJourney #CPlusPlus #Algorithms #Day54 🚀
Ayushi kumari’s Post
More Relevant Posts
-
🚀 Coding Challenge: Day 11 Solved Sqrt(x) on LeetCode. ⚡ Approach: Used Binary Search on the answer space (0 → x). Calculated mid and compared mid * mid with x: ->If equal → found exact answer ->If smaller → store mid and move right ->If larger → move left ⚡ Time Complexity: ✔ O(log x) — search space halves every step ⚡ Space Complexity: ✔ O(1) — no extra space used ⚡ Key Learning: ✔ Binary Search can be applied beyond arrays ✔ Think in terms of searching for answers, not just indices #DSA #LeetCode #BinarySearch #CPlusPlus #ProblemSolving
To view or add a comment, sign in
-
-
Solved today’s LeetCode Hard: 3655. XOR After Range Multiplication Queries II ✅ At first, it looked like a direct simulation problem. For each query: • start from l • jump by k • multiply by v Simple idea. But with n = 1e5 and queries = 1e5, that approach breaks very fast. So the real challenge was not implementing the updates… It was figuring out how to avoid doing them one by one. What I learned from this problem: The important observation was that each query updates indices in an arithmetic progression: l, l+k, l+2k ... That led to a much better approach: • Large k → process directly • Small k → group and batch efficiently That small observation completely changed the problem. What I liked about this one is that it didn’t need some magical trick. It just needed the right way of looking at the updates. Sometimes hard problems are less about advanced coding and more about seeing the structure early. Good problem. Nice learning. 🚀 Problem Link : https://lnkd.in/dHBq8t5z Solution : https://lnkd.in/dqMAvJca #LeetCode #Cpp #ProblemSolving #CodingJourney #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Day 72 of #100DaysOfDSA Solved a classic Backtracking problem 🔥 🧩 Problem Solved: LeetCode 77 – Combinations 💡 Key Idea: Generate all possible ways to choose k numbers from 1 to n using Backtracking. 🔍 Approach: Start from a number and pick it Recursively choose next numbers in increasing order Once size becomes k, store the combination Backtrack and try other possibilities ⚡ What I Learned: How recursion builds combinations efficiently Importance of start index to avoid duplicates Backtracking = Choose → Explore → Undo 💻 Language Used: C++ #Day72 #100DaysOfDSA #LeetCode #Cpp #Backtracking #Recursion #CodingJourney
To view or add a comment, sign in
-
-
60 of #100DaysOfCode Solved LeetCode 704 – Binary Search using a recursive approach in C++ 💻 🔍 Approach: Instead of the usual iterative method, I implemented Binary Search using recursion. The idea is simple but powerful: Find the middle element If it matches the target → return index ✅ If target is smaller → search left half If target is larger → search right half Base case → when search space becomes invalid (left > right) 🧠 This approach reinforces divide-and-conquer thinking and helps build strong fundamentals for advanced problems like trees and recursion-based searches. ⏱️ Complexity: Time: O(log n) Space: O(log n) due to recursion stack #LeetCode #DSA #BinarySearch #Recursion #Cpp #CodingJourney #Placements #TechLearning
To view or add a comment, sign in
-
-
Ever look at a LeetCode problem and think, "Oh, this is just simple math," only to see a constraint of $10^{15}$ staring back at you? That was my experience with the "Count Good Numbers" problem today. The core logic was actually pretty straightforward: even indices get even digits (5 options), and odd indices get prime digits (4 options). But trying to calculate 5^even * 4^odd for massive numbers? Immediate Time Limit Exceeded (TLE). I had to scrap the standard approach and write a custom pow() function using Binary Exponentiation. It’s wild how applying modulo 10^9 + 7 at every single multiplication step within the recursive call is the exact difference between a failing solution and a clean O(log n) pass without integer overflow. Definitely a great reminder that knowing the brute-force math is only half the battle—optimizing it is where the real engineering happens. Back to the grind! #LeetCode #DSA #CPP #CompetitiveProgramming #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Progress 32/50 — Generate Parentheses Today I worked on a problem focused on recursion and backtracking 🧩 💡 The challenge was to generate all possible combinations of well-formed parentheses for a given number of pairs. 🧠 Approach: Used a backtracking approach by recursively adding opening and closing parentheses while maintaining valid combinations at each step. This ensured only well-formed patterns were generated. ⏱ Time Complexity: O(4ⁿ / √n) 💡 What I learned: This problem highlighted how backtracking can be used to systematically explore valid combinations while pruning invalid paths early. 📈 Strengthening understanding of recursion and improving confidence in solving pattern-generation problems. #LeetCode #DSA #Backtracking #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
Day 7 🚀 Solved: Balanced Binary Tree (LeetCode 110) This problem builds on recursion and tree depth. A tree is balanced if the height difference between left and right subtrees is at most 1 for every node. 💡 My approaches: 🔹 Approach 1 (Brute Force): For every node, calculate left and right subtree heights Check the difference and recurse further 🔹 Approach 2 (Optimal – Postorder DFS): Compute height and balance together in one traversal Avoid recomputing subtree heights 💡 Key learning: Instead of solving subproblems separately, combine them in a single DFS to optimize performance. ⏱️ Time Complexity: Brute Force → O(n²) Optimal → O(n) 🔗 GitHub: https://lnkd.in/gVdJeg2a #DSA #LeetCode #Coding
To view or add a comment, sign in
-
🚀 Day 40 of My LeetCode Journey 💻🔥 Solved LeetCode #287 – Find the Duplicate Number today using the Negative Marking Technique 🎯 This approach uses the input array itself to track visited numbers by marking indices as negative. If an index is already negative, that number is the duplicate. Smart and efficient! ⚡ ✨ Key Learnings: 🔹 Using array indices as a hashing mechanism 🔹 Importance of Math.abs() while handling modified values 🔹 Restoring the array after processing 🔹 Solving with O(n) time complexity and O(1) extra space 💡 Problems like this show how creativity in using existing data structures can lead to optimized solutions. 📌 Day 40 complete — one more step forward in mastering Data Structures & Algorithms. 🚀 #Day40 #LeetCode #LeetCode287 #CodingJourney #DSA #Java #ProblemSolving #Algorithms #TechGrowth #Consistency #SoftwareEngineer
To view or add a comment, sign in
-
-
Day 6 🚀 Solved: Maximum Depth of Binary Tree (LeetCode 104) This is a classic recursion problem on trees. 💡 Key idea: The depth of a tree is 1 + the maximum depth of its left and right subtrees. 🔹 Approach: If the node is null → depth is 0 Recursively calculate depth of left and right Take the maximum and add 1 ⏱️ Time Complexity: O(n) 🔗 GitHub: https://lnkd.in/gz5mBpDx #DSA #LeetCode #Coding
To view or add a comment, sign in
-
Day 55 of 100 Days of LeetCode 💻 Today I solved Longest Consecutive Sequence — and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the “start of sequence” logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). 💡 Lesson learned: Don’t just think your logic is right → verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ✅ Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
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