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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Flip a Bit
00:00
5 left

Flip a Bit

EasyPython

Problem

Box services may encode multiple file properties, such as preview availability or synchronization state, inside an integer bit field. Given a non-negative integer and a bit position, toggle the bit at that position and return the resulting integer.

A toggle changes 0 to 1 and 1 to 0. Bit positions are zero-based, so position 0 is the least significant bit.

Formal Specification

Implement flip_bit(value, position).

  • Input: value, a non-negative integer, and position, an integer identifying the bit to toggle.
  • Output: The integer produced after toggling the selected bit.
  • The input integer should be treated using standard binary representation. Do not convert it to a string.

Constraints

  • 0 <= value < 2^31
  • 0 <= position <= 30
  • The result fits within a non-negative 32-bit signed integer
  • Bit positions are zero-based from the least significant bit

Function Signature

def flip_bit(value, position):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.