codeparrot/xlcost-text-to-code huggingface dataset:
Check if a string can be split into substrings starting with N followed by N characters | C # program to implement the above approach ; Function to check if the given can be split into desired substrings ; Length of the string ; Traverse the string ; Extract the digit ; Check if the extracted number does not exceed the remaining length ; Check for the remaining string ; If generating desired substrings is not possible ; Driver code
using System ; class GFG { public static bool helper ( String s , int pos ) { int len = s . Length ; if ( pos >= len ) return true ; if ( ! char . IsDigit ( s [ pos ] ) ) return false ; int num = 0 ; for ( int i = pos ; i < len ; i ++ ) { num = num * 10 + s [ pos ] - '0' ; if ( i + 1 + num > len ) return false ; if ( helper ( s , i + 1 + num ) ) return true ; } return false ; } public static void Main ( String [ ] args ) { String s = "123abc4db1c " ; if ( helper ( s , 0 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Represent K as sum of N | C # program for the above problem ; Array to store the N - Bonacci series ; Function to express K as sum of several N_bonacci numbers ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static long [ ] N_bonacci = new long [ 100 ] ; static void N_bonacci_nums ( long n , long k ) { N_bonacci [ 0 ] = 1 ; for ( int i = 1 ; i <= 50 ; ++ i ) { for ( int j = i - 1 ; j >= i - k && j >= 0 ; -- j ) N_bonacci [ i ] += N_bonacci [ j ] ; } List < long > ans = new List < long > ( ) ; for ( int i = 50 ; i >= 0 ; -- i ) if ( n - N_bonacci [ i ] >= 0 ) { ans . Add ( N_bonacci [ i ] ) ; n -= N_bonacci [ i ] ; } if ( ans . Count == 1 ) ans . Add ( 0 ) ; Console . WriteLine ( ans . Count ) ; for ( int i = 0 ; i < ans . Count ; ++ i ) Console . Write ( ans [ i ] + " , ▁ " ) ; } static void Main ( ) { long n = 21 , k = 5 ; N_bonacci_nums ( n , k ) ; } }
Divide N into K parts in the form ( X , 2 X , ... , KX ) for some value of X | Java program for the above approach ; Function to find the division ; Calculating value of x1 ; Print - 1 if division is not possible ; Get the first number ie x1 then successively multiply it by x1 k times by index number to get the required answer ; Driver Code ; Given N and K ; Function Call
import java . . * ; class GFG { static void solve ( int n , int k ) { int x1 , d ; d = k * ( k + 1 ) ; if ( ( 2 * n ) % d != 0 ) { System . out . print ( " - 1" ) ; return ; } x1 = 2 * n / d ; for ( int i = 1 ; i <= k ; i ++ ) { System . out . print ( x1 * i + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int n = 10 , k = 4 ; solve ( n , k ) ; } }
Bitonic string | C # program for the above approach ; Function to check if the given String is bitonic ; Check for increasing sequence ; If end of String has been reached ; Check for decreasing sequence ; If the end of String hasn 't  been reached ; Return true if bitonic ; Driver Code ; Given String ; Function call
using System ; class GFG { static int checkBitonic ( char [ ] s ) { int i , j ; for ( i = 1 ; i < s . Length ; i ++ ) { if ( s [ i ] > s [ i - 1 ] ) continue ; if ( s [ i ] <= s [ i - 1 ] ) break ; } if ( i == s . Length - 1 ) return 1 ; for ( j = i + 1 ; j < s . Length ; j ++ ) { if ( s [ j ] < s [ j - 1 ] ) continue ; if ( s [ j ] >= s [ j - 1 ] ) break ; } i = j ; if ( i != s . Length ) return 0 ; return 1 ; } public static void Main ( String [ ] args ) { String s = " abcdfgcba " ; Console . Write ( ( checkBitonic ( s . ToCharArray ( ) ) == 1 ) ? " YES " : " NO " ) ; } }
Find pair with maximum GCD for integers in range 2 to N | C # program to find a pair of integers less than or equal to N such that their GCD is maximum ; Function to find the required pair whose GCD is maximum ; If N is even ; If N is odd ; Driver Code
using System ; class GFG { static void solve ( int N ) { if ( N % 2 == 0 ) { Console . Write ( N / 2 + " ▁ " + N + " STRNEWLINE " ) ; } else { Console . Write ( ( N - 1 ) / 2 + " ▁ " + ( N - 1 ) + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int N = 10 ; solve ( N ) ; } }
Find initial sequence that produces a given Array by cyclic increments upto index P | C # program to implement the above approach ; Function to generate and return the required initial arrangement ; Store the minimum element in the array ; Store the number of increments ; Subtract mi - 1 from every index ; Start from the last index which had been incremented ; Stores the index chosen to distribute its element ; Traverse the array cyclically and find the index whose element was distributed ; If any index has its value reduced to 0 ; Index whose element was distributed ; Store the number of increments at the starting index ; Print the original array ; Driver Code
using System ; using System . Linq ; class GFG { static void findArray ( int [ ] a , int n , int P ) { int mi = a . Min ( ) ; int ctr = 0 ; mi = Math . Max ( 0 , mi - 1 ) ; int i ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] -= mi ; ctr += mi ; } i = P - 1 ; int start = - 1 ; while ( true ) { if ( a [ i ] == 0 ) { start = i ; break ; } a [ i ] -= 1 ; ctr += 1 ; i = ( i - 1 + n ) % n ; } a [ start ] = ctr ; for ( i = 0 ; i < n ; i ++ ) { Console . Write ( a [ i ] + " , ▁ " ) ; } } public static void Main ( String [ ] args ) { int N = 5 ; int P = 2 ; int [ ] arr = { 3 , 2 , 0 , 2 , 7 } ; findArray ( arr , N , P ) ; } }
Generate a unique Array of length N with sum of all subarrays divisible by N | C # program for the above approach ; Function to print the required array ; Print the array ; Driver code
using System ; class GFG { static void makeArray ( int [ ] a , int n ) { for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( i * n + " ▁ " ) ; } public static void Main ( ) { int N = 6 ; int [ ] arr = new int [ N ] ; makeArray ( arr , N ) ; } }
Find elements in a given range having at least one odd divisor | C # program to print all numbers with least one odd factor in the given range ; Function to prints all numbers with at least one odd divisor ; Check if the number is not a power of two ; Driver Code
using System ; class GFG { static int printOddFactorNumber ( int n , int m ) { for ( int i = n ; i <= m ; i ++ ) { if ( ( i > 0 ) && ( ( i & ( i - 1 ) ) != 0 ) ) Console . Write ( i + " ▁ " ) ; } return 0 ; } public static void Main ( ) { int N = 2 , M = 10 ; printOddFactorNumber ( N , M ) ; } }
Print the first N terms of the series 6 , 28 , 66 , 120 , 190 , 276 , ... | C # program for the above approach ; Function to print the series ; Initialise the value of k with 2 ; Iterate from 1 to n ; Print each number ; Increment the value of K by 2 for next number ; Driver code ; Given number N ; Function call
using System ; class GFG { static void printSeries ( int n ) { int k = 2 ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( k * ( 2 * k - 1 ) + " ▁ " ) ; k += 2 ; } Console . WriteLine ( ) ; } public static void Main ( ) { int N = 12 ; printSeries ( N ) ; } }
Mountain Sequence Pattern | C # program for the above approach ; Function to print pattern recursively ; Base Case ; Condition to check row limit ; Condition for assigning gaps ; Conditions to print * ; Else print ' ▁ ' ; Recursive call for columns ; Recursive call for rows ; Driver code ; Given Number N ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int k1 = 2 ; static int k2 = 2 ; static int gap = 5 ; static int printPattern ( int i , int j , int n ) { if ( j >= n ) { k1 = 2 ; k2 = 2 ; k1 -- ; k2 ++ ; if ( i == 2 ) { k1 = 0 ; k2 = n - 1 ; } return 0 ; } if ( i >= 3 ) { return 1 ; } if ( j > k2 ) { k1 += gap ; k2 += gap ; } if ( j >= k1 && j <= k2 i == 2 ) { Console . Write ( " * " ) ; } else { Console . Write ( " ▁ " ) ; } if ( printPattern ( i , j + 1 , n ) == 1 ) { return 1 ; } Console . WriteLine ( ) ; return printPattern ( i + 1 , 0 , n ) ; } static void Main ( ) { int N = 3 ; printPattern ( 0 , 0 , N * 5 ) ; } }
Build a DFA to accept Binary strings that starts or ends with "01" | C # program to check if a string either starts or ends with 01 ; Function for transition state A ; State transition to B if the character is 0 ; State transition to D if the character is 1 ; Function for transition state B ; Check if the string has ended ; State transition to C if the character is 1 ; State transition to D if the character is 0 ; Function for transition state C ; Function for transition state D ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Function for transition state E ; State transition to E if the character is 0 ; State transition to F if the character is 1 ; Function for transition state F ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void checkstateA ( string n ) { if ( n [ 0 ] == '0' ) stateB ( n . Substring ( 1 ) ) ; else stateD ( n . Substring ( 1 ) ) ; } static void stateB ( string n ) { if ( n . Length == 0 ) { Console . Write ( " string ▁ not ▁ accepted " ) ; } else { if ( n [ 0 ] == '1' ) stateC ( n . Substring ( 1 ) ) ; else stateD ( n . Substring ( 1 ) ) ; } } static void stateC ( string n ) { Console . Write ( " string ▁ accepted " ) ; } static void stateD ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ not ▁ accepted " ) ; else { if ( n [ 0 ] == '1' ) stateD ( n . Substring ( 1 ) ) ; else stateE ( n . Substring ( 1 ) ) ; } } static void stateE ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ not ▁ accepted " ) ; else { if ( n [ 0 ] == '0' ) stateE ( n . Substring ( 1 ) ) ; else stateF ( n . Substring ( 1 ) ) ; } } static void stateF ( string n ) { if ( n . Length == 0 ) Console . Write ( " string ▁ accepted " ) ; else { if ( n [ 0 ] == '1' ) stateD ( n . Substring ( 1 ) ) ; else stateE ( n . Substring ( 1 ) ) ; } } public static void Main ( string [ ] args ) { string n = "0100101" ; checkstateA ( n ) ; } }
Find the Nth Hogben Numbers | C # program to print N - th Hogben Number ; Function returns N - th Hogben Number ; Driver code
using System ; class GFG { public static int HogbenNumber ( int a ) { int p = ( int ) ( Math . Pow ( a , 2 ) - a + 1 ) ; return p ; } public static void Main ( ) { int N = 10 ; Console . Write ( HogbenNumber ( N ) ) ; } }
Check if left and right shift of any string results into given string | C # program to check if left and right shift of any string results into the given string ; Function to check string exist or not as per above approach ; Check if any character at position i and i + 2 are not equal then string doesnot exist ; Driver Code
using System ; class GFG { public static void check_string_exist ( String S ) { int size = S . Length ; bool check = true ; for ( int i = 0 ; i < size ; i ++ ) { if ( S [ i ] != S [ ( i + 2 ) % size ] ) { check = false ; break ; } } if ( check ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( String [ ] args ) { String S = " papa " ; check_string_exist ( S ) ; } }
Cumulative product of digits of all numbers in the given range | C # program to print the product of all numbers in range L and R ; Function to get product of digits ; Function to find the product of digits of all natural numbers in range L to R ; Iterate between L to R ; Driver Code
using System ; class GFG { static int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } static int productinRange ( int l , int r ) { if ( r - l > 9 ) return 0 ; else { int p = 1 ; for ( int i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } public static void Main ( String [ ] args ) { int l = 11 , r = 15 ; Console . Write ( productinRange ( l , r ) + " STRNEWLINE " ) ; l = 1 ; r = 15 ; Console . Write ( productinRange ( l , r ) ) ; } }
Check whether the string can be printed using same row of qwerty keypad | C # program to check whether the string can be printed using same row of qwerty keypad ; Function to find the row of the character in the qwerty keypad ; Sets to include the characters from the same row of the qwerty keypad ; Condition to check the row of the current character of the string ; Function to check the characters are from the same row of the qwerty keypad ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int checkQwertyRow ( char x ) { char [ ] first_row1 = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , ' - ' , ' = ' } ; HashSet < char > first_row = new HashSet < char > ( first_row1 ) ; char [ ] second_row1 = { ' Q ' , ' W ' , ' E ' , ' R ' , ' T ' , ' Y ' , ' U ' , ' I ' , ' O ' , ' P ' , ' [ ' , ' ] ' , ' q ' , ' w ' , ' e ' , ' r ' , ' t ' , ' y ' , ' u ' , ' i ' , ' o ' , ' p ' } ; HashSet < char > second_row = new HashSet < char > ( second_row1 ) ; char [ ] third_row1 = { ' A ' , ' S ' , ' D ' , ' F ' , ' G ' , ' H ' , ' J ' , ' K ' , ' L ' , ' ; ' , ' : ' , ' a ' , ' s ' , ' d ' , ' f ' , ' g ' , ' h ' , ' j ' , ' k ' , ' l ' } ; HashSet < char > third_row = new HashSet < char > ( third_row1 ) ; char [ ] fourth_row1 = { ' Z ' , ' X ' , ' C ' , ' V ' , ' B ' , ' N ' , ' M ' , ' , ' , ' . ' , ' / ' , ' z ' , ' x ' , ' c ' , ' v ' , ' b ' , ' n ' , ' m ' } ; HashSet < char > fourth_row = new HashSet < char > ( fourth_row1 ) ; if ( first_row . Contains ( x ) ) { return 1 ; } else if ( second_row . Contains ( x ) ) { return 2 ; } else if ( third_row . Contains ( x ) ) { return 3 ; } else if ( fourth_row . Contains ( x ) ) { return 4 ; } return 0 ; } static bool checkValidity ( String str ) { char x = str [ 0 ] ; int row = checkQwertyRow ( x ) ; for ( int i = 0 ; i < str . Length ; i ++ ) { x = str [ i ] ; if ( row != checkQwertyRow ( x ) ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { String str = " GeeksforGeeks " ; if ( checkValidity ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Last digit of sum of numbers in the given range in the Fibonacci series | C # program to calculate last digit of the sum of the fibonacci numbers from M to N ; Calculate the sum of the first N fibonacci numbers using Pisano period ; The first two fibonacci numbers ; Base case ; Pisano period for % 10 is 60 ; Checking the remainder ; The loop will range from 2 to two terms after the remainder ; Driver Code
using System ; class GFG { static int fib ( long n ) { int f0 = 0 ; int f1 = 1 ; if ( n == 0 ) return 0 ; if ( n == 1 ) return 1 ; else { int rem = ( int ) ( n % 60 ) ; if ( rem == 0 ) return 0 ; for ( int i = 2 ; i < rem + 3 ; i ++ ) { int f = ( f0 + f1 ) % 60 ; f0 = f1 ; f1 = f ; } int s = f1 - 1 ; return s ; } } public static void Main ( ) { int m = 10087887 ; long n = 2983097899L ; int Final = ( int ) Math . Abs ( fib ( n ) - fib ( m - 1 ) ) ; Console . WriteLine ( Final % 10 ) ; } }
Find N values of X1 , X2 , ... Xn such that X1 < X2 < ... < XN and sin ( X1 ) < sin ( X2 ) < ... < sin ( XN ) | C # program for the above approach ; Function to print all such Xi s . t . all Xi and sin ( Xi ) are strictly increasing ; Till N becomes zero ; Find the value of sin ( ) using inbuilt function ; Increment by 710 ; Driver Code ; Function Call
using System ; class GFG { static void printSinX ( int N ) { int Xi = 0 ; int num = 1 ; while ( N -- > 0 ) { Console . Write ( " X " + num + " ▁ = ▁ " + Xi ) ; Console . Write ( " ▁ sin ( X " + num + " ) ▁ = ▁ " ) ; Console . Write ( " { 0 : F6 } " , Math . Sin ( Xi ) ) ; Console . WriteLine ( ) ; num += 1 ; Xi += 710 ; } } public static void Main ( String [ ] args ) { int N = 5 ; printSinX ( N ) ; } }
Sum of all elements in an array between zeros | C # program for the above approach ; Function to find the sum between two zeros in the given array [ ] arr ; To store the sum of element between two zeros ; To store the sum ; Find first index of 0 ; Traverse the given array [ ] arr ; If 0 occurs then add it to [ ] A ; Else add element to the sum ; Print all the sum stored in A ; If there is no such element print - 1 ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void sumBetweenZero ( int [ ] arr , int N ) { int i = 0 ; List < int > A = new List < int > ( ) ; int sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { i ++ ; break ; } } for ( ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { A . Add ( sum ) ; sum = 0 ; } else { sum += arr [ i ] ; } } for ( int j = 0 ; j < A . Count ; j ++ ) { Console . Write ( A [ j ] + " ▁ " ) ; } if ( A . Count == 0 ) Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 0 , 3 , 4 , 0 , 4 , 4 , 0 , 2 , 1 , 4 , 0 , 3 } ; int N = arr . Length ; sumBetweenZero ( arr , N ) ; } }
Find the Nth term of the series 2 , 15 , 41 , 80 , 132. . . | C # program for the above approach ; Recursive function to find Nth term ; Base Case ; Recursive Call according to Nth term of the series ; Driver Code ; Input Nth term ; Function call
using System ; public class GFG { static public int nthTerm ( int N ) { if ( N == 1 ) { return 2 ; } return ( ( N - 1 ) * 13 ) + nthTerm ( N - 1 ) ; } static public void Main ( ) { int N = 17 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Subsequence pair from given Array having all unique and all same elements respectively | C # program for the above approach ; Function to find the maximum length of subsequences with given property ; To store the frequency ; Traverse the array to store the frequency ; M . Count given count of distinct element in [ ] arr ; Traverse map to find max frequency ; Find the maximum length on the basis of two cases in the approach ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void maximumSubsequence ( int [ ] arr , int N ) { Dictionary < int , int > M = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( M . ContainsKey ( arr [ i ] ) ) { M [ arr [ i ] ] = M [ arr [ i ] ] + 1 ; } else { M . Add ( arr [ i ] , 1 ) ; } } int distinct_size = M . Count ; int maxFreq = 1 ; foreach ( KeyValuePair < int , int > m in M ) { maxFreq = Math . Max ( maxFreq , m . Value ) ; } Console . Write ( Math . Max ( Math . Min ( distinct_size , maxFreq - 1 ) , Math . Min ( distinct_size - 1 , maxFreq ) ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 4 , 4 , 4 , 4 , 5 } ; int N = arr . Length ; maximumSubsequence ( arr , N ) ; } }
Total length of string from given Array of strings composed using given characters | C # implementation to find total length of string composed of given characters formed from given Array of strings ; Function to count the total length ; Dictionary for keeping frequency of characters ; Calculate the frequency ; Iterate in the N strings ; Iterates in the string ; Checks if given character of string string appears in it or not ; Adds the length of string if all characters are present ; Return the final result ; Driver code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static int countCharacters ( List < string > strings , string chars ) { int res = 0 ; Dictionary < char , int > freq = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < chars . Length ; i ++ ) { if ( freq . ContainsKey ( chars [ i ] ) ) { freq [ chars [ i ] ] ++ ; } else { freq . Add ( chars [ i ] , freq . GetValueOrDefault ( chars [ i ] , 0 ) + 1 ) ; } } foreach ( string st in strings ) { bool flag = true ; foreach ( char c in st . ToCharArray ( ) ) { if ( ! freq . ContainsKey ( c ) ) { flag = false ; break ; } } if ( flag ) res += st . Length ; } return res ; } public static void Main ( string [ ] args ) { string [ ] tmp = { " hi " , " data " , " geeksforgeeks " } ; List < string > strings = tmp . ToList ( ) ; string chars = " tiadhae " ; Console . Write ( countCharacters ( strings , chars ) ) ; } }
Construct an Array of size N in which sum of odd elements is equal to sum of even elements | C # program to Create an array of size N consisting of distinct elements where sum of odd elements is equal to sum of even elements ; Function to construct the required array ; To confirst half , distinct even numbers ; To consecond half , distinct odd numbers ; Calculate the last number of second half so as to make both the halves equal ; Function to construct the required array ; check if size is multiple of 4 then array exist ; function call to conarray ; Driver code
using System ; class GFG { static void arrayConstruct ( int N ) { for ( int i = 2 ; i <= N ; i = i + 2 ) Console . Write ( i + " ▁ " ) ; for ( int i = 1 ; i < N - 1 ; i = i + 2 ) Console . Write ( i + " ▁ " ) ; Console . Write ( N - 1 + ( N / 2 ) + " STRNEWLINE " ) ; } static void createArray ( int N ) { if ( N % 4 == 0 ) arrayConstruct ( N ) ; else Console . Write ( - 1 + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int N = 8 ; createArray ( N ) ; } }
Count of all sub | C # implementation to count all sub - strings with sum of weights at most K ; Function to count all substrings ; Hashmap to store substrings ; Iterate over all substrings ; Variable to maintain sum of all characters encountered ; Variable to maintain substring till current position ; Get position of character in string W ; Add weight to current sum ; Add current character to substring ; Check if sum of characters is <= K insert in Hashmap ; Driver code ; Initialise string ; Initialise weight
using System ; using System . Collections . Generic ; class GFG { static int distinctSubstring ( string P , string Q , int K , int N ) { HashSet < string > S = new HashSet < string > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; string s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P [ j ] - ' a ' ; sum += Q [ pos ] - '0' ; s += P [ j ] ; if ( sum <= K ) { S . Add ( s ) ; } else { break ; } } } return S . Count ; } static void Main ( ) { string S = " abcde " ; string W = "12345678912345678912345678" ; int K = 5 ; int N = S . Length ; Console . WriteLine ( distinctSubstring ( S , W , K , N ) ) ; } }
Count all sub | C # program to find the count of all the sub - Strings with weight of characters atmost K ; Function to find the count of all the subStrings with weight of characters atmost K ; Hashmap to store all subStrings ; Iterate over all subStrings ; c the sum of all characters encountered so far ; Maintain the subString till the current position ; Get the position of the character in String Q ; Add weight to current sum ; Add current character to subString ; If sum of characters is <= K then insert in into the set ; Finding the size of the set ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int distinctSubString ( String P , String Q , int K , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P [ j ] - ' a ' ; sum += Q [ pos ] - '0' ; s += P [ j ] ; if ( sum <= K ) { S . Add ( s ) ; } else { break ; } } } return S . Count ; } public static void Main ( String [ ] args ) { String P = " abcde " ; String Q = "12345678912345678912345678" ; int K = 5 ; int N = P . Length ; Console . Write ( distinctSubString ( P , Q , K , N ) ) ; } }
Program to print a Hollow Triangle inside a Triangle | C # implementation of the above approach ; Function to print the pattern ; Loop for rows ; Loop for column ; For printing equal sides of outer triangle ; For printing equal sides of inner triangle ; For printing base of both triangle ; For spacing between the triangle ; Driver Code
using System ; class GFG { static void printPattern ( int n ) { int i , j ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j < 2 * n ; j ++ ) { if ( j == ( n - i + 1 ) || j == ( n + i - 1 ) ) { Console . Write ( " * ▁ " ) ; } else if ( ( i >= 4 && i <= n - 4 ) && ( j == n - i + 4 j == n + i - 4 ) ) { Console . Write ( " * ▁ " ) ; } else if ( i == n || ( i == n - 4 && j >= n - ( n - 2 * 4 ) && j <= n + n - 2 * 4 ) ) { Console . Write ( " * ▁ " ) ; } else { Console . Write ( " ▁ " + " ▁ " ) ; } } Console . Write ( " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int N = 9 ; printPattern ( N ) ; } }