• 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: Maximum Score from Performing Multiplication Operations

    February 10, 2026 2 minute read

    Problem Statement

    Problem of The Day: Delete and Earn

    February 9, 2026 1 minute read

    Problem Statement

    Problem of The Day: Online Stock Span

    February 8, 2026 less than 1 minute read

    Problem Statement

    Problem of The Day: Daily Temperatures

    February 8, 2026 less than 1 minute read

    Problem Statement

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