PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's understanding of frequency analysis and space-efficient algorithm design for identifying the uniquely odd-occurring value in an array.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find odd-frequency element with O(1) space

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You're given an integer array where exactly one value appears an odd number of times and all other values appear an even number of times. Implement a function that returns the odd-frequency value. Follow-ups: a) Reduce extra space to O( 1). b) Analyze time and space complexity. c) Explain correctness for large inputs and negative integers.

Quick Answer: This question evaluates a candidate's understanding of frequency analysis and space-efficient algorithm design for identifying the uniquely odd-occurring value in an array.

You are given a non-empty integer array nums. Exactly one distinct value appears an odd number of times, and every other distinct value appears an even number of times. Return the value that appears an odd number of times. Your solution should use O(1) extra space and should work for large inputs and negative integers.

Constraints

  • 1 <= len(nums) <= 1000000
  • -1000000000 <= nums[i] <= 1000000000
  • Exactly one distinct value in nums appears an odd number of times
  • All other distinct values appear an even number of times

Examples

Input: ([2, 3, 2, 4, 4],)

Expected Output: 3

Explanation: 2 appears twice and 4 appears twice, while 3 appears once, so 3 is the odd-frequency value.

Input: ([7],)

Expected Output: 7

Explanation: The single element appears once, which is odd.

Input: ([-1, 2, -1, 2, -1],)

Expected Output: -1

Explanation: 2 appears twice, while -1 appears three times. Negative integers work because XOR cancellation still applies.

Input: ([0, 5, 0, 5, 0],)

Expected Output: 0

Explanation: 5 appears twice, while 0 appears three times, so the answer is 0.

Input: ([10, 14, 10, 14, 14, 10, 10],)

Expected Output: 14

Explanation: 10 appears four times, while 14 appears three times.

Hints

  1. Think about an operation where combining a value with itself cancels it out.
  2. The bitwise XOR operation has useful properties: x ^ x = 0 and x ^ 0 = x.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)