You are viewing a single comment's thread. Return to all comments →
Let's consider a test case
let the original matrix be
1 1 1 1 1 5 4 1 1 1 1 1 1 1 1 1
In this case, your program will mark 5 to -1, as all the surrounding elements are smaller than 5.
1 1 1 1 1 -1 4 1 1 1 1 1 1 1 1 1
But now in the next iteration for 4, all the surrounding elements (including -1) are smaller than 4, so it will mark 4 as -1 as well.
it will print output as
1 1 1 1 1 x x 1 1 1 1 1 1 1 1 1
But it should have printed
1 1 1 1 1 x 1 1 1 1 1 1 1 1 1 1
I faced the same problem. So I changed -1 to Integer.MAX_INT.
Let me know if you need more help. All the best.
Seems like cookies are disabled on this browser, please enable them to open this website
Cavity Map
You are viewing a single comment's thread. Return to all comments →
Let's consider a test case
let the original matrix be
In this case, your program will mark 5 to -1, as all the surrounding elements are smaller than 5.
But now in the next iteration for 4, all the surrounding elements (including -1) are smaller than 4, so it will mark 4 as -1 as well.
it will print output as
But it should have printed
I faced the same problem. So I changed -1 to Integer.MAX_INT.
Let me know if you need more help. All the best.