3821. Find Nth Smallest Integer With K One Bits Hard
1/**
2 * [3821] Find Nth Smallest Integer With K One Bits
3 *
4 * You are given two positive integers n and k.
5 * Return an integer denoting the n^th smallest positive integer that has exactly k ones in its binary representation. It is guaranteed that the answer is strictly less than 2^50.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">n = 4, k = 2</span>
10 * Output: <span class="example-io">9</span>
11 * Explanation:
12 * The 4 smallest positive integers that have exactly k = 2 ones in their binary representations are:
13 *
14 * 3 = 112
15 * 5 = 1012
16 * 6 = 1102
17 * 9 = 10012
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">n = 3, k = 1</span>
22 * Output: <span class="example-io">4</span>
23 * Explanation:
24 * The 3 smallest positive integers that have exactly k = 1 one in their binary representations are:
25 *
26 * 1 = 12
27 * 2 = 102
28 * 4 = 1002
29 * </div>
30 *
31 * Constraints:
32 *
33 * 1 <= n <= 2^50
34 * 1 <= k <= 50
35 * The answer is strictly less than 2^50.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/find-nth-smallest-integer-with-k-one-bits/
41// discuss: https://leetcode.com/problems/find-nth-smallest-integer-with-k-one-bits/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn nth_smallest(n: i64, k: i32) -> i64 {
47
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3821() {
59 }
60}
61Back
© 2026 bowen.ge All Rights Reserved.