Range Update with Step & XOR LeetCode Solution

🚀 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 🚀

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories