Get K | C # implementation of the above approach ; Function to return the K - th letter from new String . ; finding size = length of new string S ' ; get the K - th letter ; Driver code
using System ; class GFG { static String K_thletter ( String S , int K ) { int N = S . Length ; long size = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( char . IsDigit ( S [ i ] ) ) { size = size * ( S [ i ] - '0' ) ; } else { size += 1 ; } } for ( int i = N - 1 ; i >= 0 ; -- i ) { K %= ( int ) size ; if ( K == 0 && char . IsLetter ( S [ i ] ) ) { return ( String ) " " + S [ i ] ; } if ( char . IsDigit ( S [ i ] ) ) { size = size / ( S [ i ] - '0' ) ; } else { size -= 1 ; } } return null ; } public static void Main ( String [ ] args ) { String S = " geeks2for2" ; int K = 15 ; Console . WriteLine ( K_thletter ( S , K ) ) ; } }