codeparrot/xlcost-text-to-code huggingface dataset:
Recursive program to replace all occurrences of pi with 3.14 in a given string | C ++ program for above approach ; A simple recursive approach to replace all pi in a given function with "3.14" . Firstly function is declared we don 't need any helper function one function is enough ; Base case if s is empty or length of s is 1 return the s ; If the 0 th and 1 st element of s are p and i we have to handle them for rest we have to call recursion it will give the result ; Smalloutput is a variable used to store recursion result ; And we have to add the recursion result with the first part we handled and return the answer ; If 1 st & 2 nd element aren 't "p" & "i", then keep  1st index as it is & call recursion for rest of  the string. ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; string replacePi ( string s ) { if ( s . length ( ) == 0 || s . length ( ) == 1 ) return s ; if ( s [ 0 ] == ' p ' && s [ 1 ] == ' i ' ) { string smallOutput = replacePi ( s . substr ( 2 ) ) ; return "3.14" + smallOutput ; } else { return s [ 0 ] + replacePi ( s . substr ( 1 ) ) ; } } int main ( ) { string s = " pipppiiipi " ; string result = replacePi ( s ) ; cout << result << endl ; return 0 ; }
Check if the given string is vowel prime | C ++ implementation of the approach ; Function that returns true if c is a vowel ; Function that returns true if all the vowels in the given string are only at prime indices ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; 0 and 1 are not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; For every character of the given string ; If current character is vowel and the index is not prime ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) return true ; return false ; } bool isVowelPrime ( string str , int n ) { bool prime [ n ] ; memset ( prime , true , sizeof ( prime ) ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i < n ; i += p ) prime [ i ] = false ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( isVowel ( str [ i ] ) && ! prime [ i ] ) return false ; } return true ; } int main ( ) { string str = " geeksforgeeks " ; int n = str . length ( ) ; if ( isVowelPrime ( str , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Swap all occurrences of two characters to get lexicographically smallest string | C ++ implementation of the approach ; Function to return the lexicographically smallest string after swapping all the occurrences of any two characters ; To store the first index of every character of str ; Store the first occurring index every character ; If current character is appearing for the first time in str ; Starting from the leftmost character ; For every character smaller than str [ i ] ; If there is a character in str which is smaller than str [ i ] and appears after it ; If the required character pair is found ; If swapping is possible ; Characters to be swapped ; For every character ; Replace every ch1 with ch2 and every ch2 with ch1 ; Driver code
#include <iostream> NEW_LINE using namespace std ; #define MAX  26 NEW_LINE string smallestStr ( string str , int n ) { int i , j ; int chk [ MAX ] ; for ( i = 0 ; i < MAX ; i ++ ) chk [ i ] = -1 ; for ( i = 0 ; i < n ; i ++ ) { if ( chk [ str [ i ] - ' a ' ] == -1 ) chk [ str [ i ] - ' a ' ] = i ; } for ( i = 0 ; i < n ; i ++ ) { bool flag = false ; for ( j = 0 ; j < str [ i ] - ' a ' ; j ++ ) { if ( chk [ j ] > chk [ str [ i ] - ' a ' ] ) { flag = true ; break ; } } if ( flag ) break ; } if ( i < n ) { char ch1 = str [ i ] ; char ch2 = char ( j + ' a ' ) ; for ( i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ch1 ) str [ i ] = ch2 ; else if ( str [ i ] == ch2 ) str [ i ] = ch1 ; } } return str ; } int main ( ) { string str = " ccad " ; int n = str . length ( ) ; cout << smallestStr ( str , n ) ; return 0 ; }
Longest sub string of 0 's in a binary string which is repeated K times | C ++ program to find the find the Longest continuous sequence of '0' after repeating Given string K time ; Function to find the longest substring of 0 's ; To store size of the string ; To store the required answer ; Find the longest substring of 0 's ; Run a loop upto s [ i ] is zero ; Check the conditions ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int longest_substring ( string s , int k ) { int n = s . size ( ) ; if ( k > 1 ) { s += s ; n *= 2 ; } int ans = 0 ; int i = 0 ; while ( i < n ) { int x = 0 ; while ( s [ i ] == '0' && i < n ) x ++ , i ++ ; ans = max ( ans , x ) ; i ++ ; } if ( k == 1 or ans != n ) return ans ; else return ( ans / 2 ) * k ; } int main ( ) { string s = "010001000" ; int k = 4 ; cout << longest_substring ( s , k ) ; return 0 ; }
Find the number of occurrences of a character upto preceding position | CPP program to find the number of occurrences of a character at position P upto p - 1 ; Function to find the number of occurrences of a character at position P upto p - 1 ; Return the required count ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Occurrence ( string s , int position ) { int count = 0 ; for ( int i = 0 ; i < position - 1 ; i ++ ) if ( s [ i ] == s [ position - 1 ] ) count ++ ; return count ; } int main ( ) { string s = " ababababab " ; int p = 9 ; cout << Occurrence ( s , p ) ; return 0 ; }
Find the number of occurrences of a character upto preceding position | CPP program to find the number of occurrences of a character at position P upto p - 1 ; Function to find the number of occurrences of a character at position P upto p - 1 ; Iterate over the string ; Store the Occurrence of same character ; Increase its frequency ; Return the required count ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countOccurrence ( string s , int position ) { int alpha [ 26 ] = { 0 } , b [ s . size ( ) ] = { 0 } ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { b [ i ] = alpha [ ( int ) s [ i ] - 97 ] ; alpha [ ( int ) s [ i ] - 97 ] ++ ; } return b [ position - 1 ] ; } int main ( ) { string s = " ababababab " ; int p = 9 ; cout << countOccurrence ( s , p ) ; return 0 ; }
Map every character of one string to another such that all occurrences are mapped to the same character | C ++ implementation of the approach ; Function that returns true if the mapping is possible ; Both the strings are of un - equal lengths ; To store the frequencies of the characters in both the string ; Update frequencies of the characters ; For every character of s1 ; If current character is not present in s1 ; Find a character in s2 that has frequency equal to the current character 's  frequency in s1 ; If such character is found ; Set the frequency to - 1 so that it doesn 't get picked again ; Set found to true ; If there is no character in s2 that could be mapped to the current character in s1 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  26 NEW_LINE bool canBeMapped ( string s1 , int l1 , string s2 , int l2 ) { if ( l1 != l2 ) return false ; int freq1 [ MAX ] = { 0 } ; int freq2 [ MAX ] = { 0 } ; for ( int i = 0 ; i < l1 ; i ++ ) freq1 [ s1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) freq2 [ s2 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq1 [ i ] == 0 ) continue ; bool found = false ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq1 [ i ] == freq2 [ j ] ) { freq2 [ j ] = -1 ; found = true ; break ; } } if ( ! found ) return false ; } return true ; } int main ( ) { string s1 = " axx " ; string s2 = " cbc " ; int l1 = s1 . length ( ) ; int l2 = s2 . length ( ) ; if ( canBeMapped ( s1 , l1 , s2 , l2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Distinct strings such that they contains given strings as sub | C ++ implementation of the approach ; Set to store strings and avoid duplicates ; Recursive function to generate the required strings ; If current string is part of the result ; Insert it into the set ; If character from str1 can be chosen ; If character from str2 can be chosen ; Function to print the generated strings from the set ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; set < string > stringSet ; void find_permutation ( string & str1 , string & str2 , int len1 , int len2 , int i , int j , string res ) { if ( res . length ( ) == len1 + len2 ) { stringSet . insert ( res ) ; return ; } if ( i < len1 ) find_permutation ( str1 , str2 , len1 , len2 , i + 1 , j , res + str1 [ i ] ) ; if ( j < len2 ) find_permutation ( str1 , str2 , len1 , len2 , i , j + 1 , res + str2 [ j ] ) ; } void print_set ( ) { set < string > :: iterator itr ; for ( itr = stringSet . begin ( ) ; itr != stringSet . end ( ) ; itr ++ ) cout << ( * itr ) << endl ; } int main ( ) { string str1 = " aa " , str2 = " ab " ; int len1 = str1 . length ( ) ; int len2 = str2 . length ( ) ; find_permutation ( str1 , str2 , len1 , len2 , 0 , 0 , " " ) ; print_set ( ) ; return 0 ; }
Generate all possible strings such that char at index i is either str1 [ i ] or str2 [ i ] | C ++ implementation of the approach ; Recursive function to generate the required strings ; If length of the current string is equal to the length of the given strings then the current string is part of the result ; Choosing the current character from the string a ; Choosing the current character from the string b ; Driver code ; Third argument is an empty string that we will be appended in the recursion calls Fourth arguments is the length of the resultant string so far
#include <bits/stdc++.h> NEW_LINE using namespace std ; void generateStr ( char * a , char * b , string s , int count , int len ) { if ( count == len ) { cout << s << endl ; return ; } generateStr ( a + 1 , b + 1 , s + ( * a ) , count + 1 , len ) ; generateStr ( a + 1 , b + 1 , s + ( * b ) , count + 1 , len ) ; } int main ( ) { char * a = " abc " , * b = " def " ; int n = strlen ( a ) ; generateStr ( a , b , " " , 0 , n ) ; return 0 ; }
Program to generate all possible valid IP addresses from given string | Set 2 | C ++ implementation of the approach ; Function to get all the valid ip - addresses ; If index greater than givenString size and we have four block ; Remove the last dot ; Add ip - address to the results ; To add one index to ip - address ; Select one digit and call the same function for other blocks ; Backtrack to generate another possible ip address So we remove two index ( one for the digit and other for the dot ) from the end ; Select two consecutive digits and call the same function for other blocks ; Backtrack to generate another possible ip address So we remove three index from the end ; Select three consecutive digits and call the same function for other blocks ; Backtrack to generate another possible ip address So we remove four index from the end ; Driver code ; Fill result vector with all valid ip - addresses ; Print all the generated ip - addresses
#include <iostream> NEW_LINE #include <vector> NEW_LINE using namespace std ; void GetAllValidIpAddress ( vector < string > & result , string givenString , int index , int count , string ipAddress ) { if ( givenString . size ( ) == index && count == 4 ) { ipAddress . pop_back ( ) ; result . push_back ( ipAddress ) ; return ; } if ( givenString . size ( ) < index + 1 ) return ; ipAddress = ipAddress + givenString . substr ( index , 1 ) + ' . ' ; GetAllValidIpAddress ( result , givenString , index + 1 , count + 1 , ipAddress ) ; ipAddress . erase ( ipAddress . end ( ) - 2 , ipAddress . end ( ) ) ; if ( givenString . size ( ) < index + 2 givenString [ index ] == '0' ) return ; ipAddress = ipAddress + givenString . substr ( index , 2 ) + ' . ' ; GetAllValidIpAddress ( result , givenString , index + 2 , count + 1 , ipAddress ) ; ipAddress . erase ( ipAddress . end ( ) - 3 , ipAddress . end ( ) ) ; if ( givenString . size ( ) < index + 3 || stoi ( givenString . substr ( index , 3 ) ) > 255 ) return ; ipAddress += givenString . substr ( index , 3 ) + ' . ' ; GetAllValidIpAddress ( result , givenString , index + 3 , count + 1 , ipAddress ) ; ipAddress . erase ( ipAddress . end ( ) - 4 , ipAddress . end ( ) ) ; } int main ( ) { string givenString = "25525511135" ; vector < string > result ; GetAllValidIpAddress ( result , givenString , 0 , 0 , " " ) ; for ( int i = 0 ; i < result . size ( ) ; i ++ ) { cout << result [ i ] << " STRNEWLINE " ; } }
Count of non | C ++ implementation of the approach ; Function to return the count of required non - overlapping sub - strings ; To store the required count ; If "010" matches the sub - string starting at current index i ; If "101" matches the sub - string starting at current index i ; Driver code
#include <iostream> NEW_LINE using namespace std ; int countSubStr ( string s , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 2 ; ) { if ( s [ i ] == '0' && s [ i + 1 ] == '1' && s [ i + 2 ] == '0' ) { count ++ ; i += 3 ; } else if ( s [ i ] == '1' && s [ i + 1 ] == '0' && s [ i + 2 ] == '1' ) { count ++ ; i += 3 ; } else { i ++ ; } } return count ; } int main ( ) { string s = "10101010101" ; int n = s . length ( ) ; cout << countSubStr ( s , n ) ; return 0 ; }
Find distinct characters in distinct substrings of a string | C ++ implementation of the approach ; Function to return the count of distinct characters in all the distinct sub - strings of the given string ; To store all the sub - strings ; To store the current sub - string ; To store the characters of the current sub - string ; If current sub - string hasn 't  been stored before ; Insert it into the set ; Update the count of distinct characters ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTotalDistinct ( string str ) { int cnt = 0 ; set < string > items ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { string temp = " " ; set < char > ans ; for ( int j = i ; j < str . length ( ) ; ++ j ) { temp = temp + str [ j ] ; ans . insert ( str [ j ] ) ; if ( items . find ( temp ) == items . end ( ) ) { items . insert ( temp ) ; cnt += ans . size ( ) ; } } } return cnt ; } int main ( ) { string str = " ABCA " ; cout << countTotalDistinct ( str ) ; return 0 ; }
Partition the string in two parts such that both parts have at least k different characters | C ++ implementation of the above approach ; Function to find the partition of the string such that both parts have at least k different characters ; Length of the string ; To check if the current character is already found ; Count number of different characters in the left part ; If current character is not already found , increase cnt by 1 ; If count becomes equal to k , we 've  got the first part, therefore,  store current index and break the loop ; Increment i by 1 ; Clear the map ; Assign cnt as 0 ; If the current character is not already found , increase cnt by 1 ; If cnt becomes equal to k , the second part also have k different characters so break it ; If the second part has less than k different characters , then print " Not ▁ Possible " ; Otherwise print both parts ; Driver code ; Function call
#include <iostream> NEW_LINE #include <map> NEW_LINE using namespace std ; void division_of_string ( string str , int k ) { int n = str . size ( ) ; map < char , bool > has ; int ans , cnt = 0 , i = 0 ; while ( i < n ) { if ( ! has [ str [ i ] ] ) { cnt ++ ; has [ str [ i ] ] = true ; } if ( cnt == k ) { ans = i ; break ; } i ++ ; } i ++ ; has . clear ( ) ; cnt = 0 ; while ( i < n ) { if ( ! has [ str [ i ] ] ) { cnt ++ ; has [ str [ i ] ] = true ; } if ( cnt == k ) { break ; } i ++ ; } if ( cnt < k ) { cout << " Not ▁ possible " << endl ; } else { i = 0 ; while ( i <= ans ) { cout << str [ i ] ; i ++ ; } cout << endl ; while ( i < n ) { cout << str [ i ] ; i ++ ; } cout << endl ; } cout << endl ; } int main ( ) { string str = " geeksforgeeks " ; int k = 4 ; division_of_string ( str , k ) ; return 0 ; }
Count substrings that contain all vowels | SET 2 | C ++ implementation of the approach ; Function that returns true if c is a vowel ; Function to return the count of sub - strings that contain every vowel at least once and no consonant ; Map is used to store count of each vowel ; Start index is set to 0 initially ; If substring till now have all vowels atleast once increment start index until there are all vowels present between ( start , i ) and add n - i each time ; Function to extract all maximum length sub - strings in s that contain only vowels and then calls the countSubstringsUtil ( ) to find the count of valid sub - strings in that string ; If current character is a vowel then append it to the temp string ; The sub - string containing all vowels ends here ; If there was a valid sub - string ; Reset temp string ; For the last valid sub - string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } int countSubstringsUtil ( string s ) { int count = 0 ; map < char , int > mp ; int n = s . length ( ) ; int start = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mp [ s [ i ] ] ++ ; while ( mp [ ' a ' ] > 0 && mp [ ' e ' ] > 0 && mp [ ' i ' ] > 0 && mp [ ' o ' ] > 0 && mp [ ' u ' ] > 0 ) { count += n - i ; mp [ s [ start ] ] -- ; start ++ ; } } return count ; } int countSubstrings ( string s ) { int count = 0 ; string temp = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( isVowel ( s [ i ] ) ) { temp += s [ i ] ; } else { if ( temp . length ( ) > 0 ) count += countSubstringsUtil ( temp ) ; temp = " " ; } } if ( temp . length ( ) > 0 ) count += countSubstringsUtil ( temp ) ; return count ; } int main ( ) { string s = " aeouisddaaeeiouua " ; cout << countSubstrings ( s ) << endl ; return 0 ; }
Remove first adjacent pairs of similar characters until possible | C ++ implementation of the above approach ; Function to remove adjacent duplicates ; Iterate for every character in the string ; If ans string is empty or its last character does not match with the current character then append this character to the string ; Matches with the previous one ; Return the answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string removeDuplicates ( string S ) { string ans = " " ; for ( auto it : S ) { if ( ans . empty ( ) or ans . back ( ) != it ) ans . push_back ( it ) ; else if ( ans . back ( ) == it ) ans . pop_back ( ) ; } return ans ; } int main ( ) { string str = " keexxllx " ; cout << removeDuplicates ( str ) ; }
Reverse individual words with O ( 1 ) extra space | C ++ implementation of the approach ; Function to resturn the string after reversing the individual words ; Pointer to the first character of the first word ; If the current word has ended ; Pointer to the last character of the current word ; Reverse the current word ; Pointer to the first character of the next word ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string reverseWords ( string str ) { int start = 0 ; for ( int i = 0 ; i <= str . size ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' || i == str . size ( ) ) { int end = i - 1 ; while ( start < end ) { swap ( str [ start ] , str [ end ] ) ; start ++ ; end -- ; } start = i + 1 ; } } return str ; } int main ( ) { string str = " Geeks ▁ for ▁ Geeks " ; cout << reverseWords ( str ) ; return 0 ; }
Reverse the Words of a String using Stack | C ++ implementation of the approach ; Function to reverse the words of the given sentence ; Create an empty character array stack ; Push words into the stack ; Get the words in reverse order ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void reverse ( char k [ ] ) { stack < char * > s ; char * token = strtok ( k , " ▁ " ) ; while ( token != NULL ) { s . push ( token ) ; token = strtok ( NULL , " ▁ " ) ; } while ( ! s . empty ( ) ) { cout << s . top ( ) << " ▁ " ; s . pop ( ) ; } } int main ( ) { char k [ ] = " geeks ▁ for ▁ geeks " ; reverse ( k ) ; return 0 ; }
Count of substrings which contains a given character K times | C ++ program to count the number of substrings which contains the character C exactly K times ; Function to count the number of substrings which contains the character C exactly K times ; left and right counters for characters on both sides of substring window ; left and right pointer on both sides of substring window ; initialize the frequency ; result and length of string ; initialize the left pointer ; initialize the right pointer ; traverse all the window substrings ; counting the characters on leftSide of substring window ; counting the characters on rightSide of substring window ; Add the possible substrings on both sides to result ; Setting the frequency for next substring window ; reset the left , right counters ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSubString ( string s , char c , int k ) { int leftCount = 0 , rightCount = 0 ; int left = 0 , right = 0 ; int freq = 0 ; int result = 0 , len = s . length ( ) ; while ( s [ left ] != c && left < len ) { left ++ ; leftCount ++ ; } right = left + 1 ; while ( freq != ( k - 1 ) && ( right - 1 ) < len ) { if ( s [ right ] == c ) freq ++ ; right ++ ; } while ( left < len && ( right - 1 ) < len ) { while ( s [ left ] != c && left < len ) { left ++ ; leftCount ++ ; } while ( right < len && s [ right ] != c ) { if ( s [ right ] == c ) freq ++ ; right ++ ; rightCount ++ ; } result = result + ( leftCount + 1 ) * ( rightCount + 1 ) ; freq = k - 1 ; leftCount = 0 ; rightCount = 0 ; left ++ ; right ++ ; } return result ; } int main ( ) { string s = "3123231" ; char c = '3' ; int k = 2 ; cout << countSubString ( s , c , k ) ; return 0 ; }
Count of sub | C ++ implementation of the approach ; Function to return the total required sub - sequences ; Find ways for all values of x ; x + 1 ; Removing all unnecessary digits ; Prefix Sum Array for X + 1 digit ; Sum of squares ; Previous sum of all possible pairs ; To find sum of multiplication of all possible pairs ; To prevent overcounting ; Adding ways for all possible x ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE #define MOD  1000000007 NEW_LINE using namespace std ; int solve ( string test ) { int size = test . size ( ) ; int total = 0 ; for ( int i = 0 ; i <= 8 ; i ++ ) { int x = i ; int y = i + 1 ; string newtest ; for ( int j = 0 ; j < size ; j ++ ) { if ( test [ j ] == x + 48 test [ j ] == y + 48 ) { newtest += test [ j ] ; } } if ( newtest . size ( ) > 0 ) { int size1 = newtest . size ( ) ; int prefix [ size1 ] = { 0 } ; for ( int j = 0 ; j < size1 ; j ++ ) { if ( newtest [ j ] == y + 48 ) { prefix [ j ] ++ ; } } for ( int j = 1 ; j < size1 ; j ++ ) { prefix [ j ] += prefix [ j - 1 ] ; } int count = 0 ; int firstcount = 0 ; int ss = 0 ; int prev = 0 ; for ( int j = 0 ; j < size1 ; j ++ ) { if ( newtest [ j ] == x + 48 ) { count ++ ; firstcount ++ ; } else { ss += count * count ; int pairsum = ( firstcount * firstcount - ss ) / 2 ; int temp = pairsum ; pairsum -= prev ; prev = temp ; int secondway = prefix [ size1 - 1 ] ; if ( j != 0 ) secondway -= prefix [ j - 1 ] ; int answer = count * ( count - 1 ) * secondway * ( secondway - 1 ) ; answer /= 4 ; answer += ( pairsum * secondway * ( secondway - 1 ) ) / 2 ; total += answer ; count = 0 ; } } } } return total ; } int main ( ) { string test = "13134422" ; cout << solve ( test ) << endl ; return 0 ; }
Find if it is possible to make a binary string which contanins given number of "0" , "1" , "01" and "10" as sub sequences | C ++ implementation of the approach ; Function that returns true if it is possible to make a binary string consisting of l 0 ' s , ▁ m ▁ 1' s , x "01" sub - sequences and y "10" sub - sequences ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int l , int m , int x , int y ) { if ( l * m == x + y ) return true ; return false ; } int main ( ) { int l = 3 , m = 2 , x = 4 , y = 2 ; if ( isPossible ( l , m , x , y ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }