Given a string describing a code pattern, return its Big O time complexity as a string.
The possible inputs and their expected outputs are:
| Input | Output | Why |
|-------|--------|-----|
| "constant" | "O(1)" | Direct access, no loops |
| "logarithmic" | "O(log n)" | Halving/doubling pattern |
| "linear" | "O(n)" | Single loop over input |
| "linearithmic" | "O(n log n)" | Sorting, then processing |
| "quadratic" | "O(n^2)" | Two nested loops over input |
| "exponential" | "O(2^n)" | Generating all subsets |
This problem reinforces the Big O hierarchy through pattern matching.
pattern = "linear""O(n)"pattern = "quadratic""O(n^2)"pattern = "constant""O(1)"pattern is one of: "constant", "logarithmic", "linear", "linearithmic", "quadratic", "exponential"Run your code to see results
Use Cmd+Enter to run