Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
3 XOR 2 Mod 5
00:00
5 left

3 XOR 2 Mod 5

MediumPython

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):
Interviewer

Your question is 3 XOR 2 Mod 5. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.