Maximum Fixed Point ( Value equal to index ) in a given Array | C # implementation of the above approach ; 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 ; Driver code ; Given Input ; Function Call
using System ; class GFG { static void findLargestIndex ( int [ ] arr , int n ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == i ) { Console . Write ( i ) ; return ; } } Console . Write ( - 1 ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 10 , - 5 , 0 , 3 , 7 } ; int n = arr . Length ; findLargestIndex ( arr , n ) ; } }