codeparrot/xlcost-text-to-code huggingface dataset:
Overall percentage change from successive changes | C # implementation of above approach ; Calculate successive change of 1 st 2 change ; Calculate successive change for rest of the value ; Driver code ; Calling function
using System ; class GFG { static float successiveChange ( int [ ] arr , int N ) { float var1 , var2 , result = 0 ; var1 = arr [ 0 ] ; var2 = arr [ 1 ] ; result = var1 + var2 + ( ( var1 * var2 ) / 100 ) ; for ( int i = 2 ; i < N ; i ++ ) result = result + arr [ i ] + ( ( result * arr [ i ] ) / 100 ) ; return result ; } public static void Main ( ) { int [ ] arr = { 10 , 20 , 30 , 10 } ; int N = arr . Length ; float result = successiveChange ( arr , N ) ; Console . WriteLine ( " Percentage ▁ change ▁ is ▁ = ▁ " + result + " ▁ % " ) ; } }
Minimum numbers ( smaller than or equal to N ) with sum S | C # program to find the minimum numbers required to get to S ; Function to find the minimum numbers required to get to S ; Driver Code
using System ; class GFG { static int minimumNumbers ( int n , int s ) { if ( ( s % n ) > 0 ) return s / n + 1 ; else return s / n ; } public static void Main ( ) { int n = 5 ; int s = 11 ; Console . WriteLine ( minimumNumbers ( n , s ) ) ; } }
Sum of multiples of A and B less than N | C # program to find the sum of all multiples of A and B below N ; Function to find sum of AP series ; Number of terms ; Function to find the sum of all multiples of A and B below N ; Since , we need the sum of multiples less than N ; common factors of A and B ; Driver code
class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static int sumAP ( int n , int d ) { n /= d ; return ( n ) * ( 1 + n ) * d / 2 ; } static int sumMultiples ( int A , int B , int n ) { n -- ; int common = ( A * B ) / __gcd ( A , B ) ; return sumAP ( n , A ) + sumAP ( n , B ) - sumAP ( n , common ) ; } public static void Main ( ) { int n = 100 , A = 5 , B = 10 ; System . Console . WriteLine ( " Sum ▁ = ▁ " + sumMultiples ( A , B , n ) ) ; } }
Check if a prime number can be expressed as sum of two Prime Numbers | C # program to check if a prime number can be expressed as sum of two Prime Numbers ; Function to check whether a number is prime or not ; Function to check if a prime number can be expressed as sum of two Prime Numbers ; if the number is prime , and number - 2 is also prime ; Driver code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static bool isPossible ( int N ) { if ( isPrime ( N ) && isPrime ( N - 2 ) ) return true ; else return false ; } public static void Main ( ) { int n = 13 ; if ( isPossible ( n ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Count pairs from two arrays whose modulo operation yields K | C # implementation of the approach ; Function to return the total pairs of elements whose modulo yield K ; set is used to avoid duplicate pairs ; check which element is greater and proceed according to it ; check if modulo is equal to K ; return size of the set ; Driver code
using System ; using System . Collections . Generic ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int totalPairs ( int [ ] arr1 , int [ ] arr2 , int K , int n , int m ) { HashSet < pair > s = new HashSet < pair > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr1 [ i ] > arr2 [ j ] ) { if ( arr1 [ i ] % arr2 [ j ] == K ) s . Add ( new pair ( arr1 [ i ] , arr2 [ j ] ) ) ; } else { if ( arr2 [ j ] % arr1 [ i ] == K ) s . Add ( new pair ( arr2 [ j ] , arr1 [ i ] ) ) ; } } } return s . Count ; } public static void Main ( String [ ] args ) { int [ ] arr1 = { 8 , 3 , 7 , 50 } ; int [ ] arr2 = { 5 , 1 , 10 , 4 } ; int K = 3 ; int n = arr1 . Length ; int m = arr2 . Length ; Console . WriteLine ( totalPairs ( arr1 , arr2 , K , n , m ) ) ; } }
Largest sub | C # program to find the length of the largest sub - array of an array every element of whose is a perfect square ; function to return the length of the largest sub - array of an array every element of whose is a perfect square ; if both a and b are equal then arr [ i ] is a perfect square ; Driver code
using System ; class GFG { static int contiguousPerfectSquare ( int [ ] arr , int n ) { int a ; float b ; int current_length = 0 ; int max_length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { b = ( float ) Math . Sqrt ( arr [ i ] ) ; a = ( int ) b ; if ( a == b ) current_length ++ ; else current_length = 0 ; max_length = Math . Max ( max_length , current_length ) ; } return max_length ; } public static void Main ( ) { int [ ] arr = { 9 , 75 , 4 , 64 , 121 , 25 } ; int n = arr . Length ; Console . WriteLine ( contiguousPerfectSquare ( arr , n ) ) ; } }
Count pairs of numbers from 1 to N with Product divisible by their Sum | C # program to count pairs of numbers from 1 to N with Product divisible by their Sum ; Function to count pairs ; variable to store count ; Generate all possible pairs such that 1 <= x < y < n ; Driver code
using System ; class GFG { static int countPairs ( int n ) { int count = 0 ; for ( int x = 1 ; x < n ; x ++ ) { for ( int y = x + 1 ; y <= n ; y ++ ) { if ( ( y * x ) % ( y + x ) == 0 ) count ++ ; } } return count ; } public static void Main ( ) { int n = 15 ; Console . WriteLine ( countPairs ( n ) ) ; } }
Find the index of the left pointer after possible moves in the array | C # program to find the index of the left pointer ; Function that returns the index of the left pointer ; there 's only one element in the array ; initially both are at end ; Driver code
using System ; class GFG { static int getIndex ( int [ ] a , int n ) { if ( n == 1 ) return 0 ; int ptrL = 0 , ptrR = n - 1 , sumL = a [ 0 ] , sumR = a [ n - 1 ] ; while ( ptrR - ptrL > 1 ) { if ( sumL < sumR ) { ptrL ++ ; sumL += a [ ptrL ] ; } else if ( sumL > sumR ) { ptrR -- ; sumR += a [ ptrR ] ; } else { break ; } } return ptrL ; } public static void Main ( ) { int [ ] a = { 2 , 7 , 9 , 8 , 7 } ; int n = a . Length ; Console . WriteLine ( getIndex ( a , n ) ) ; } }
Find the position of the last removed element from the array | C # program to find the position of the last removed element from the array ; Function to find the original position of the element which will be removed last ; take ceil of every number ; Since position is index + 1 ; Driver code
using System ; class GFG { static int getPosition ( int [ ] a , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] / m + ( a [ i ] % m ) ) ; } int ans = - 1 , max = - 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( max < a [ i ] ) { max = a [ i ] ; ans = i ; } } return ans + 1 ; } static public void Main ( ) { int [ ] a = { 2 , 5 , 4 } ; int n = a . Length ; int m = 2 ; Console . WriteLine ( getPosition ( a , n , m ) ) ; } }
Find the value of f ( n ) / f ( r ) * f ( n | C # program to find the value of f ( n ) / f ( r ) * f ( n - r ) ; Function to find value of given F ( n ) ; iterate over n ; calculate result ; return the result ; Driver code
using System ; public class GFG { static int calcFunction ( int n , int r ) { int finalDenominator = 1 ; int mx = Math . Max ( r , n - r ) ; for ( int i = mx + 1 ; i <= n ; i ++ ) { int denominator = ( int ) Math . Pow ( i , i ) ; int numerator = ( int ) Math . Pow ( i - mx , i - mx ) ; finalDenominator = ( finalDenominator * denominator ) / numerator ; } return finalDenominator ; } public static void Main ( ) { int n = 6 , r = 2 ; Console . WriteLine ( "1 / " + calcFunction ( n , r ) ) ; } }
Check if the array has an element which is equal to sum of all the remaining elements | C # program to Check if the array has an element which is equal to sum of all the remaining elements ; Function to check if such element exists or not ; Storing frequency in map ; Stores the sum ; Traverse the array and count the array elements ; Only possible if sum is even ; If half sum is available ; Driver code
using System ; using System . Collections . Generic ; class Solution { static Boolean isExists ( int [ ] arr , int n ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . ContainsKey ( arr [ i ] ) ) { var val = m [ arr [ i ] ] ; m . Remove ( arr [ i ] ) ; m . Add ( arr [ i ] , val + 1 ) ; } else { m . Add ( arr [ i ] , 1 ) ; } sum += arr [ i ] ; } if ( sum % 2 == 0 ) { if ( m [ sum / 2 ] != 0 ) return true ; } return false ; } public static void Main ( ) { int [ ] a = { 5 , 1 , 2 , 2 } ; int n = a . Length ; if ( isExists ( a , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Print all numbers less than N with at | C # program to print all the numbers less than N which have at most 2 unique digits ; Function to generate all possible numbers ; If the number is less than n ; If the number exceeds ; Check if it is not the same number ; Function to print all numbers ; All combination of digits ; Print all numbers ; Driver code
using System ; using System . Collections . Generic ; class GFG { static SortedSet < int > st = new SortedSet < int > ( ) ; static void generateNumbers ( int n , int num , int a , int b ) { if ( num > 0 && num < n ) st . Add ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } static void printNumbers ( int n ) { for ( int i = 0 ; i <= 9 ; i ++ ) for ( int j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; Console . Write ( " The ▁ numbers ▁ are : ▁ " ) ; foreach ( int obj in st ) Console . Write ( obj + " ▁ " ) ; st . Clear ( ) ; } public static void Main ( String [ ] args ) { int n = 12 ; printNumbers ( n ) ; } }
Smallest prime number missing in an array | C # implementation of the above approach ; this store all prime number upto 10 ^ 5 this function find all prime ; use sieve to find prime ; if number is prime then store it in prime vector ; Function to find the smallest prime missing ; first of all find all prime ; now store all number as index of freq arr so that we can improve searching ; now check for each prime ; Driver code ; find smallest prime which is not present
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static ArrayList findPrime ( int MAX ) { bool [ ] pm = new bool [ MAX + 1 ] ; for ( int i = 0 ; i < MAX + 1 ; i ++ ) pm [ i ] = true ; pm [ 0 ] = pm [ 1 ] = false ; for ( int i = 2 ; i <= MAX ; i ++ ) if ( pm [ i ] ) for ( int j = 2 * i ; j <= MAX ; j += i ) pm [ j ] = false ; ArrayList prime = new ArrayList ( ) ; for ( int i = 0 ; i <= MAX ; i ++ ) if ( pm [ i ] ) prime . Add ( i ) ; return prime ; } static int max_element ( int [ ] arr ) { int max = arr [ 0 ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) max = Math . Max ( max , arr [ i ] ) ; return max ; } static int findSmallest ( int [ ] arr , int n ) { int MAX = max_element ( arr ) ; ArrayList prime = findPrime ( MAX ) ; HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) s . Add ( arr [ i ] ) ; int ans = - 1 ; for ( int i = 0 ; i < prime . Count ; i ++ ) { if ( ! s . Contains ( ( int ) prime [ i ] ) ) { ans = ( int ) ( prime [ i ] ) ; break ; } } return ( int ) ans ; } static void Main ( ) { int [ ] arr = { 3 , 0 , 1 , 2 , 7 } ; int n = arr . Length ; if ( findSmallest ( arr , n ) == - 1 ) Console . Write ( " No ▁ prime ▁ number ▁ missing " ) ; else Console . Write ( findSmallest ( arr , n ) ) ; } }
Find the number after successive division | C # implementation of the above approach ; Function to find the number ; Driver Code
using System ; class GFG { static int findNum ( int [ ] div , int [ ] rem , int N ) { int num = rem [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { num = num * div [ i ] + rem [ i ] ; } return num ; } static public void Main ( ) { int [ ] div = { 8 , 3 } ; int [ ] rem = { 2 , 2 } ; int N = div . Length ; Console . WriteLine ( findNum ( div , rem , N ) ) ; } }
Program to find the profit or loss when CP of N items is equal to SP of M items | C # implementation of above formula ; Function to calculate Profit or loss ; Driver Code
using System ; class GFG { static void profitLoss ( int N , int M ) { if ( N == M ) Console . Write ( " No ▁ Profit ▁ nor ▁ Loss " ) ; else { float result = 0 ; result = ( float ) ( Math . Abs ( N - M ) ) / M ; if ( N - M < 0 ) Console . Write ( " Loss ▁ = ▁ - " + result * 100 + " % " ) ; else Console . Write ( " Profit ▁ = ▁ " + result * 100 + " % " ) ; } } static public void Main ( ) { int N = 8 , M = 9 ; profitLoss ( N , M ) ; } }
Aronson 's Sequence | C # program to generate the first n terms of Aronson 's sequence ; Returns the given number in words ; Get number of digits in given number ; Base cases ; The following arrays contain one digit ( both cardinal and ordinal forms ) , two digit ( < 20 , ordinal forms ) numbers , and multiples ( ordinal forms ) and powers of 10. ; If single digit number ; here len can be 3 or 4 ; last two digits ; Handle all powers of 10 ; Handle two digit numbers < 20 ; Function to print the first n terms of Aronson 's sequence ; check if character is alphabet or not ; convert number to words in ordinal format and append ; Driver code
using System ; class GFG { static String convert_to_words ( char [ ] num ) { int len = num . Length ; if ( len == 0 len > 4 ) { return " " ; } String [ ] single_digits_temp = { " " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " } ; String [ ] single_digits = { " " , " first " , " second " , " third " , " fourth " , " fifth " , " sixth " , " seventh " , " eighth " , " ninth " } ; String [ ] two_digits = { " " , " tenth " , " eleventh " , " twelfth " , " thirteenth " , " fourteenth " , " fifteenth " , " sixteenth " , " seventeenth " , " eighteenth " , " nineteenth " } ; String [ ] tens_multiple = { " " , " tenth " , " twentieth " , " thirtieth " , " fortieth " , " fiftieth " , " sixtieth " , " seventieth " , " eightieth " , " ninetieth " } ; String [ ] tens_power = { " hundred " , " thousand " } ; String word = " " ; if ( len == 1 ) { word += single_digits [ num [ 0 ] - '0' ] ; return word ; } int i = 0 , ctr = 0 ; String s = " ▁ " ; while ( i < len ) { if ( len >= 3 ) { if ( num [ i ] != '0' ) { word += single_digits_temp [ num [ i ] - '0' ] + " ▁ " ; word += tens_power [ len - 3 ] + " ▁ " ; ctr ++ ; } len -- ; Array . Copy ( num , 1 , num , 0 , num . Length - 1 ) ; } else { if ( ctr != 0 ) { s = " ▁ and ▁ " ; word = word . Substring ( 0 , word . Length - 1 ) ; } if ( num [ i + 1 ] == '0' ) if ( num [ i ] == '0' ) word = word + " th " ; else word += s + tens_multiple [ num [ i ] - '0' ] ; else if ( num [ i ] == '1' ) word += s + two_digits [ num [ i + 1 ] - '0' + 1 ] ; else { if ( num [ i ] != '0' ) word += s + tens_multiple [ num [ i ] - '0' ] . Substring ( 0 , tens_multiple [ num [ i ] - '0' ] . Length - 4 ) + " y ▁ " ; else word += s ; word += single_digits [ num [ i + 1 ] - '0' ] ; } i += 2 ; } if ( i == len ) { if ( word [ 0 ] == ' ▁ ' ) word = word . Substring ( 1 , word . Length - 1 ) ; } } return word ; } static void Aronsons_sequence ( int n ) { String str = " T ▁ is ▁ the ▁ " ; int ind = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( char . IsLetterOrDigit ( str [ i ] ) ) { ind += 1 ; } if ( str [ i ] == ' t ' str [ i ] == ' T ' ) { n -= 1 ; str += convert_to_words ( String . Join ( " " , ind ) . ToCharArray ( ) ) + " , ▁ " ; Console . Write ( ind + " , ▁ " ) ; } if ( n == 0 ) break ; } } public static void Main ( String [ ] args ) { int n = 6 ; Aronsons_sequence ( n ) ; } }
Find all good indices in the given Array | C # program to find all good indices in the given array ; Function to find all good indices in the given array ; hash to store frequency of each element ; Storing frequency of each element and calculating sum simultaneously ; check if array is good after removing i - th index element ; print good indices ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void niceIndices ( int [ ] A , int n ) { int sum = 0 ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( A [ i ] ) ) { var val = mp [ A [ i ] ] ; mp . Remove ( A [ i ] ) ; mp . Add ( A [ i ] , val + 1 ) ; sum += A [ i ] ; } else { mp . Add ( A [ i ] , 0 ) ; sum += A [ i ] ; } } for ( int i = 0 ; i < n ; ++ i ) { int k = sum - A [ i ] ; if ( k % 2 == 0 ) { k = k >> 1 ; if ( mp . ContainsKey ( k ) ) { if ( ( A [ i ] == k && mp [ k ] > 1 ) || ( A [ i ] != k ) ) Console . Write ( ( i + 1 ) + " ▁ " ) ; } } } } public static void Main ( String [ ] args ) { int [ ] A = { 8 , 3 , 5 , 2 } ; int n = A . Length ; niceIndices ( A , n ) ; } }
Count pieces of circle after N cuts | C # program to find number of pieces of circle after N cuts ; Function to find number of pieces of circle after N cuts ; Driver program
class solution { static int countPieces ( int N ) { return 2 * N ; } static void Main ( ) { int N = 100 ; System . Console . WriteLine ( countPieces ( N ) ) ; } }
Sum of all the multiples of 3 and 7 below N | C # program to find the sum of all multiples of 3 and 7 below N ; Function to find sum of AP series ; Number of terms ; Function to find the sum of all multiples of 3 and 7 below N ; Since , we need the sum of multiples less than N ; Driver code
using System ; class GFG { static long sumAP ( long n , long d ) { n /= d ; return ( n ) * ( 1 + n ) * d / 2 ; } static long sumMultiples ( long n ) { n -- ; return sumAP ( n , 3 ) + sumAP ( n , 7 ) - sumAP ( n , 21 ) ; } static public void Main ( String [ ] args ) { long n = 24 ; Console . WriteLine ( sumMultiples ( n ) ) ; } }
Check whether product of digits at even places is divisible by sum of digits at odd place of a number | C # implementation of the above approach ; below function checks whether product of digits at even places is divisible by K ; if size is even ; if size is odd ; Driver code
using System ; class GFG { static bool productSumDivisible ( int n , int size ) { int sum = 0 , product = 1 ; while ( n > 0 ) { if ( size % 2 == 0 ) { product *= n % 10 ; } else { sum += n % 10 ; } n = n / 10 ; size -- ; } if ( product % sum == 0 ) { return true ; } return false ; } public static void Main ( ) { int n = 1234 ; int len = 4 ; if ( productSumDivisible ( n , len ) ) Console . WriteLine ( " TRUE " ) ; else Console . WriteLine ( " FALSE " ) ; } }
Check whether product of digits at even places is divisible by sum of digits at odd place of a number | C # implementation of the above approach ; Below function checks whether product of digits at even places is divisible by sum of digits at odd places ; Converting integer to string ; Traveersing the string ; Driver code
using System ; class GFG { static bool productSumDivisible ( int n ) { int sum = 0 ; int product = 1 ; string num = n . ToString ( ) ; for ( int i = 0 ; i < num . Length ; i ++ ) { if ( i % 2 != 0 ) { product = product * ( int ) Char . GetNumericValue ( num [ i ] ) ; } else { sum = sum + ( int ) Char . GetNumericValue ( num [ i ] ) ; } } if ( product % sum == 0 ) { return true ; } else { return false ; } } static public void Main ( ) { int n = 1234 ; if ( productSumDivisible ( n ) ) { Console . WriteLine ( " TRUE " ) ; } else { Console . WriteLine ( " FALSE " ) ; } } }
GCD of a number raised to some power and another number | C # program to find GCD of a ^ n and b . ; Returns GCD of a ^ n and b . ; Driver code
using System ; class GFG { public static long gcd ( long a , long b ) { if ( a == 0 ) { return b ; } return gcd ( b % a , a ) ; } public static long powGCD ( long a , long n , long b ) { for ( int i = 0 ; i < n ; i ++ ) { a = a * a ; } return gcd ( a , b ) ; } public static void Main ( string [ ] args ) { long a = 10 , b = 5 , n = 2 ; Console . WriteLine ( powGCD ( a , n , b ) ) ; } }
Position after taking N steps to the right and left in an alternate manner | C # program to find the last coordinate where it ends his journey ; Function to return the last destination ; Driver Code
using System ; class GFG { public static int lastCoordinate ( int n , int a , int b ) { return ( ( n + 1 ) / 2 ) * a - ( n / 2 ) * b ; } public static void Main ( string [ ] args ) { int n = 3 , a = 5 , b = 2 ; Console . WriteLine ( lastCoordinate ( n , a , b ) ) ; } }
Smallest number greater than or equal to N divisible by K | C # implementation of the above approach ; Function to find the smallest number greater than or equal to N that is divisible by k ; Driver Code
public class GFG { static int findNum ( int N , int K ) { int rem = ( N + K ) % K ; if ( rem == 0 ) return N ; else return N + K - rem ; } static void Main ( ) { int N = 45 , K = 6 ; System . Console . WriteLine ( " Smallest ▁ number ▁ greater ▁ than ▁ or ▁ equal ▁ to ▁ " + N + " that is divisible by " + K + " ▁ is ▁ " + findNum ( N , K ) ) ; } }
Sum and Product of digits in a number that divide the number | C # implementation of the above approach ; Print the sum and product of digits that divides the number . ; Fetching each digit of the number ; Checking if digit is greater than 0 and can divides n . ; Driver code
using System ; class GFG { static void countDigit ( int n ) { int temp = n , sum = 0 , product = 1 ; while ( temp != 0 ) { int d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 ) { sum += d ; product *= d ; } } Console . Write ( " Sum ▁ = ▁ " + sum ) ; Console . Write ( " Product = " } public static void Main ( ) { int n = 1012 ; countDigit ( n ) ; } }
Largest number smaller than or equal to N divisible by K | C # implementation of the above approach ; Function to find the largest number smaller than or equal to N that is divisible by k ; Driver code
using System ; class GFG { static int findNum ( int N , int K ) { int rem = N % K ; if ( rem == 0 ) return N ; else return N - rem ; } public static void Main ( ) { int N = 45 , K = 6 ; Console . Write ( " Largest ▁ number ▁ smaller ▁ " + " than ▁ or ▁ equal ▁ to ▁ " + N + " that is divisible by " + K + " ▁ is ▁ " + findNum ( N , K ) ) ; } }
Check if any permutation of a number is divisible by 3 and is Palindromic | C # implementation of the above approach ; Function to check if any permutation of a number is divisible by 3 and is Palindromic ; Hash array to store frequency of digits of n ; traverse the digits of integer and store their frequency ; Calculate the sum of digits simultaneously ; Check if number is not divisible by 3 ; If more than one digits have odd frequency , palindromic permutation not possible ; Driver Code
using System ; class GFG { static bool isDivisiblePalindrome ( int n ) { int [ ] hash = new int [ 10 ] ; int digitSum = 0 ; while ( n != 0 ) { digitSum += n % 10 ; hash [ n % 10 ] ++ ; n /= 10 ; } if ( digitSum % 3 != 0 ) return false ; int oddCount = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( hash [ i ] % 2 != 0 ) oddCount ++ ; } if ( oddCount > 1 ) return false ; else return true ; } static public void Main ( ) { int n = 34734 ; Console . WriteLine ( isDivisiblePalindrome ( n ) ) ; } }