C # implementation of the approach
using System ; using System . Collections . Generic ; class GFG { static void Count ( int [ ] temp ) { int [ ] query = { 9 , 3 , 2 } ; int Q = query . Length ; for ( int i = 0 ; i < Q ; i ++ ) { int pos = query [ i ] ; Console . WriteLine ( temp [ pos - 1 ] ) ; } } static int [ ] processing ( String s , int len ) { int [ ] temp = new int [ len ] ; Dictionary < int , int > d = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( ! d . ContainsKey ( s [ i ] ) ) { d . Add ( s [ i ] , i ) ; } else { temp [ i ] = temp [ d [ s [ i ] ] ] + 1 ; d [ s [ i ] ] = i ; } } return temp ; }