Maximum Recursion Depth
Consider the following MaxDepth class. What is the maximum recursion depth when the main method is executed?
public class MaxDepth {
public static int process(int[] arr, int low, int high) {
if(low >= high) return 1;
int mid = (low + high) / 2;
int left = process(arr, low, mid);
int right = process(arr, mid+1, high);
return Math.max(left, right) + 1;
}
public static void main(String[] args) {
int[] data = new int[16];
System.out.println(process(data, 0, data.length - 1));
}
}
A
16
B
4
C
5
D
6
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | mtanarupi | 2 | 2 | 0m 00s | 200 |
| #2 | songqiuhui2012 | 1 | 1 | 0m 35s | 65 |
| #3 | ethan | 0 | 1 | 0m 00s | -10 |
| #4 | psak12 | 1 | 2 | 2m 18s | -48 |
| #5 | suhanakochhar006 | 3 | 4 | 6m 12s | -82 |
| #6 | ravi.palepu | 0 | 1 | 1m 16s | -86 |
| #7 | singhris000 | 0 | 2 | 5m 55s | -375 |
APFIVE