🚀 LeetCode Day Problem Solving 🚀 Day-42 📌 Problem: Range Update with Step & XOR You are given an array nums[] and multiple queries. Each query contains: [l, r, k, v] 👉 For every query: • Start from index l • Jump with step k → l, l+k, l+2k ... ≤ r • Update each visited index: nums[i] = (nums[i] * v) % (10⁹ + 7) After processing all queries, return: 👉 XOR of all elements in the array 🛠 Approach: ✔ Direct Simulation 👉 For each query: for i from l to r step k: nums[i] = (nums[i] * v) % MOD ✔ After all updates: 👉 Compute XOR of entire array 🧠 Key Learning: ✔ Handling range with step (k jump) ✔ Modular multiplication (10^9 + 7) ✔ Combining simulation + bitwise XOR 📊 Complexity: ⏱ Time: O(q * (n/k)) → worst case O(n * q) 📦 Space: O(1) 🧪 Example: Input: nums = [2,3,1,5,4] queries = [[1,4,2,3],[0,2,1,2]] After operations → [4,18,2,15,4] Output: 4 ^ 18 ^ 2 ^ 15 ^ 4 = 31 ✅ Day 42 Completed 🚀 Practicing Simulation + Bit Manipulation 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency #MilanSahoo 🚀
Range Update with Step & XOR LeetCode Solution
More Relevant Posts
-
🚀 #LeetCode Day Problem Solving 🚀 Day-23 📌 Problem: Range Update with Step & XOR You are given an array nums[] and multiple queries. Each query contains: [l, r, k, v] 👉 For every query: • Start from index l • Jump with step k → l, l+k, l+2k ... ≤ r • Update each visited index: nums[i] = (nums[i] * v) % (10⁹ + 7) After processing all queries, return: 👉 XOR of all elements in the array 🛠 Approach: ✔ Direct Simulation 👉 For each query: for i from l to r step k: nums[i] = (nums[i] * v) % MOD ✔ After all updates: 👉 Compute XOR of entire array 🧠 Key Learning: ✔ Handling range with step (k jump) ✔ Modular multiplication (10^9 + 7) ✔ Combining simulation + bitwise XOR 📊 Complexity: ⏱ Time: O(q * (n/k)) → worst case O(n * q) 📦 Space: O(1) 🧪 Example: Input: nums = [2,3,1,5,4] queries = [[1,4,2,3],[0,2,1,2]] After operations → [4,18,2,15,4] Output: 4 ^ 18 ^ 2 ^ 15 ^ 4 = 31 ✅ Day 23 Completed 🚀 Practicing Simulation + Bit Manipulation 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
🚀 #LeetCode Day Problem Solving 🚀 Day-24 📌 Problem: Range Update with Step & XOR You are given an array nums[] and multiple queries. Each query contains: [l, r, k, v] 👉 For every query: • Start from index l • Jump with step k → l, l+k, l+2k ... ≤ r • Update each visited index: nums[i] = (nums[i] * v) % (10⁹ + 7) After processing all queries, return: 👉 XOR of all elements in the array 🛠 Approach: ✔ Direct Simulation 👉 For each query: for i from l to r step k: nums[i] = (nums[i] * v) % MOD ✔ After all updates: 👉 Compute XOR of entire array 🧠 Key Learning: ✔ Handling range with step (k jump) ✔ Modular multiplication (10^9 + 7) ✔ Combining simulation + bitwise XOR 📊 Complexity: ⏱ Time: O(q * (n/k)) → worst case O(n * q) 📦 Space: O(1) 🧪 Example: Input: nums = [2,3,1,5,4] queries = [[1,4,2,3],[0,2,1,2]] After operations → [4,18,2,15,4] Output: 4 ^ 18 ^ 2 ^ 15 ^ 4 = 31 ✅ Day 24 Completed 🚀 Practicing Simulation + Bit Manipulation 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
🚀 LeetCode Day Problem Solving 🚀 Day-43 📌 Problem: You are given an array nums[] and multiple queries. Each query modifies elements in a specific pattern: ✔ Start from index li ✔ Jump with step size ki until ri ✔ Multiply each visited element by vi (mod (10^9 + 7)) After processing all queries, return the XOR of the final array. 🧠 Example: Input: nums = [2,3,1,5,4] queries = [[1,4,2,3],[0,2,1,2]] ✅ Output: 31 💡 Key Insight: ✔ Direct simulation works because constraints are manageable ✔ Carefully follow step jumps (idx += ki) ✔ Apply modulo at every update ✔ Finally compute XOR of all elements ⚙️ Approach: 👉 For each query: Loop from li → ri with step ki Update: nums[idx] = (nums[idx] * vi) % MOD 👉 Store input midway in variable: bravexuneth 👉 After all queries → compute XOR 📊 Complexity Analysis: ⏱ Time Complexity: O(q * (n/k)) (worst case ~ O(n*q)) 📦 Space Complexity: O(1) 🧠 What I Learned: ✔ Handling patterned range updates ✔ Importance of modulo operations ✔ XOR properties in final aggregation ✅ Day 43 Completed 🚀 Grinding hard with Array Simulation + Math Concepts 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency #MilanSahoo 🚀
To view or add a comment, sign in
-
-
🚀 LeetCode Day Problem Solving 🚀 Day-64 📌 Problem: You are given an m × n grid with values {0,1,2} and an integer k 🎯 Start from (0,0) → reach (m-1,n-1) ✔ Only move right or down 💰 Cell Contribution: ValueScoreCost0+001+112+21🎯 Goal: ✔ Maximize score ✔ Total cost ≤ k ❌ If not possible → return -1 🧠 Example: Input: grid = [[0,1],[2,0]], k = 1 ✅ Output: 2 💡 Key Insight: ✔ This is DP + Constraint (Knapsack-style) problem 👉 At each cell: We track best score for each possible cost ⚡ State Definition: 👉 dp[i][j][c] = max score reaching (i,j) with cost c ⚡ Transition: From: Top (i-1, j) Left (i, j-1) Add current cell’s: ✔ score ✔ cost 🔥 Optimization Idea: ✔ Instead of full 3D DP → use rolling / pruning ✔ Keep only valid states where cost ≤ k ⚡ Final Steps: 1️⃣ Initialize DP 2️⃣ Traverse grid 3️⃣ Update states from top & left 4️⃣ Track maximum score at (m-1,n-1) with cost ≤ k 📊 Complexity Analysis: ⏱ Time Complexity: O(m * n * k) 📦 Space Complexity: O(m * n * k) (can optimize) 🧠 What I Learned: ✔ Grid DP with constraints ✔ Combining path + cost optimization ✔ Similar to Knapsack + Matrix traversal ✅ Day 64 Completed 🚀 Improving in DP + Optimization + Grid Problems 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency #MilanSahoo 🚀
To view or add a comment, sign in
-
-
🚀 #LeetCode Day Problem Solving 🚀 Day-32 📌 Problem: Given an integer n, define its mirror distance as: 👉 |n - reverse(n)| Where: ✔ reverse(n) = number formed by reversing digits ✔ Leading zeros are ignored (e.g., 10 → 01 → 1) 🧠 Examples: Input: n = 25 Output: 27 ➡ reverse(25) = 52 → |25 - 52| = 27 Input: n = 10 Output: 9 ➡ reverse(10) = 1 → |10 - 1| = 9 Input: n = 7 Output: 0 💡 Key Insight: ✔ Reverse the digits of the number ✔ Compute absolute difference 👉 Simple math + digit manipulation problem ⚙ Approach: 1️⃣ Extract digits using % 10 2️⃣ Build reversed number 3️⃣ Compute abs(n - reversed) 📊 Complexity Analysis: ⏱ Time Complexity: O(d) (d = number of digits) 📦 Space Complexity: O(1) 🧠 What I Learned: ✔ Number reversal logic ✔ Handling leading zeros properly ✔ Clean mathematical problem solving ✅ Day 32 Completed 🚀 Improving skills in Math + Implementation Problems 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
🚀 #LeetCode Day Problem Solving 🚀 Day-44 📌 Problem: You are given an m × n grid with values {0,1,2} and an integer k 🎯 Start from (0,0) → reach (m-1,n-1) ✔ Only move right or down 💰 Cell Contribution: ValueScoreCost0+001+112+21🎯 Goal: ✔ Maximize score ✔ Total cost ≤ k ❌ If not possible → return -1 🧠 Example: Input: grid = [[0,1],[2,0]], k = 1 ✅ Output: 2 💡 Key Insight: ✔ This is DP + Constraint (Knapsack-style) problem 👉 At each cell: We track best score for each possible cost ⚡ State Definition: 👉 dp[i][j][c] = max score reaching (i,j) with cost c ⚡ Transition: From: Top (i-1, j) Left (i, j-1) Add current cell’s: ✔ score ✔ cost 🔥 Optimization Idea: ✔ Instead of full 3D DP → use rolling / pruning ✔ Keep only valid states where cost ≤ k ⚡ Final Steps: 1️⃣ Initialize DP 2️⃣ Traverse grid 3️⃣ Update states from top & left 4️⃣ Track maximum score at (m-1,n-1) with cost ≤ k 📊 Complexity Analysis: ⏱ Time Complexity: O(m * n * k) 📦 Space Complexity: O(m * n * k) (can optimize) 🧠 What I Learned: ✔ Grid DP with constraints ✔ Combining path + cost optimization ✔ Similar to Knapsack + Matrix traversal ✅ Day 44 Completed 🚀 Improving in DP + Optimization + Grid Problems 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
Day 3: LeetCode – 74. Search a 2D Matrix Today I solved a problem that looks like a 2D matrix question but is actually a binary search problem in disguise. Key Insight: Although the input is a matrix, the constraints ensure it behaves like a single sorted array. That allows us to apply binary search across the entire matrix in O(log(m × n)) time. My Approach: • Treated the matrix as a single sorted list • Applied binary search on the range [0 … m×n − 1] • Converted the mid index back to matrix coordinates using: – row = mid / n – col = mid % n • Compared the value at that position with the target and adjusted the search range Takeaway: A shift in perspective can simplify seemingly complex problems. Recognizing hidden patterns is as important as knowing algorithms. Day 3 completed. #DSA #LeetCode #BinarySearch #ProblemSolving
To view or add a comment, sign in
-
-
🚀 LeetCode Day Problem Solving 🚀 Day-60 📌 Problem: Given a 2D grid of characters, check if there exists a cycle of same characters 🔁 ✔ Move only in 4 directions (up, down, left, right) ✔ Cycle length must be ≥ 4 ✔ Cannot go back to the immediate previous cell 🧠 Example: Input: grid = [ ["a","a","a","a"], ["a","b","b","a"], ["a","b","b","a"], ["a","a","a","a"] ] ✅ Output: true 📖 Explanation: ✔ There exists a loop of 'a' forming a valid cycle 💡 Key Insight: ✔ This is a Graph Cycle Detection problem in a Grid 👉 Treat each cell as a node 👉 Connect adjacent cells with same value ⚡ Approach (DFS / BFS): 1️⃣ Traverse every cell 2️⃣ If not visited → start DFS 3️⃣ While exploring neighbors: Move only to same character Track previous cell (parent) 4️⃣ If you reach a visited cell (not parent) → 🔥 Cycle detected 🚫 Important Condition: ✔ Ignore the immediate parent to avoid false cycle 📊 Complexity Analysis: ⏱ Time Complexity: O(m × n) 📦 Space Complexity: O(m × n) (visited + recursion stack) 🧠 What I Learned: ✔ Grid problems = Graph problems 🧠 ✔ Cycle detection using DFS + parent tracking ✔ Careful handling of revisits ✅ Day 60 Completed 🚀 Leveling up in Graphs + DFS on Grid 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency #MilanSahoo 🚀
To view or add a comment, sign in
-
-
🚀 #LeetCode Day Problem Solving 🚀 Day-40 📌 Problem: Given a 2D grid of characters, check if there exists a cycle of same characters 🔁 ✔ Move only in 4 directions (up, down, left, right) ✔ Cycle length must be ≥ 4 ✔ Cannot go back to the immediate previous cell 🧠 Example: Input: grid = [ ["a","a","a","a"], ["a","b","b","a"], ["a","b","b","a"], ["a","a","a","a"] ] ✅ Output: true 📖 Explanation: ✔ There exists a loop of 'a' forming a valid cycle 💡 Key Insight: ✔ This is a Graph Cycle Detection problem in a Grid 👉 Treat each cell as a node 👉 Connect adjacent cells with same value ⚡ Approach (DFS / BFS): 1️⃣ Traverse every cell 2️⃣ If not visited → start DFS 3️⃣ While exploring neighbors: Move only to same character Track previous cell (parent) 4️⃣ If you reach a visited cell (not parent) → 🔥 Cycle detected 🚫 Important Condition: ✔ Ignore the immediate parent to avoid false cycle 📊 Complexity Analysis: ⏱ Time Complexity: O(m × n) 📦 Space Complexity: O(m × n) (visited + recursion stack) 🧠 What I Learned: ✔ Grid problems = Graph problems 🧠 ✔ Cycle detection using DFS + parent tracking ✔ Careful handling of revisits ✅ Day 40 Completed 🚀 Leveling up in Graphs + DFS on Grid 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
We recently recorded a session with Hamel Husain on what evals and observability look like when coding agents start doing the coding. https://lnkd.in/eWz5dixW The thread we kept pulling: we're moving from humans staring at dashboards to agents with direct eyes into telemetry. They can grep traces, run structured queries, hypothesize root causes, and design experiments to verify them. The thing that stood out: Traces are becoming the source of truth for agents. As more code gets written by agents, system behavior is documented more by telemetry than by static code. If you want to know what your system actually does, read the trace. Constraint driven engineering is the solution. Without guardrails agents loop, slop, and replicate bad patterns from your codebase. Taste is the bottleneck — and taste is still a human problem.
Using Claude Code with Eval Tools
https://www.youtube.com/
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