Recursive Method Time Complexity
What is the worst-case time complexity of the tail-recursive tailSum method shown below?
public int tailSum(int[] arr, int index, int acc) {
if(index == arr.length) return acc;
return tailSum(arr, index + 1, acc + arr[index]);
}
A
O(n)
B
O(log n)
C
O(n^2)
D
O(1)
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | singhris000 | 1 | 1 | 0m 23s | 77 |
| #2 | ethan | 1 | 3 | 1m 52s | -32 |
| #3 | suhanakochhar006 | 1 | 4 | 6m 22s | -312 |
| #4 | richa.tuli | 1 | 2 | 9m 10s | -460 |
APFIVE