Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

3 XOR 2 Mod 5

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is 3 XOR 2 Mod 5. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Wealthfront's Portfolio dashboard receives integer event codes for account activity. For each inclusive range query, compute the bitwise XOR of the event codes in that range, then return the result modulo modulus.

The operation order is explicitly (XOR of the range) % modulus. For example, 3 XOR 2 % 5 means (3 XOR 2) % 5 = 1.

Formal Specification

Implement xor_range_modulo(values, queries, modulus).

  • values is a list of nonnegative integers.
  • queries is a list of two-element lists [left, right], using zero-based inclusive indices.
  • modulus is a positive integer.
  • For each query, return (values[left] XOR values[left + 1] XOR ... XOR values[right]) % modulus.
  • Return the answers in the same order as the queries.

Constraints

  • 1 <= len(values) <= 100,000
  • 1 <= len(queries) <= 100,000
  • 0 <= values[i] < 2^31
  • 0 <= left <= right < len(values)
  • 1 <= modulus <= 10^9

Function Signature

def xor_range_modulo(values, queries, modulus):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output