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
Solved LeetCode Hard 3655 XOR After Range Multiplication Queries II
More Relevant Posts
-
Here’s the fix: The code used different variable names. Fixing that and keeping the print inside the loop makes it run perfectly. #DebuggingSkills #PythonForBeginners #STEMEducation #CodingChallenge #LearnCoding
To view or add a comment, sign in
-
-
🚀 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 🚀
To view or add a comment, sign in
-
-
🚀 LinkedIn Challenge – Day 98 📌 Problem: Edit Distance (LeetCode 72) Today’s problem was a classic Dynamic Programming question. 👉 Given two strings, the goal is to find the minimum number of operations required to convert one string into another. Allowed operations: • Insert a character • Delete a character • Replace a character 💡 Key Insight: This problem is all about breaking it into smaller subproblems. At each step, you decide the minimum cost among: - inserting a character - deleting a character - replacing a character The optimal solution builds up using previous results — a perfect example of DP optimization (space optimized tabulation). 📊 My Result: • Runtime: 47 ms • Memory: 19.22 MB ⚡ Learning Takeaway: Not every problem is about brute force. Recognizing overlapping subproblems and applying DP can drastically reduce complexity. Consistency > Motivation. See you on Day 99. 💯 #Day98 #LeetCode #DataStructures #Algorithms #DynamicProgramming #CodingJourney
To view or add a comment, sign in
-
-
Day 8 🚀 Solved: Diameter of Binary Tree (LeetCode 543) This problem builds directly on tree depth and recursion. The diameter is the length of the longest path between any two nodes. 💡 My approaches: 🔹 Approach 1 (Brute Force): For every node, compute left and right subtree heights Check all possible paths Results in repeated computations 🔹 Approach 2 (Optimal – DFS): Compute height using postorder traversal At each node, update diameter as left_height + right_height Done in a single traversal 💡 Key learning: While calculating height, we can simultaneously track the best diameter instead of recomputing values. ⏱️ Time Complexity: Brute Force → O(n²) Optimal → O(n) 🔗 GitHub: https://lnkd.in/gnVqwUNQ #DSA #LeetCode #Coding
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
-
🚀 Solved a challenging Binary Tree problem – FindElements (Recover Contaminated Tree) on LeetCode! Today I worked on an interesting problem where an entire binary tree was “contaminated” (all values set to -1), and the goal was to reconstruct the original tree structure using given rules and efficiently support search queries. 🔍 Key Learnings & Approach: Recovered the tree using DFS by applying: Left child → 2*x + 1 Right child → 2*x + 2 Designed a recursive solution to restore values starting from root = 0 Implemented a traversal-based search to verify whether a target exists in the tree ⚡ Performance: ✅ All test cases passed (34/34) ⏱ Runtime: 304 ms 💾 Memory Usage: Optimized (better than ~91% submissions) 💡 What made it interesting? This problem is a great example of: Tree reconstruction logic DFS traversal usage Understanding implicit tree properties 📌 Next Improvement Plan: Planning to optimize the find() operation from O(n) to O(1) using hashing (unordered_set) for faster lookups. Consistency in solving DSA problems is really paying off. On to the next challenge! 💪 #DataStructures #Algorithms #BinaryTree #LeetCode #CodingJourney #Cplusplus #DSA #ProblemSolving
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 Challenge 21/50 💡 Approach: Dynamic Programming (Row by Row) Pascal's Triangle is one of the most beautiful patterns in mathematics — and also a perfect introduction to Dynamic Programming! Each row is entirely built from the one above it. 🔍 Key Insight: → First and last element of every row is always 1 → Every middle element = sum of two elements directly above → Build each row using the previously computed row → No formula needed — just pure DP logic! 📈 Complexity: ✅ Time: O(n²) — every cell computed exactly once ✅ Space: O(n²) — storing the full triangle (required for output) Pascal's Triangle isn't just a coding problem — it hides binomial coefficients, Fibonacci numbers, and combinatorics all in one elegant structure! 🔺 #LeetCode #DSA #DynamicProgramming #Java #ADA #PBL2 #LeetCodeChallenge #Day21of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #PascalsTriangle
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
-
-
Day 35/75 🚀 Solved Count Good Nodes in Binary Tree (LeetCode 1448) today! ✅ All 63/63 test cases passed ⚡ Runtime: 91 ms (Beats ~82%) 💾 Memory: 88.34 MB (Beats ~64%) 🔍 Approach: Used DFS (recursion) while tracking the maximum value seen so far on the path. ✔️ Start from root with initial max = root value ✔️ If current node value ≥ max so far → it's a “good node” ✔️ Update max and continue traversal ✔️ Recursively check left and right subtree 💡 Key Learning: Passing state (like max value) in recursion helps solve path-based problems efficiently. No need to store full paths—just keep track of what's important. Consistency + depth thinking = stronger tree skills 🌳🔥 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
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