AND Gate with Multiplexers
Problem statement
Build an AND gate using multiplexers and evaluate it for every input pair in inputs. Each row is [a,b], with both values either0 or1. Return the resulting bit for each row in the same order.
For this practice, use a two-input multiplexer mux(s,d0,d1): it returns d0 when s=0, otherwise d1. Compose the gate only from this primitive, wires and constants0 and1. You may implement the primitive with a conditional; do not replace the circuit with direct logical or bitwise gate operators or an arithmetic shortcut.
The automated tests check the truth-table behavior. The construction restriction is an implementation requirement explained by the reference circuits; this software exercise does not compile HDL or audit a synthesized gate netlist.
Function
andWithMux(inputs: int[][]) → int[]Examples
Example 1
inputs = [[0,0],[0,1],[1,0],[1,1]]return = [0,0,0,1]The AND truth table in order00,01,10,11 is 0,0,0,1.
Example 2
inputs = []return = []There are no input pairs, so return an empty array.
Example 3
inputs = [[1,0],[1,1],[0,1]]return = [0,1,0]Evaluate each pair independently, preserving the input order.
Constraints
0 <= inputs.length <= 10000.Every row has exactly 2 entries.Every entry is an integer from 0 to 1.