Search
⌘K

Leetcode 3007. Maximum Number That Sum of the Prices Is Less Than or Equal to K

Given k and x, define price(num) as the count of 1-bits in num at bit positions x, 2x, 3x, ... (LSB = position 1); the accumulated price up to N is the sum of price(i) for i=1..N. Return the largest N whose accumulated price ≤ k — the core challenge is efficiently computing these cumulative bit counts for large k (≤1e15) by exploiting the periodicity of bit patterns (x ≤ 8).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.