Problem

Update Logs by Symmetric XOR

FULLTIMEOA
See Salesforce online assessment and hiring insights

You are given an integer array log of size n and an integer iterations.

For each iteration i from 0 to iterations - 1, compute index = i mod n. Let symmetric = n - index - 1. Update log[index] to log[index] XOR log[symmetric].

Return the final array after all iterations are complete.

Examples
01 · Example 1
log = [1, 2, 3]
iterations = 2
return = [2, 0, 3]

Iteration 0 updates index 0: 1 XOR 3 = 2. Iteration 1 updates the middle index: 2 XOR 2 = 0.

02 · Example 2
log = [4, 7, 1, 2]
iterations = 5
return = [2, 6, 7, 4]

Applying the five updates at indices 0,1,2,3,0 produces [2,6,7,4].

Constraints
  • 1 <= log.length
  • 0 <= iterations
More Salesforce problems
drafts saved locally
public int[] updateLogsBySymmetricXor(int[] log, long iterations) {
  // write your code here
}
log[1, 2, 3]
iterations2
expected[2, 0, 3]
sign in to submit