codeparrot/xlcost-text-to-code huggingface dataset:
Find consecutive 1 s of length >= n in binary representation of a number | C # implementation of above approach ; Function to count the number of leading zeros ; Function to find the string of n consecutive 1 's ; Initialize position to return . ; Skip leading 0 's ; Set position after leading 0 's ; Count first group of 1 's. ; If length of consecutive 1 's  is greater than or equal to n ; Not enough 1 's  skip over to next group ; Update the position ; if no string is found ; Driver code
using System ; public class GFG { static int countLeadingZeros ( int x ) { int y ; int n ; n = 32 ; y = x >> 16 ; if ( y != 0 ) { n = n - 16 ; x = y ; } y = x >> 8 ; if ( y != 0 ) { n = n - 8 ; x = y ; } y = x >> 4 ; if ( y != 0 ) { n = n - 4 ; x = y ; } y = x >> 2 ; if ( y != 0 ) { n = n - 2 ; x = y ; } y = x >> 1 ; if ( y != 0 ) return n - 2 ; return n - x ; } static int FindStringof1s ( int x , int n ) { int k , p ; p = 0 ; while ( x != 0 ) { k = countLeadingZeros ( x ) ; x = x << k ; p = p + k ; k = countLeadingZeros ( ~ x ) ; if ( k >= n ) return p + 1 ; x = x << k ; p = p + k ; } return - 1 ; } static public void Main ( ) { int x = 35 ; int n = 2 ; Console . WriteLine ( FindStringof1s ( x , n ) ) ; } }
Assign other value to a variable from two possible values | C # program to change value of x according to its current value . ; Function to alternate the values ; Main function
using System ; public class GFG { static int alternate ( int a , int b , int x ) { return x = a ^ b ^ x ; } public static void Main ( ) { int a = - 10 ; int b = 15 ; int x = a ; Console . Write ( " x ▁ is ▁ : ▁ " + x ) ; x = alternate ( a , b , x ) ; Console . Write ( " STRNEWLINE After ▁ exchange ▁ " ) ; Console . Write ( " x is : " } }
Number of leading zeros in binary representation of a given number | C # program of number of leading zeros in binary representation of a given number ; Function to count the no . of leading zeros ; Keep shifting x by one until leftmost bit does not become 1. ; Driver Code
using System ; class GFG { static byte sizeofInt = 8 ; static int countZeros ( int x ) { int total_bits = sizeofInt * 8 ; int res = 0 ; while ( ( x & ( 1 << ( total_bits - 1 ) ) ) == 0 ) { x = ( x << 1 ) ; res ++ ; } return res ; } public static void Main ( String [ ] args ) { int x = 101 ; Console . WriteLine ( countZeros ( x ) ) ; } }
Number of leading zeros in binary representation of a given number | C # program of number of leading zeros in binary representation of a given number ; Function to count the no . of leading zeros ; Driver Code
using System ; class GFG { static int countZeros ( int x ) { int y ; int n = 32 ; y = x >> 16 ; if ( y != 0 ) { n = n - 16 ; x = y ; } y = x >> 8 ; if ( y != 0 ) { n = n - 8 ; x = y ; } y = x >> 4 ; if ( y != 0 ) { n = n - 4 ; x = y ; } y = x >> 2 ; if ( y != 0 ) { n = n - 2 ; x = y ; } y = x >> 1 ; if ( y != 0 ) return n - 2 ; return n - x ; } static public void Main ( ) { int x = 101 ; Console . WriteLine ( countZeros ( x ) ) ; } }
Comparing leading zeros in binary representations of two numbers | C # program to find the number with more leading zeroes . ; Function to compare the no . of leading zeros ; if both have same no . of leading zeros ; if y has more leading zeros ; Driver Code
using System ; class GFG { static void LeadingZeros ( int x , int y ) { if ( ( x ^ y ) <= ( x & y ) ) Console . WriteLine ( " STRNEWLINE Equal " ) ; else if ( ( x & ( ~ y ) ) > y ) Console . WriteLine ( y ) ; else Console . WriteLine ( x ) ; } static public void Main ( ) { int x = 10 , y = 16 ; LeadingZeros ( x , y ) ; } }
Printing all subsets of { 1 , 2 , 3 , ... n } without using array or loop | C # code to print all subsets of { 1 , 2 , 3 , n } without using array or loop , just recursion . ; This recursive function calls subset function to print the subsets one by one . numBits -- > number of bits needed to represent the number ( simply input value n ) . num -- > Initially equal to 2 ^ n - 1 and decreases by 1 every recursion until 0. ; Print the subset corresponding to binary representation of num . ; Call the function recursively to print the next subset . ; This function recursively prints the subset corresponding to the binary representation of num . nthBit -- > nth bit from right side starting from n and decreases until 0. ; Print number in given subset only if the bit corresponding to it is set in num . ; Check for the next bit ; Driver codeM
using System ; class GfG { static void printSubSets ( int numOfBits , int num ) { if ( num >= 0 ) { Console . Write ( " { ▁ " ) ; subset ( numOfBits - 1 , num , numOfBits ) ; Console . WriteLine ( " } " ) ; printSubSets ( numOfBits , num - 1 ) ; } else return ; } static void subset ( int nthBit , int num , int numOfBits ) { if ( nthBit >= 0 ) { if ( ( num & ( 1 << nthBit ) ) != 0 ) { Console . Write ( numOfBits - nthBit + " ▁ " ) ; } subset ( nthBit - 1 , num , numOfBits ) ; } else return ; } public static void Main ( String [ ] args ) { int n = 4 ; printSubSets ( n , ( int ) ( Math . Pow ( 2 , n ) ) - 1 ) ; } }
Number of mismatching bits in the binary representation of two integers | C # implementation of the approach ; compute number of different bits ; since , the numbers are less than 2 ^ 31 run the loop from '0' to '31' only ; right shift both the numbers by ' i ' and check if the bit at the 0 th position is different ; Driver code ; find number of different bits
using System ; class GFG { static void solve ( int A , int B ) { int count = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { if ( ( ( A >> i ) & 1 ) != ( ( B >> i ) & 1 ) ) { count ++ ; } } Console . WriteLine ( " Number ▁ of ▁ different ▁ bits ▁ : ▁ " + count ) ; } public static void Main ( ) { int A = 12 , B = 15 ; solve ( A , B ) ; } }
Set the rightmost off bit | C # program to set the rightmost unset bit ; If all bits are set ; Set rightmost 0 bit ; Driver program to test above
using System ; public class GFG { static int setRightmostUnsetBit ( int n ) { if ( ( n & ( n + 1 ) ) == 0 ) return n ; return n | ( n + 1 ) ; } public static void Main ( ) { int n = 21 ; Console . WriteLine ( setRightmostUnsetBit ( n ) ) ; } }
Print the number of set bits in each node of a Binary Tree | C # program to print the number of set bits in each node of the binary tree ; Binary Tree node ; Utility function that allocates a new Node ; Function to print the number of set bits in each node of the binary tree ; Print the number of set bits of current node using __builtin_popcount ( ) ; Traverse Left Subtree ; Traverse Right Subtree ; Driver code
using System ; class GFG { public class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static void printSetBit ( Node root ) { if ( root == null ) return ; Console . Write ( " Set ▁ bits ▁ in ▁ Node ▁ " + root . data + " ▁ = ▁ " + bitCount ( root . data ) + " STRNEWLINE " ) ; printSetBit ( root . left ) ; printSetBit ( root . right ) ; } static int bitCount ( int x ) { int setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } public static void Main ( String [ ] args ) { Node root = newNode ( 16 ) ; root . left = newNode ( 13 ) ; root . left . left = newNode ( 14 ) ; root . left . right = newNode ( 12 ) ; root . right = newNode ( 11 ) ; root . right . left = newNode ( 10 ) ; root . right . right = newNode ( 16 ) ; printSetBit ( root ) ; } }
Find bitwise AND ( & ) of all possible sub | C # program to find of all the sub - arrays ; function to return AND of sub - arrays ; Driver code ; size of the array ; print and of all subarrays
using System ; public class GFG { static int AND ( int [ ] a , int n ) { int ans = a [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) ans &= a [ i ] ; return ans ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 } ; int n = a . Length ; Console . WriteLine ( AND ( a , n ) ) ; } }
2 's complement for a givin string using XOR | C # program to find 2 's complement using XOR. ; A flag used to find if a 1 bit is seen or not . ; xor operator is used to flip the ; bits after converting in to ASCII values ; If there is no 1 in the string so just add 1 in starting of string and return ; Driver code
using System ; class GFG { static void TwoscomplementbyXOR ( string str ) { int n = str . Length ; bool check_bit = false ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == '0' && check_bit == false ) { continue ; } else { if ( check_bit == true ) { if ( str [ i ] == '0' ) str = str . Substring ( 0 , i ) + '1' + str . Substring ( i + 1 ) ; else str = str . Substring ( 0 , i ) + '0' + str . Substring ( i + 1 ) ; } check_bit = true ; } } if ( check_bit == false ) { Console . WriteLine ( "1" + str ) ; } else Console . WriteLine ( str ) ; } static void Main ( ) { string str = "101" ; TwoscomplementbyXOR ( str ) ; } }
Check whether bits are in alternate pattern in the given range | Set | C # implementation to check whether bits are in alternate pattern in the given range ; function to check whether rightmost kth bit is set or not in ' n ' ; function to set the rightmost kth bit in ' n ' ; kth bit of n is being set by this operation ; function to check if all the bits are set or not in the binary representation of ' n ' ; if true , then all bits are set ; else all bits are not set ; function to check if a number has bits in alternate pattern ; to check if all bits are set in ' num ' ; function to check whether bits are in alternate pattern in the given range ; preparing a number ' num ' and ' left _ shift ' which can be further used for the check of alternate pattern in the given range ; unset all the bits which are left to the rth bit of ( r + 1 ) th bit ; right shift ' num ' by ( l - 1 ) bits ; Driver code
using System ; class GFG { static bool isKthBitSet ( int n , int k ) { if ( ( n >> ( k - 1 ) ) == 1 ) return true ; return false ; } static int setKthBit ( int n , int k ) { return ( ( 1 << ( k - 1 ) ) n ) ; } static bool allBitsAreSet ( int n ) { if ( ( ( n + 1 ) & n ) == 0 ) return true ; return false ; } static bool bitsAreInAltOrder ( int n ) { int num = n ^ ( n >> 1 ) ; return allBitsAreSet ( num ) ; } static bool bitsAreInAltPatrnInGivenRange ( int n , int l , int r ) { int num , left_shift ; if ( isKthBitSet ( n , r ) ) { num = n ; left_shift = r ; } else { num = setKthBit ( n , ( r + 1 ) ) ; left_shift = r + 1 ; } num = num & ( ( 1 << left_shift ) - 1 ) ; num = num >> ( l - 1 ) ; return bitsAreInAltOrder ( num ) ; } public static void Main ( ) { int n = 18 ; int l = 1 , r = 3 ; if ( bitsAreInAltPatrnInGivenRange ( n , l , r ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check whether bits are in alternate pattern in the given range | C # implementation to check whether bits are in alternate pattern in the given range ; function to check whether bits are in alternate pattern in the given range ; right shift n by ( l - 1 ) bits ; get the bit at the last position in ' num ' ; right shift ' num ' by 1 ; loop until there are bits in the given range ; get the bit at the last position in ' num ' ; if true , then bits are not in alternate pattern ; update ' prev ' ; right shift ' num ' by 1 ; bits are in alternate pattern in the given range ; Driver Code
using System ; class GFG { static bool bitsAreInAltPatrnInGivenTRange ( int n , int l , int r ) { int num , prev , curr ; num = n >> ( l - 1 ) ; prev = num & 1 ; num = num >> 1 ; for ( int i = 1 ; i <= ( r - l ) ; i ++ ) { curr = num & 1 ; if ( curr == prev ) return false ; prev = curr ; num = num >> 1 ; } return true ; } static void Main ( ) { int n = 18 ; int l = 1 , r = 3 ; if ( bitsAreInAltPatrnInGivenTRange ( n , l , r ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Increment a number without using ++ or + | C # program to increment an unsigned int using bitwise operators . ; function that increment the value . ; Invert bits and apply negative sign ; Driver code
using System ; class GFG { static long increment ( long i ) { i = - ( ~ i ) ; return i ; } public static void Main ( ) { long n = 3 ; Console . WriteLine ( increment ( n ) ) ; } }
First element greater than or equal to X in prefix sum of N numbers using Binary Lifting | C # program to find lower_bound of x in prefix sums array using binary lifting . ; function to make prefix sums array ; function to find lower_bound of x in prefix sums array using binary lifting . ; initialize position ; find log to the base 2 value of n . ; if x less than first number . ; starting from most significant bit . ; if value at this position less than x then updateposition Here ( 1 << i ) is similar to 2 ^ i . ; + 1 because ' pos ' will have position of largest value less than ' x ' ; Driver code ; given array ; value to find ; size of array ; to store prefix sum ; call for prefix sum ; function call
using System ; class GFG { static void MakePreSum ( int [ ] arr , int [ ] presum , int n ) { presum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) presum [ i ] = presum [ i - 1 ] + arr [ i ] ; } static int BinaryLifting ( int [ ] presum , int n , int x ) { int pos = 0 ; int LOGN = ( int ) Math . Log ( n ) ; if ( x <= presum [ 0 ] ) return 0 ; for ( int i = LOGN ; i >= 0 ; i -- ) { if ( pos + ( 1 << i ) < n && presum [ pos + ( 1 << i ) ] < x ) { pos += ( 1 << i ) ; } } return pos + 1 ; } public static void Main ( ) { int [ ] arr = { 2 , 5 , 7 , 1 , 6 , 9 , 12 , 4 , 6 } ; int x = 8 ; int n = arr . Length ; int [ ] presum = new int [ n ] ; MakePreSum ( arr , presum , n ) ; Console . WriteLine ( BinaryLifting ( presum , n , x ) ) ; } }
Maximum sum by adding numbers with same number of set bits | C # program to find maximum sum by adding numbers with same number of set bits ; count the number of bits for each element of array ; Count the number of set bits ; Function to return the the maximum sum ; Calculate the ; Assuming the number to be a maximum of 32 bits ; Add the number to the number of set bits ; Find the maximum sum ; Driver code
using System ; class GFG { static int bit_count ( int n ) { int count = 0 ; while ( n > 0 ) { count ++ ; n = n & ( n - 1 ) ; } return count ; } static int maxsum ( int [ ] arr , int n ) { int [ ] bits = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { bits [ i ] = bit_count ( arr [ i ] ) ; } int [ ] sum = new int [ 32 ] ; for ( int i = 0 ; i < n ; i ++ ) { sum [ bits [ i ] ] += arr [ i ] ; } int maximum = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { maximum = Math . Max ( sum [ i ] , maximum ) ; } return maximum ; } static void Main ( ) { int [ ] arr = { 2 , 3 , 8 , 5 , 6 , 7 } ; int n = arr . Length ; Console . WriteLine ( maxsum ( arr , n ) ) ; } }
Sum of XOR of sum of all pairs in an array | C # program to find XOR of pair sums . ; Driver code
using System ; class GFG { static int xorPairSum ( int [ ] ar , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum ^ ar [ i ] ; return 2 * sum ; } static public void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int n = arr . Length ; Console . WriteLine ( xorPairSum ( arr , n ) ) ; } }
Count pairs with Bitwise OR as Even number | C # program to count pairs with even OR ; Count total even numbers in array . ; return count of even pair ; Driver Code
using System ; class GFG { static int findEvenPair ( int [ ] A , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( ( ! ( ( A [ i ] & 1 ) > 0 ) ) ) count ++ ; return count * ( count - 1 ) / 2 ; } public static void Main ( String [ ] args ) { int [ ] A = { 5 , 6 , 2 , 8 } ; int N = A . Length ; Console . WriteLine ( findEvenPair ( A , N ) ) ; } }
Check whether all the bits are unset in the given range | C # implementation to check whether all the bits are unset in the given range or not ; function to check whether all the bits are unset in the given range or not ; calculating a number ' num ' having ' r ' number of bits and bits in the range l to r are the only set bits ; new number which could only have one or more set bits in the range l to r and nowhere else ; if true , then all bits are unset in the given range ; else all bits are not unset in the given range ; Driver Code
using System ; class GFG { static bool allBitsSetInTheGivenRange ( int n , int l , int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( new_num == 0 ) return true ; return false ; } public static void Main ( ) { int n = 17 ; int l = 2 , r = 4 ; if ( allBitsSetInTheGivenRange ( n , l , r ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Check if a number has same number of set and unset bits | C # program to check if a number has same number of set and unset bits ; Function to check if a number has same setbits and unset bits ; iterate for all bits of a number ; if set ; if unset ; right shift number by 1 ; is number of set bits are equal to unset bits ; Driver Code ; function to check
using System ; public class GFG { static bool checkSame ( int n ) { int set = 0 ; int unset = 0 ; while ( n > 0 ) { if ( ( n & 1 ) == 1 ) set ++ ; else unset ++ ; n = n >> 1 ; } if ( set == unset ) return true ; else return false ; } static public void Main ( ) { int n = 12 ; if ( checkSame ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Check if concatenation of two strings is balanced or not | C # program to check if sequence obtained by concatenating two bracket sequences is balanced or not . ; Check if given string is balanced bracket sequence or not . ; If current bracket is an opening bracket push it to stack . ; If current bracket is a closing bracket then pop from stack if it is not empty . If stack is empty then sequence is not balanced . ; If stack is not empty , then sequence is not balanced . ; Function to check if string obtained by concatenating two bracket sequences is balanced or not . ; Check if s1 + s2 is balanced or not . ; Check if s2 + s1 is balanced or not . ; Driver code .
using System ; using System . Collections . Generic ; class GFG { static bool isBalanced ( String s ) { Stack < char > st = new Stack < char > ( ) ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ( ' ) { st . Push ( s [ i ] ) ; } else if ( st . Count == 0 ) { return false ; } else { st . Pop ( ) ; } } if ( st . Count != 0 ) { return false ; } return true ; } static bool isBalancedSeq ( String s1 , String s2 ) { if ( isBalanced ( s1 + s2 ) ) { return true ; } return isBalanced ( s2 + s1 ) ; } public static void Main ( String [ ] args ) { String s1 = " ) ( ) ( ( ) ) ) ) " ; String s2 = " ( ( ) ( ( ) ( " ; if ( isBalancedSeq ( s1 , s2 ) ) { Console . WriteLine ( " Balanced " ) ; } else { Console . WriteLine ( " Not ▁ Balanced " ) ; } } }
Find iâ €™ th index character in a binary string obtained after n iterations | Set 2 | C # program to find ith Index character in a binary string obtained after n iterations ; Function to find the i - th character ; distance between two consecutive elements after N iterations ; binary representation of M ; kth digit will be derived from root for sure ; Check whether there is need to flip root or not ; Driver Code
using System ; class GFG { static void KthCharacter ( int m , int n , int k ) { int distance = ( int ) Math . Pow ( 2 , n ) ; int Block_number = k / distance ; int remaining = k % distance ; int [ ] s = new int [ 32 ] ; int x = 0 ; for ( ; m > 0 ; x ++ ) { s [ x ] = m % 2 ; m = m / 2 ; } int root = s [ x - 1 - Block_number ] ; if ( remaining == 0 ) { Console . WriteLine ( root ) ; return ; } Boolean flip = true ; while ( remaining > 1 ) { if ( ( remaining & 1 ) > 0 ) { flip = ! flip ; } remaining = remaining >> 1 ; } if ( flip ) { Console . WriteLine ( ! ( root > 0 ) ) ; } else { Console . WriteLine ( root ) ; } } public static void Main ( ) { int m = 5 , k = 5 , n = 3 ; KthCharacter ( m , n , k ) ; } }
Check whether the number has only first and last bits set | Set 2 | C # to check whether the number has only first and last bits set ; function to check whether the number has only first and last bits set ; Driver Code
using System ; class GFG { static bool onlyFirstAndLastAreSet ( int n ) { if ( n == 1 ) return true ; if ( n == 2 ) return false ; return ( ( ( n - 1 ) & ( n - 2 ) ) == 0 ) ; } public static void Main ( ) { int n = 9 ; if ( onlyFirstAndLastAreSet ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Number with set bits only between L | C # program to print the integer with all the bits set in range L - R Naive Approach ; Function to return the integer with all the bits set in range L - R ; iterate from L to R and add all powers of 2 ; Driver Code
using System ; class GFG { static int getInteger ( int L , int R ) { int number = 0 ; for ( int i = L ; i <= R ; i ++ ) number += ( int ) Math . Pow ( 2 , i ) ; return number ; } public static void Main ( ) { int L = 2 , R = 5 ; Console . Write ( getInteger ( L , R ) ) ; } }
Number with set bits only between L | C # program to print the integer with all the bits set in range L - R Efficient Approach ; Function to return the integer with all the bits set in range L - R ; Driver Code
using System ; class GFG { static int setbitsfromLtoR ( int L , int R ) { return ( 1 << ( R + 1 ) ) - ( 1 << L ) ; } public static void Main ( ) { int L = 2 , R = 5 ; Console . WriteLine ( setbitsfromLtoR ( L , R ) ) ; } }
XOR of Sum of every possible pair of an array | C # program to find XOR of sum of every possible pairs in an array ; Function to find XOR of sum of all pairs ; Calculate xor of all the elements ; Return twice of xor value ; Drivers code
using System ; class GFG { static int findXor ( int [ ] arr , int n ) { int xoR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xoR = xoR ^ arr [ i ] ; } return xoR * 2 ; } public static void Main ( ) { int [ ] arr = { 1 , 5 , 6 } ; int n = arr . Length ; Console . WriteLine ( findXor ( arr , n ) ) ; } }
Largest set with bitwise OR equal to n | C # Program to find the largest set with bitwise OR equal to n ; function to find the largest set with bitwise OR equal to n ; If the bitwise OR of n and i is equal to n , then include i in the set ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void setBitwiseORk ( int n ) { List < int > v = new List < int > ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { if ( ( i n ) == n ) { v . Add ( i ) ; } } for ( int i = 0 ; i < v . Count ; i ++ ) { Console . Write ( v [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; setBitwiseORk ( n ) ; } }
Two odd occurring elements in an array where all other occur even times | C # code to find two odd occurring elements in an array where all other elements appear even number of times . ; Find XOR of all numbers ; Find a set bit in the XOR ( We find rightmost set bit here ) ; Traverse through all numbers and divide them in two groups ( i ) Having set bit set at same position as the only set bit in set_bit ( ii ) Having 0 bit at same position as the only set bit in set_bit ; XOR of two different sets are our required numbers . ; Driver code
using System ; class GFG { static void printOdds ( int [ ] arr , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res = res ^ arr [ i ] ; int set_bit = res & ( ~ ( res - 1 ) ) ; int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & set_bit ) != 0 ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } Console . WriteLine ( x + " ▁ " + y ) ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 3 , 4 , 4 , 5 } ; int n = arr . Length ; printOdds ( arr , n ) ; } }