• Skip to primary navigation
  • Skip to content
  • Skip to footer
Thomas Ngo Thomas Ngo
  • Home
  • Journal
  • Tags
  • About

    Thomas Ngo

    Software Engineer

    • Stanton, California
    • Email
    • GitHub
    • Resume

    Problem of The Day: Smallest Number With All Set Bits

    October 28, 2025 less than 1 minute read

    Problem Statement

    leetcode problem link

    Brute Force [TLE]

    class Solution:
        def smallestNumber(self, n: int) -> int:
            x = n
            res = 0
            while x > 0:
                res = (res << 1) | 1
                x = x >> 1
    
            return res
    

    Editorial

    class Solution:
        def smallestNumber(self, n: int) -> int:
            x = 1
            while x < n:
                x = x * 2 + 1
            return x
    

    Tags: Problem of The Day

    Updated: October 28, 2025

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Problem of The Day: Make Array Elements Equal to Zero

    October 27, 2025 1 minute read

    Problem Statement

    Problem of The Day: Number of Laser Beams in a Bank

    October 26, 2025 less than 1 minute read

    Problem Statement

    Problem of The Day: Simple Bank System

    October 26, 2025 1 minute read

    Problem Statement

    Problem of The Day: Calculate Money in Leetcode Bank

    October 25, 2025 less than 1 minute read

    Problem Statement

    • Follow:
    • GitHub
    • LinkedIn
    © 2025 Thomas Ngo.