Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect and Clear Register Bitflags

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

Your question is Detect and Clear Register Bitflags. 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

An AMD Ryzen Embedded peripheral exposes its register states as an array of unsigned 32-bit integers. Given a bitmask of fault flags, scan every register, identify registers containing at least one selected flag, and clear only those selected bits.

Modify the input array in place and return a dictionary containing the updated registers array and the zero-based affected_indices of registers whose selected bits were set. Bits outside the mask must remain unchanged.

Formal Specification

Implement clear_register_flags(registers, mask).

  • registers is a list of nonnegative integers, each representing one 32-bit register value.
  • mask is a nonnegative 32-bit integer. A 1 bit identifies a flag to detect and clear.
  • Return {"registers": registers, "affected_indices": indices} after modifying registers in place.
  • affected_indices must be ordered from smallest to largest index.

Constraints

  • 1 <= len(registers) <= 10^5
  • 0 <= registers[i] < 2^32
  • 0 <= mask < 2^32
  • The input list must be modified in place

Function Signature

def clear_register_flags(registers, mask):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output