Why is the brute-force approach less ideal here?
Practice this question from Number of 1 Bits - Brian Kernighan Pattern Practice Quiz, with options and an explanation.
Question
Why is the brute-force approach less ideal here?
Option A — Correct answer
Checking every bit position does unnecessary work for sparse numbers.
Option B
It always uses less memory
Option C
It avoids all edge cases
Option D
It does not read the input
Explanation
Checking every bit position does unnecessary work for sparse numbers.