Given an integer n and a string pattern describing a loop structure, return the total number of iterations that pattern would execute.
The patterns are:
"single" — A single for loop from 0 to n-1: n iterations"nested" — Two nested for loops, each from 0 to n-1: n² iterations"half" — A loop that starts at n and halves each step until reaching 0: the number of times you can halve n before it reaches 0 (i.e., floor(log₂(n)) + 1 for n > 0, or 0 if n = 0)This problem tests your understanding of how loop structures map to Big O complexity.
n = 5, pattern = "single"5n = 4, pattern = "nested"16n = 8, pattern = "half"40 <= n <= 10^9pattern is one of "single", "nested", or "half"Run your code to see results
Use Cmd+Enter to run