Length of Smallest Non Prime Subsequence in given numeric String | C # program for the above approach ; Function to find the smallest length of resultant subsequence ; Check for a subsequence of size 1 ; Check for a subsequence of size 2 ; If none of the above check is successful then subsequence must be of size 3 ; Never executed ; Driver Code
using System ; class GFG { static void findMinimumSubsequence ( string S ) { bool flag = false ; string dummy = " " ; for ( int j = 0 ; j < S . Length ; j ++ ) { if ( S [ j ] != '2' && S [ j ] != '3' && S [ j ] != '5' && S [ j ] != '7' ) { Console . WriteLine ( 1 ) ; flag = true ; break ; } } if ( ! flag ) { for ( int j = 0 ; j < S . Length - 1 ; j ++ ) { for ( int j1 = j + 1 ; j1 < S . Length ; j1 ++ ) { dummy = S [ j ] . ToString ( ) + S [ j1 ] . ToString ( ) ; if ( dummy != "23" && dummy != "37" && dummy != "53" && dummy != "73" ) { Console . WriteLine ( 2 ) ; } if ( flag == true ) break ; else flag = true ; } if ( flag == true ) break ; } } if ( flag == false ) { if ( S . Length >= 3 ) { Console . WriteLine ( 3 ) ; } else { Console . WriteLine ( - 1 ) ; } } } public static void Main ( ) { string S = "237" ; findMinimumSubsequence ( S ) ; } }