codeparrot/xlcost-text-to-code huggingface dataset:
Maximum length possible by cutting N given woods into at least K pieces | C # program to implement the above approach ; Function to check if it is possible to cut woods into K pieces of length len ; Stores count of pieces having length equal to K ; Traverse wood [ ] array ; Update count ; Function to find the maximum value of L ; Stores minimum possible of L ; Stores maximum possible value of L ; Apply binary search over the range [ left , right ] ; Stores mid value of left and right ; If it is possible to cut woods into K pieces having length of each piece equal to mid ; Update left ; Update right ; Driver Code
using System ; using System . Linq ; class GFG { static bool isValid ( int [ ] wood , int N , int len , int K ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { count += wood [ i ] / len ; } return count >= K ; } static int findMaxLen ( int [ ] wood , int N , int K ) { int left = 1 ; int right = wood . Max ( ) ; while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( isValid ( wood , N , mid , K ) ) { left = mid + 1 ; } else { right = mid - 1 ; } } return right ; } public static void Main ( String [ ] args ) { int [ ] wood = { 5 , 9 , 7 } ; int N = wood . Length ; int K = 4 ; Console . Write ( findMaxLen ( wood , N , K ) ) ; } }
Count quadruplets with sum K from given array | C # program for the above approach ; Function to return the number of quadruplets with the given sum ; Initialize variables ; Initialize answer ; All possible first elements ; All possible second elements ; All possible third elements ; All possible fourth elements ; Increment counter by 1 if quadruplet sum is S ; Return the final count ; Driver Code ; Given array arr [ ] ; Given sum S ; Function Call
class GFG { static int countSum ( int [ ] a , int n , int sum ) { int i , j , k , l ; int count = 0 ; for ( i = 0 ; i < n - 3 ; i ++ ) { for ( j = i + 1 ; j < n - 2 ; j ++ ) { for ( k = j + 1 ; k < n - 1 ; k ++ ) { for ( l = k + 1 ; l < n ; l ++ ) { if ( a [ i ] + a [ j ] + a [ k ] + a [ l ] == sum ) count ++ ; } } } } return count ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 3 , 1 , 2 , 4 } ; int S = 13 ; int N = arr . Length ; System . Console . Write ( countSum ( arr , N , S ) ) ; } }
Minimum adjacent swaps to group similar characters together | C # program for the above approach ; Function to find minimum adjacent swaps required to make all the same character adjacent ; Initialize answer ; Create a 2D array of size 26 ; Traverse the String ; Get character ; Append the current index in the corresponding vector ; Traverse each character from a to z ; Add difference of adjacent index ; Return answer ; Driver Code ; Given String ; Size of String ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int minSwaps ( String S , int n ) { int swaps = 0 ; List < int > [ ] arr = new List < int > [ 26 ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) arr [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int pos = S [ i ] - ' a ' ; arr [ pos ] . Add ( i ) ; } for ( char ch = ' a ' ; ch <= ' z ' ; ++ ch ) { int pos = ch - ' a ' ; for ( int i = 1 ; i < arr [ pos ] . Count ; ++ i ) { swaps += Math . Abs ( arr [ pos ] [ i ] - arr [ pos ] [ i - 1 ] - 1 ) ; } } return swaps ; } public static void Main ( String [ ] args ) { String S = " abbccabbcc " ; int N = S . Length ; Console . Write ( minSwaps ( S , N ) ) ; } }
Construct a graph which does not contain any pair of adjacent nodes with same value | C # program for the above approach ; Function that prints the edges of the generated graph ; First print connections stored in store [ ] ; Check if there is more than one occurrence of 1 st unique element ; Print all other occurrence of 1 st unique element with second unique element ; Function to construct the graph such that the every adjacent nodes have different value ; Stores pair of edges formed ; Stores first unique occurrence ; Check for the second unique occurrence ; Store indices of 2 nd unique occurrence ; To check if arr has only 1 unique element or not ; Store the connections of all unique elements with Node 1 ; If value at node ( i + 1 ) is same as value at Node 1 then store its indices ; If count is zero then it 's not  possible to construct the graph ; If more than 1 unique element is present ; Print the edges ; Driver Code ; Given array having node values ; Function Call
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 void printConnections ( List < pair > store , List < int > ind , int ind1 ) { foreach ( pair pr in store ) { Console . Write ( pr . first + " ▁ " + pr . second + " STRNEWLINE " ) ; } if ( ind . Count != 0 ) { foreach ( int x in ind ) { Console . Write ( ind1 + " ▁ " + ( x + 1 ) + " STRNEWLINE " ) ; } } } static void constructGraph ( char [ ] arr , int N ) { List < int > ind = new List < int > ( ) ; List < pair > store = new List < pair > ( ) ; char x = arr [ 0 ] ; int count = 0 ; int ind1 = - 1 ; for ( int i = 1 ; i <= N - 1 ; ++ i ) { if ( arr [ i ] != x ) { ind1 = i + 1 ; count ++ ; store . Add ( new pair ( 1 , i + 1 ) ) ; } else { ind . Add ( i ) ; } } if ( count == 0 ) { Console . Write ( " Not ▁ Possible " ) ; } else { Console . Write ( " Possible " + " STRNEWLINE " ) ; printConnections ( store , ind , ind1 ) ; } } public static void Main ( String [ ] args ) { int N = 5 ; char [ ] arr = { ' a ' , ' b ' , ' a ' , ' b ' , ' c ' } ; constructGraph ( arr , N ) ; } }
Minimum substring flips required to convert given binary string to another | C # program for the above approach ; Function that finds the minimum number of operations required such that string A and B are the same ; Stores the count of steps ; Stores the last index whose bits are not same ; Iterate until both string are unequal ; Check till end of string to find rightmost unequals bit ; Update the last index ; Flipping characters up to the last index ; Flip the bit ; Increasing steps by one ; Print the count of steps ; Driver Code ; Given strings A and B ; Function Call
using System ; class GFG { static void findMinimumOperations ( string a , string b ) { int step = 0 ; int last_index = 0 ; while ( a . Equals ( b ) == false ) { for ( int i = 0 ; i < a . Length ; i ++ ) { if ( a [ i ] != b [ i ] ) { last_index = i ; } } char [ ] ch = a . ToCharArray ( ) ; for ( int i = 0 ; i <= last_index ; i ++ ) { if ( ch [ i ] == '0' ) { ch [ i ] = '1' ; } else { ch [ i ] = '0' ; } } a = new string ( ch ) ; step ++ ; } Console . WriteLine ( step ) ; } public static void Main ( ) { string A = "101010" ; string B = "110011" ; findMinimumOperations ( A , B ) ; } }
Count all disjoint pairs having absolute difference at least K from a given array | C # program for the above approach ; Function to check if it is possible to form M pairs with abs diff at least K ; Traverse the array over [ 0 , M ] ; If valid index ; Return 1 ; Function to count distinct pairs with absolute difference atleast K ; Stores the count of all possible pairs ; Initialize left and right ; Sort the array ; Perform Binary Search ; Find the value of mid ; Check valid index ; Update ans ; Print the answer ; Driver Code ; Given array arr [ ] ; Given difference K ; Size of the array ; Function call
using System ; class GFG { static int isValid ( int [ ] arr , int n , int m , int d ) { for ( int i = 0 ; i < m ; i ++ ) { if ( Math . Abs ( arr [ n - m + i ] - arr [ i ] ) < d ) { return 0 ; } } return 1 ; } static void countPairs ( int [ ] arr , int N , int K ) { int ans = 0 ; int left = 0 , right = N / 2 + 1 ; Array . Sort ( arr ) ; while ( left < right ) { int mid = ( left + right ) / 2 ; if ( isValid ( arr , N , mid , K ) == 1 ) { ans = mid ; left = mid + 1 ; } else right = mid - 1 ; } Console . WriteLine ( ans ) ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 5 } ; int K = 2 ; int N = arr . Length ; countPairs ( arr , N , K ) ; } }
Minimum common element in subarrays of all possible lengths | C # program to implement the above approach ; Function to find maximum distance between every two element ; Stores index of last occurence of each array element ; Initialize temp [ ] with - 1 ; Traverse the array ; If array element has not occurred previously ; Update index in temp ; Otherwise ; Compare temp [ a [ i ] ] with distance from its previous occurence and store the maximum ; Compare temp [ i ] with distance of its last occurence from the end of the array and store the maximum ; Function to find the minimum common element in subarrays of all possible lengths ; Function call to find a the maximum distance between every pair of repetition ; Initialize ans [ ] to - 1 ; Check if subarray of length temp [ i ] contains i as one of the common elements ; Find the minimum of all common elements ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void max_distance ( int [ ] a , int [ ] temp , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { temp [ i ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( ! mp . ContainsKey ( a [ i ] ) ) temp [ a [ i ] ] = i + 1 ; else temp [ a [ i ] ] = Math . Max ( temp [ a [ i ] ] , i - mp [ a [ i ] ] ) ; if ( mp . ContainsKey ( a [ i ] ) ) { mp [ a [ i ] ] = i ; } else { mp . Add ( a [ i ] , i ) ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( temp [ i ] != - 1 ) { if ( mp . ContainsKey ( i ) ) { temp [ i ] = Math . Max ( temp [ i ] , n - mp [ i ] ) ; } else { temp [ i ] = Math . Max ( temp [ i ] , n ) ; } } } } static void min_comm_ele ( int [ ] a , int [ ] ans , int [ ] temp , int n ) { max_distance ( a , temp , n ) ; for ( int i = 1 ; i <= n ; i ++ ) { ans [ i ] = - 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( temp [ i ] >= 0 && ans [ temp [ i ] ] == - 1 ) ans [ temp [ i ] ] = i ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( i > 1 && ans [ i - 1 ] != - 1 ) { if ( ans [ i ] == - 1 ) ans [ i ] = ans [ i - 1 ] ; else ans [ i ] = Math . Min ( ans [ i ] , ans [ i - 1 ] ) ; } Console . Write ( ans [ i ] + " ▁ " ) ; } } static void Main ( ) { int N = 6 ; int [ ] a = { 1 , 3 , 4 , 5 , 6 , 7 } ; int [ ] temp = new int [ 100 ] ; Array . Fill ( temp , 0 ) ; int [ ] ans = new int [ 100 ] ; Array . Fill ( ans , 0 ) ; min_comm_ele ( a , ans , temp , N ) ; } }
Find a triplet in an array such that arr [ i ] arr [ k ] and i < j < k | C # program to implement the above approach ; Function to find a triplet that satisfy the conditions ; Traverse the given array ; Stores current element ; Stores element just before the current element ; Stores element just after the current element ; Check the given conditions ; Print a triplet ; If no triplet found ; Driver Code
using System ; class GFG { static void FindTrip ( int [ ] arr , int N ) { for ( int i = 1 ; i < N - 1 ; i ++ ) { int p = arr [ i - 1 ] ; int q = arr [ i ] ; int r = arr [ i + 1 ] ; if ( p < q && q > r ) { Console . WriteLine ( ( i - 1 ) + " ▁ " + ( i ) + " ▁ " + ( i + 1 ) ) ; return ; } } Console . WriteLine ( - 1 ) ; } public static void Main ( ) { int [ ] arr = { 2 , 1 , 4 , 3 } ; int N = arr . Length ; FindTrip ( arr , N ) ; } }
Count subarrays having each distinct element occurring at least twice | C # program to implement the above approach ; Function to get the count of subarrays having each element occurring at least twice ; Stores count of subarrays having each distinct element occurring at least twice ; Stores count of unique elements in a subarray ; Store frequency of each element of a subarray ; Traverse the given array ; Count frequency and check conditions for each subarray ; Update frequency ; Check if frequency of arr [ j ] equal to 1 ; Update Count of unique elements ; Update count of unique elements ; If each element of subarray occurs at least twice ; Update cntSub ; Remove all elements from the subarray ; Update cntUnique ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int cntSubarrays ( int [ ] arr , int N ) { int cntSub = 0 ; int cntUnique = 0 ; Dictionary < int , int > cntFreq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j ++ ) { if ( cntFreq . ContainsKey ( arr [ j ] ) ) { var val = cntFreq [ arr [ j ] ] ; cntFreq . Remove ( arr [ j ] ) ; cntFreq . Add ( arr [ j ] , val + 1 ) ; } else { cntFreq . Add ( arr [ j ] , 1 ) ; } if ( cntFreq [ arr [ j ] ] == 1 ) { cntUnique ++ ; } else if ( cntFreq [ arr [ j ] ] == 2 ) { cntUnique -- ; } if ( cntUnique == 0 ) { cntSub ++ ; } } cntFreq . Clear ( ) ; cntUnique = 0 ; } return cntSub ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 2 , 2 , 2 } ; int N = arr . Length ; Console . Write ( cntSubarrays ( arr , N ) ) ; } }
Check if permutation of a given string can be made palindromic by removing at most K characters | C # program to implement the above approach ; Function to check if the string satisfies the given conditions or not ; Stores length of given string ; Stores frequency of each character of str ; Update frequency of current character ; Stores count of distinct character whose frequency is odd ; Traverse the cntFreq [ ] array . ; If frequency of character i is odd ; Update cntOddFreq ; If count of distinct character having odd frequency is <= K + 1 ; Driver Code ; If str satisfy the given conditions
using System ; class GFG { public static bool checkPalinK ( String str , int K ) { int N = str . Length ; int [ ] cntFreq = new int [ 256 ] ; for ( int i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] ] ++ ; } int cntOddFreq = 0 ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( cntFreq [ i ] % 2 == 1 ) { cntOddFreq ++ ; } } if ( cntOddFreq <= ( K + 1 ) ) { return true ; } return false ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; int K = 2 ; if ( checkPalinK ( str , K ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Maximum number of elements that can be removed such that MEX of the given array remains unchanged | C # program for the above approach ; Function to find the maximum number of elements that can be removed ; Initialize hash [ ] with 0 s ; Initialize MEX ; Set hash [ i ] = 1 , if i is present in arr [ ] ; Find MEX from the hash ; Print the maximum numbers that can be removed ; Driver Code ; Given array ; Size of the array ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void countRemovableElem ( int [ ] arr , int N ) { int [ ] hash = new int [ N + 1 ] ; Array . Fill ( hash , 0 ) ; int mex = N + 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] <= N ) hash [ arr [ i ] ] = 1 ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( hash [ i ] == 0 ) { mex = i ; break ; } } Console . WriteLine ( N - ( mex - 1 ) ) ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 5 , 1 , 6 } ; int N = arr . Length ; countRemovableElem ( arr , N ) ; } }
Print all positions of a given string having count of smaller characters equal on both sides | C # program to implement the above approach ; Function to find indexes of the given string that satisfy the condition ; Stores length of given string ; Stores frequency of each character of str ; Update frequency of current character ; cntLeftFreq [ i ] Stores frequency of characters present on the left side of index i . ; Traverse the given string ; Stores count of smaller characters on left side of i . ; Stores count of smaller characters on Right side of i . ; Traverse smaller characters on left side of index i . ; Update cntLeft ; Update cntRight ; Update cntLeftFreq [ str [ i ] ] ; If count of smaller elements on both sides equal ; Print current index ; ; Driver Code
using System ; class GFG { static void printIndexes ( char [ ] str ) { int N = str . Length ; int [ ] cntFreq = new int [ 256 ] ; for ( int i = 0 ; i < N ; i ++ ) { cntFreq [ str [ i ] ] ++ ; } int [ ] cntLeftFreq = new int [ 256 ] ; for ( int i = 0 ; i < N ; i ++ ) { int cntLeft = 0 ; int cntRight = 0 ; for ( int j = str [ i ] - 1 ; j >= 0 ; j -- ) { cntLeft += cntLeftFreq [ j ] ; cntRight += cntFreq [ j ] - cntLeftFreq [ j ] ; } cntLeftFreq [ str [ i ] ] ++ ; if ( cntLeft == cntRight && cntLeft != 0 ) { Console . Write ( i + " ▁ " ) ; } } } public static void Main ( ) { string str = " aabacdabbb " ; printIndexes ( str . ToCharArray ( ) ) ; } }
Count three | C # program to implement the above approach ; Function to count three - digit numbers having difference x with its reverse ; If x is not multiple of 99 ; No solution exists ; Generate all possible pairs of digits [ 1 , 9 ] ; If any pair is obtained with difference x / 99 ; Increase count ; Return the count ; Driver Code
using System ; class GFG { static int Count_Number ( int x ) { int ans = 0 ; if ( x % 99 != 0 ) { ans = - 1 ; } else { int diff = x / 99 ; for ( int i = 1 ; i < 10 ; i ++ ) { for ( int j = 1 ; j < 10 ; j ++ ) { if ( ( i - j ) == diff ) { ans += 10 ; } } } } return ans ; } public static void Main ( ) { int x = 792 ; Console . WriteLine ( Count_Number ( x ) ) ; } }
Check if a point having maximum X and Y coordinates exists or not | C # program for the above approach ; Initialize INF as inifnity ; Function to return the point having maximum X and Y coordinates ; Base Case ; Stores if valid point exists ; If point arr [ i ] is valid ; Check for the same point ; Check for a valid point ; If current point is the required point ; Otherwise ; Function to find the required point ; Stores the point with maximum X and Y - coordinates ; If no required point exists ; Driver Code ; Given array of points ; Function Call
using System ; class GFG { static int INF = int . MaxValue ; static int [ ] findMaxPoint ( int [ , ] arr , int i , int n ) { if ( i == n ) return new int [ ] { INF , INF } ; bool flag = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( j == i ) continue ; if ( arr [ j , 0 ] >= arr [ i , 0 ] arr [ j , 1 ] >= arr [ i , 1 ] ) { flag = false ; break ; } } int [ ] ans = new int [ arr . GetLength ( 1 ) ] ; if ( flag ) { for ( int k = 0 ; k < ans . GetLength ( 0 ) ; k ++ ) ans [ k ] = arr [ i , k ] ; return ans ; } return findMaxPoint ( arr , i + 1 , n ) ; } static void findMaxPoints ( int [ , ] arr , int n ) { int [ ] ans = findMaxPoint ( arr , 0 , n ) ; if ( ans [ 0 ] == INF ) { Console . WriteLine ( - 1 ) ; } else { Console . WriteLine ( " ( " + ans [ 0 ] + " ▁ " + ans [ 1 ] + " ) " ) ; } } public static void Main ( String [ ] args ) { int [ , ] arr = new int [ , ] { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; int N = arr . GetLength ( 0 ) ; findMaxPoints ( arr , N ) ; } }
Check if a point having maximum X and Y coordinates exists or not | C # program for the above approach ; Function to find the point having max X and Y coordinates ; Initialize maxX and maxY ; Length of the given array ; Get maximum X & Y coordinates ; Check if the required point i . e . , ( maxX , maxY ) is present ; If point with maximum X and Y coordinates is present ; If no such point exists ; Driver Code ; Given array of points ; Print answer
using System ; class GFG { static void findMaxPoint ( int [ , ] arr ) { int maxX = int . MinValue ; int maxY = int . MinValue ; int n = arr . GetLength ( 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { maxX = Math . Max ( maxX , arr [ i , 0 ] ) ; maxY = Math . Max ( maxY , arr [ i , 1 ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( maxX == arr [ i , 0 ] && maxY == arr [ i , 1 ] ) { Console . WriteLine ( " ( " + maxX + " , ▁ " + maxY + " ) " ) ; return ; } } Console . WriteLine ( - 1 ) ; } public static void Main ( String [ ] args ) { int [ , ] arr = new int [ , ] { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; findMaxPoint ( arr ) ; } }
Search insert position of K in a sorted array | C # program for the above approach ; Function to find insert position of K ; Traverse the array ; If K is found ; If current array element exceeds K ; If all elements are smaller than K ; Driver Code
using System ; class GFG { static int find_index ( int [ ] arr , int n , int K ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == K ) return i ; else if ( arr [ i ] > K ) return i ; return n ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 5 , 6 } ; int n = arr . Length ; int K = 2 ; Console . WriteLine ( find_index ( arr , n , K ) ) ; } }
Count subarrays for every array element in which they are the minimum | Set 2 | C # program for the above approach ; Function to calculate total number of sub - arrays for each element where that element is occurring as the minimum element ; Map for storing the number of sub - arrays for each element ; Traverse over all possible subarrays ; Minimum in each subarray ; Print the result ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void minSubarray ( int [ ] arr , int N ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int mini = int . MaxValue ; for ( int j = i ; j < N ; j ++ ) { mini = Math . Min ( mini , arr [ j ] ) ; if ( mp . ContainsKey ( mini ) ) { mp [ mini ] = mp [ mini ] + 1 ; } else { mp . Add ( mini , 1 ) ; } } } for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( mp [ arr [ i ] ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 , 4 } ; int N = arr . Length ; minSubarray ( arr , N ) ; } }
Count subarrays for every array element in which they are the minimum | Set 2 | C # program for the above approach ; Function to count subarrays for each element where it is the minimum ; For the length of strictly larger numbers on the left of A [ i ] ; Storing x in result [ i ] ; For the length of strictly larger numbers on the right of A [ i ] ; Store x * y in result array ; Print the result ; Driver Code ; Function Call
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 void minSubarray ( int [ ] arr , int N ) { int [ ] result = new int [ N ] ; Stack < pair > l = new Stack < pair > ( ) ; Stack < pair > r = new Stack < pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int count = 1 ; while ( l . Count != 0 && l . Peek ( ) . first > arr [ i ] ) { count += l . Peek ( ) . second ; l . Pop ( ) ; } l . Push ( new pair ( arr [ i ] , count ) ) ; result [ i ] = count ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { int count = 1 ; while ( r . Count != 0 && r . Peek ( ) . first >= arr [ i ] ) { count += r . Peek ( ) . second ; r . Pop ( ) ; } r . Push ( new pair ( arr [ i ] , count ) ) ; result [ i ] *= count ; } for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( result [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 , 4 } ; int N = arr . Length ; minSubarray ( arr , N ) ; } }
Count Full Prime numbers in a given range | C # program to implement the above approach ; Function to check if a number is prime or not ; If a divisor of n exists ; Function to check if a number is Full Prime or not ; If n is not a prime ; Otherwise ; Extract digit ; If any digit of n is non - prime ; Function to print count of Full Primes in a range [ L , R ] ; Stores count of full primes ; Check if i is full prime ; Driver Code ; Stores count of full primes
using System ; class GFG { static bool isPrime ( int num ) { if ( num <= 1 ) return false ; for ( int i = 2 ; i * i <= num ; i ++ ) if ( num % i == 0 ) return false ; return true ; } static bool isFulPrime ( int n ) { if ( ! isPrime ( n ) ) return false ; else { while ( n > 0 ) { int rem = n % 10 ; if ( ! ( rem == 2 rem == 3 rem == 5 rem == 7 ) ) return false ; n = n / 10 ; } } return true ; } static int countFulPrime ( int L , int R ) { int cnt = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( ( i % 2 ) != 0 && isFulPrime ( i ) ) { cnt ++ ; } } return cnt ; } public static void Main ( String [ ] args ) { int L = 1 , R = 100 ; int ans = 0 ; if ( L < 3 ) ans ++ ; Console . WriteLine ( ans + countFulPrime ( L , R ) ) ; } }