• 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 Level Sum of a Binary Tree

    December 25, 2025 1 minute read

    Problem Statement

    Problem of The Day: Longest ZigZag Path in a Binary Tree

    December 25, 2025 1 minute read

    Problem Statement

    Problem of The Day: Longest ZigZag Path in a Binary Tree

    December 25, 2025 less than 1 minute read

    Problem Statement

    Problem of The Day: Leaf-Similar Trees

    December 21, 2025 1 minute read

    Problem Statement

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