FastPrepUpdate Logs by Symmetric XOR
Problems/Update Logs by Symmetric XOR

Update Logs by Symmetric XOR

Salesforce logoSalesforceFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

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:

  1. Compute index = i mod n.
  2. Compute symmetric = n - index - 1.
  3. 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 = 2return = [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 = 5return = [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

More Salesforce problems

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int[] updateLogsBySymmetricXor(int[] log, long iterations) {
      // write your code here
    }
}
Checking account…