Code Room
CodingEasycod-g1497
Subject Bit manipulationLevel Entry–Mid~10 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.