Update Logs by Symmetric XOR
Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Salesforce reportedly served this one in March 2026, and it looks scarier than it is. Strip the story and it's a bit-manipulation problem hiding a cycle. You walk indices 0 to n-1 over and over, XORing each element with its mirror, and iterations can hit 10^18. Simulating is dead on arrival. If the OA invite is in your inbox, learn what the pass structure does to the array. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you the solution in real time as a safety net.
The problem
You are given an integer array log of size n and a non-negative integer iterations. The updates are applied sequentially and in-place. For each iteration i from 0 to iterations - 1: Compute index = i mod n. Compute symmetric = n - index - 1. Set log[index] = log[index] XOR log[symmetric], using the current array values at that moment. If index == symmetric, the element is updated to 0 because x XOR x = 0. Return the final array after all iterations are complete. Since iterations can be very large, solutions should reason about the repeated index cycle instead of simulating every iteration one by one. Function updateLogsBySymmetricXor(log: int[], iterations: long) → int[] Examples Example 1 log = [1, 2, 3] iterations = 2 return = [2, 0, 3] Iteration 0 updates index 0: 1 XOR 3 = 2, so the array becomes [2,2,3]. Iteration 1 updates the middle index, where index == symmetric, so 2 XOR 2 = 0. The result is [2,0,3]. Example 2 log = [4, 7, 1, 2] iterations = 5 return = [2, 6, 7, 4] The updates are in-place at indices 0,1,2,3,0. The array changes as [4,7,1,2] -> [6,7,1,2] -> [6,6,1,2] -> [6,6,7,2] -> [6,6,7,4] -> [2,6,7,4]. Constraints 1 <= log.length <= 2 * 10^5 0 <= log[i] <= 10^9 0 <= iterations <= 10^18
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: iterations is huge, but the process is periodic in passes of n steps. Do the math on one full pass. For index i in the first half, log[i] becomes log[i] XOR log[n-1-i]. Then the mirror index j = n-1-i is processed later, using the already updated log[i], so log[j] becomes log[j] XOR log[i] XOR log[j], which equals the original log[i]. The middle element of an odd n becomes 0. After one pass the pairs are swapped in effect, with the first half holding XORs. Run a second pass and the state follows a short cycle, so you only need a small number of full passes plus a partial pass. Compute full = iterations / n, rem = iterations mod n, simulate a reduced number of passes, then simulate rem steps. The pitfall is using the original values instead of the current in-place ones, and overflow on iterations, so use a 64-bit type. If the cycle derivation slips under pressure, StealthCoder is the hedge. Verify against Example 2 first.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Update Logs by Symmetric XOR cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Salesforce's OA.
Salesforce reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Update Logs by Symmetric XOR FAQ
What's the trick in Update Logs by Symmetric XOR?+
Don't simulate 10^18 steps. The index sequence repeats every n steps, and the array state repeats after a small number of full passes. Reduce iterations to a few passes plus a remainder, then simulate only that. Work out one pass by hand to see the pattern.
How hard is this Salesforce OA question really?+
Medium. The code is short, but the insight is the hard part. If you try brute force you'll time out on large iterations. Once you see that passes become periodic, the implementation is a couple of simple loops over an array of up to 2 * 10^5 elements.
What happens at the middle index when n is odd?+
When index equals symmetric, the element XORs with itself and becomes 0. Example 1 shows this: the middle value 2 turns into 0. Handle it naturally, since x XOR x is 0, but remember later passes will keep it consistent with the in-place values.
Why do I need a 64-bit integer?+
Iterations goes up to 10^18, which overflows a 32-bit int. Use long in Java or C++ long long, and Python is fine. Compute iterations divided by n and iterations mod n in 64-bit, then cast the small remainder down for looping.
How do I prepare for this in 48 hours?+
Hand-trace Example 2 and write the array after each step. Then trace a full second pass and spot where the state repeats. Practice in-place XOR updates and the mod-cycle reduction idea. Test odd and even n, plus iterations of 0, before you submit.