Maximum Fixed Point ( Value equal to index ) in a given Array | Function to find the maximum index i such that arr [ i ] is equal to i ; Traversing the array from backwards ; If arr [ i ] is equal to i ; If there is no such index ; Given Input ; Function Call
function findLargestIndex ( arr , n ) { for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == i ) { document . write ( i ) ; return ; } } document . write ( - 1 ) ; } var arr = [ - 10 , - 5 , 0 , 3 , 7 ] ; var n = arr . length ; findLargestIndex ( arr , n ) ;