0% completed
issue with test case [1, 2, 5, 3, 7, 10, 9, 12]
Faraz
Mar 1, 2024
i have dry run it multiple times, iam getting 6 as the size of subarray window? i think visualization of algorithm is misleading , if you dry run the first input based on the visualization of algorithm you get 6 as the size of subarray!
i might be wrong, but i have dry run it twice, what you guys think???
i think the problem is here: while (low > 0 && arr[low - 1] > subarrayMin) { low -= 1; } // extend the subarray to include any number which is smaller than the maximum of // the subarray while (high < arr.length - 1 && arr[high + 1] < subarrayMax) { high += 1; }
While in visualization it compares arr[min] > subarray_min ? then low-- , to insert from beginning
the min and max i found in subarray 👇 min=3 max=10
the first inorder from beginning where low is at index 2, which is 5.
so, the arr[low] > subarray_min: 5 > 3 ? --> low--
so the size of subarray becomes 6!!
0
0
Comments
Shubham Voraa year ago
You found wrong min and max. The value of the min is -1 and max is 3.
On this page