XOR the Arithmetic-Step Array

Quick Overview

XOR the Arithmetic-Step Array. Define n values nums[i]=start+2*i for zero-based indices0..n-1. Return their bitwise XOR.

XOR the Arithmetic-Step Array

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Define n values nums[i]=start+2*i for zero-based indices 0..n-1. Return their bitwise XOR. ```cpp class Solution { public: int xorOperation(int n, int start); }; ``` ### Examples **Example 1:** ```text Input: n = 3, start = 2 Output: 0 Explanation: The values are2,4,6,and2 XOR4 XOR6 is0. ``` **Example 2:** ```text Input: n = 1, start = 9 Output: 9 Explanation: The single value is9. ``` ### Constraints - `1 <= n <= 1000` and `0 <= start <= 1000`. - The defined array has length n. ### Contract considerations The array is defined implicitly; materializing it is optional. ```hint Read the boundary condition Check the first and last generated terms and a zero starting value. The requested operation is bitwise XOR. ``` ### Boundary reminders The array is defined implicitly; materializing it is optional.

Overview: XOR the Arithmetic-Step Array. Define n values nums[i]=start+2*i for zero-based indices0..n-1. Return their bitwise XOR.

Amazon logo
Amazon
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Define n values nums[i]=start+2*i for zero-based indices 0..n-1. Return their bitwise XOR.

class Solution {
public:
    int xorOperation(int n, int start);
};

Examples

Example 1:

Input: n = 3, start = 2
Output: 0
Explanation: The values are2,4,6,and2 XOR4 XOR6 is0.

Example 2:

Input: n = 1, start = 9
Output: 9
Explanation: The single value is9.

Constraints

  • 1 <= n <= 1000 and 0 <= start <= 1000 .
  • The defined array has length n.

Contract considerations

The array is defined implicitly; materializing it is optional.

Boundary reminders

The array is defined implicitly; materializing it is optional.