JS/TS | Base Conversion | Efficient
Intuition\nThe problem seems unusual at first glance but it actually translates into a mathematical problem involving base conversion. We are essentially trying
# Intuition\nThe problem seems unusual at first glance but it actually translates into a mathematical problem involving base conversion. We are essentially trying to represent the number of buckets ($b$) in a different base ($rounds$), where each "digit" in this number system corresponds to a pig. The base of this number system is determined by the number of states a single pig can be in, given the testing duration and the latency period for the poison to take effect.\n\n# Approach\n1. Calculate the total number of states a single pig can be in ($rounds$), which is $(testDur / latency) + 1$.\n2. Initialize a counter ($n$) for the number of pigs needed.\n3. Run a while loop to find the minimum $n$ such that $rounds^n >= b$.\n\n# Complexity\n- **Time complexity**: $O(\\log_{rounds} b)$\nWe are using a while loop to find the minimum $n$ where $rounds^n >= b$.\n\n- **Space complexity**: $O(1)$\nWe\'re only using constant extra space.\n\n# Code\n```\nfunction poorPigs(b: number, latency: number, testDur: number): number {\n    // Total states one pig can be in\n    let rounds: number = testDur / latency + 1, n = 0\n    // Find min n where rounds^n >= b\n    while (rounds ** n < b) n++\n    return n\n}\n\n```
['Math', 'TypeScript', 'JavaScript']