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

Question

A graphics engine requires every texture dimension to be an exact power of two (1, 2, 4, 8, 16, ...). Given an integer n (which may be zero or negative), return true if n is a power of two and false otherwise. Solve it with bit operations rather than a loop of divisions: a power of two has exactly one set bit in its binary representation. For example, 16 returns true and 24 returns false.

Implement
is_power_of_two(n: int) → bool
Examples
in[16]outtrue
in[24]outfalse
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.