Largest number in the Array having frequency same as value | C # solution to the above problem ; Function to find the largest number whose frequency is equal to itself . ; Find the maximum element in the array ; Driver code
using System ; using System . Linq ; class GFG { static int findLargestNumber ( int [ ] arr ) { int k = arr . Max ( ) ; int [ ] m = new int [ k + 1 ] ; foreach ( int n in arr ) ++ m [ n ] ; for ( int n = arr . Length - 1 ; n > 0 ; -- n ) { if ( n == m [ n ] ) return n ; } return - 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 5 , 2 , 4 , 5 } ; Console . Write ( findLargestNumber ( arr ) + " STRNEWLINE " ) ; } }