Check if an Array is a permutation of numbers from 1 to N : Set 2 | Java program to decide if an array represents a permutation or not ; Function to check if an array represents a permutation or not ; Counting the frequency ; Check if each frequency is 1 only ; Driver code
class GFG { static String permutation ( int arr [ ] , int N ) { int [ ] hash = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { hash [ arr [ i ] ] ++ ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( hash [ i ] != 1 ) return " No " ; } return " Yes " ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 5 , 5 , 3 } ; int n = arr . length ; System . out . print ( permutation ( arr , n ) + "NEW_LINE"); } }