Bug Report for https://neetcode.io/problems/replace-elements-with-greatest-element-on-right-side
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
For solution 2. Suffix Max:
What about the situation when last element of input array is smaller than -1:
For example if input array is:
arr =[2, 4, 5, 3, 1, -2]
expected output array would be:
arr =[5,5,3,1,-2,-1]
but actually output will be:
[5,5,3,1,-1,-1]
since in the first iteration of the loop when comparing values in max function, function gives back -1 instead of -2, because -2 was compared to artificial -1 value which was not initially in the input array but was initialized as first max value.
Instead, we should assign -1 value at the last place in ans array after for loop.
