• 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: Letter Combinations of a Phone Number

    January 23, 2026 2 minute read

    Problem Statement

    Problem of The Day: Find Peak Element

    January 20, 2026 less than 1 minute read

    Problem Statement

    Problem of The Day: Successful Pairs of Spells and Potions

    January 15, 2026 1 minute read

    Problem Statement

    Problem of The Day: Total Cost to Hire K Workers

    January 15, 2026 less than 1 minute read

    Problem Statement

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