Find the n | C # program to find n - th palindrome ; Utility function which is used to convert binary string into integer ; Convert binary string into integer ; Function to find nth binary palindrome number ; Stores the binary palindrome string ; Base case ; Add 2 nd binary palindrome string ; Runs till the nth binary palindrome number ; Remove curr binary palindrome string from queue ; If n == 0 then we find the n 'th binary  palindrome so we return our answer ; Calculate length of curr binary palindrome string ; If length is even . so it is our first case we have two choices ; If length is odd . so it is our second case we have only one choice ; Driver code ; Function Call
using System ; using System . Collections . Generic ; class GFG { public static int convertStringToInt ( String s ) { int ans = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '1' ) ans += 1 << i ; } return ans ; } public static int getNthNumber ( int n ) { Queue < String > q = new Queue < String > ( ) ; if ( n == 1 ) return 1 ; n = n - 1 ; q . Enqueue ( "11" ) ; while ( n -- > 0 ) { String curr = q . Dequeue ( ) ; if ( n == 0 ) return convertStringToInt ( curr ) ; int len = curr . Length ; if ( len % 2 == 0 ) { q . Enqueue ( curr . Substring ( 0 , len / 2 ) + "0" + curr . Substring ( len / 2 ) ) ; q . Enqueue ( curr . Substring ( 0 , len / 2 ) + "1" + curr . Substring ( len / 2 ) ) ; } else { char midChar = curr [ len / 2 ] ; q . Enqueue ( curr . Substring ( 0 , len / 2 ) + midChar + curr . Substring ( len / 2 ) ) ; } } return - 1 ; } public static void Main ( String [ ] args ) { int n = 9 ; Console . WriteLine ( getNthNumber ( n ) ) ; } }