Code RoomExtract lowest bits
EasyPrep Room Coding #701

Extract lowest bits

CodingAlgorithms & data structuresEntry–Mid~10 min

A device packs several fields into one non-negative integer, and the lowest k bits hold a rolling counter. Given the packed value n (0 <= n < 2^31) and a width k (0 <= k <= 30), return the counter: the integer formed by the lowest k bits of n. When k is 0 the counter is empty, so return 0. For example, n = 173 (binary 10101101) with k = 4 returns 13 (binary 1101).

Implement
low_bits_value(n: int, k: int) → int
Examples
in[173,4]out13
in[37,5]out5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 10 min
InputExpectedGot
[173,4]13not run yetsample
[37,5]5not run yetsample