Check if the given Prufer sequence is valid or not | C # implementation of the approach ; Function that returns true if given Prufer sequence is valid ; Iterate in the Prufer sequence ; If out of range ; Driver code
using System ; class GFG { static Boolean isValidSeq ( int [ ] a , int n ) { int nodes = n + 2 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] < 1 a [ i ] > nodes ) return false ; } return true ; } public static void Main ( String [ ] args ) { int [ ] a = { 4 , 1 , 3 , 4 } ; int n = a . Length ; if ( isValidSeq ( a , n ) ) Console . WriteLine ( " Valid " ) ; else Console . WriteLine ( " Invalid " ) ; } }