Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Lists, Gates, and Interrupts

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

Your question is Python Lists, Gates, and Interrupts. 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

Arm firmware often manipulates compact signal arrays and selects logic paths through multiplexers. Implement a simulator that applies requested swaps to an integer list and evaluates Boolean gates using only a 2:1 MUX abstraction.

Formal Specification

Write process_signals(values, swaps, gates).

  • values is a list of integers.
  • Each swap is [i, j, method], where method is either "temp" or "xor". Swap values[i] and values[j] in place. The "temp" method must use a temporary variable. The "xor" method must swap using XOR without a third variable. Assume i != j.
  • Each gate is [name, a, b], where name is "NOT", "AND", "OR", or "XOR", and a and b are Boolean integers, either 0 or 1. For NOT, ignore b.
  • Model a 2:1 MUX as mux(select, input0, input1), which returns input0 when select == 0 and input1 when select == 1.
  • Construct every gate from MUX calls, rather than using the corresponding Python Boolean operator directly.
  • Return a dictionary with the final list under "values" and gate results, in input order, under "gates".

Constraints

  • 1 <= len(values) <= 10^4
  • 0 <= len(swaps), len(gates) <= 10^4
  • Every swap index is valid and distinct
  • List values fit within signed 32-bit integers
  • Gate inputs are restricted to 0 and 1

Function Signature

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