Skip to content

Practice Smallest Number With All Set Bits

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3370
LeetCode Problem

Smallest Number With All Set Bits

Problem Statement

You are given a positive number n. Return the smallest number x greater than or equal to n, such that the binary representation of x contains only set bits

Source: Smallest Number With All Set Bits on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5
Output
7

# Example 2

Input
n = 10
Output
15

# Example 3

Input
n = 3
Output
3

Constraints

1 <= n <= 1000

Related LeetCode Problems

Practice more problems similar to Smallest Number With All Set Bits.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.