Muennighoff/xP3x-sample huggingface dataset:
inputs: "Maximum length of consecutive 1 s or 0 s after flipping at most K characters | C ++ program for the above approach ; Function to find the maximum length continuos segment of character c after flipping at most K characters ; Stores the maximum length ; Stores the count of char ' c ' ; Start of window ; Remove the extra ' c ' from left ; Increment the value of the left ; Update the resultant maximum length of character ch ; Function to find the maximum length of consecutive 0 s or 1 s by flipping at most K characters of the string ; Print the maximum of the maximum length of 0 s or 1 s ; Driver Code"
Solution in C++:
targets: #include <bits/stdc++.h>
using namespace std ; int maxLength ( string str , int n , char c , int k ) { int ans = -1 ; int cnt = 0 ; int left = 0 ; for ( int right = 0 ; right < n ; right ++ ) { if ( str [ right ] == c ) { cnt ++ ; } while ( cnt > k ) { if ( str [ left ] == c ) { cnt -- ; } left ++ ; } ans = max ( ans , right - left + 1 ) ; } return ans ; } int maxConsecutiveSegment ( string S , int K ) { int N = S . length ( ) ; return max ( maxLength ( S , N , '0' , K ) , maxLength ( S , N , '1' , K ) ) ; } int main ( ) { string S = "1001" ; int K = 1 ; cout << maxConsecutiveSegment ( S , K ) ; return 0 ; }
inputs: "Tetranacci Numbers | Function to return the N - th tetranacci number ; base cases ; base cases ; base cases ; function to print the nth tetranacci number ; Driver code"
Solution in php:
targets: < ? php function printTetraRec ( $ n ) { if ( $ n == 0 ) return 0 ; if ( $ n == 1 $ n == 2 ) return 1 ; if ( $ n == 3 ) return 2 ; else return printTetraRec ( $ n - 1 ) + printTetraRec ( $ n - 2 ) + printTetraRec ( $ n - 3 ) + printTetraRec ( $ n - 4 ) ; } function printTetra ( $ n ) { echo printTetraRec ( $ n ) . " " ; } $ n = 10 ; printTetra ( $ n ) ; ? >
inputs: "Write a program to calculate pow ( x , n ) | C # program for the above approach ; If x ^ 0 return 1 ; If we need to find of 0 ^ y ; For all other cases ; Driver Code"
How can the above be solved in C-Sharp?
targets: using System ; class GFG { public static int power ( int x , int y ) { if ( y == 0 ) return 1 ; if ( x == 0 ) return 0 ; return x * power ( x , y - 1 ) ; } public static void Main ( String [ ] args ) { int x = 2 ; int y = 3 ; Console . WriteLine ( power ( x , y ) ) ; } }
inputs: "Permutation Coefficient | Returns value of Permutation Coefficient P ( n , k ) ; Calculate value of Permutation Coefficient in bottom up manner ; Base Cases ; Calculate value using previosly stored values ; This step is important as P ( i , j ) = 0 for j > i ; Driver Code"
Solution in php:
targets: < ? php function permutationCoeff ( $ n , $ k ) { $ P = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= min ( $ i , $ k ) ; $ j ++ ) { if ( $ j == 0 ) $ P [ $ i ] [ $ j ] = 1 ; else $ P [ $ i ] [ $ j ] = $ P [ $ i - 1 ] [ $ j ] + ( $ j * $ P [ $ i - 1 ] [ $ j - 1 ] ) ; $ P [ $ i ] [ $ j + 1 ] = 0 ; } } return $ P [ $ n ] [ $ k ] ; } $ n = 10 ; $ k = 2 ; echo " Value ▁ of ▁ P ( " , $ n , " ▁ , " , $ k , " ) ▁ is ▁ " , permutationCoeff ( $ n , $ k ) ; ? >
inputs: "Recursive Program to print multiplication table of a number | C ++ program to print table of a number using recursion ; Function that print the table of a given number using recursion ; Base Case ; Print the table for current iteration ; Recursive call to next iteration ; Driver Code ; Input number whose table is to print ; Function call to print the table"
Solution in C++:
targets: #include <iostream>
using namespace std ; void mul_table ( int N , int i ) { if ( i > 10 ) return ; cout << N << " ▁ * ▁ " << i << " ▁ = ▁ " << N * i << endl ; return mul_table ( N , i + 1 ) ; } int main ( ) { int N = 8 ; mul_table ( N , 1 ) ; return 0 ; }
inputs: "Count of total subarrays whose sum is a Fibonacci Numbers | Function to check whether a number is perfect square or not ; Function to check whether a number is fibonacci number or not ; If 5 * n * n + 4 or 5 * n * n - 5 is a perfect square , then the number is Fibonacci ; Function to count the subarray with sum fibonacci number ; Traverse the array arr [ ] to find the sum of each subarray ; To store the sum ; Check whether sum of subarray between [ i , j ] is fibonacci or not ; Driver Code ; Function Call"
Solution in Javascript:
targets: function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function fibonacciSubarrays ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; ++ i ) { var sum = 0 ; for ( var j = i ; j < n ; ++ j ) { sum += arr [ j ] ; if ( isFibonacci ( sum ) ) { ++ count ; } } } document . write ( count ) ; } var arr = [ 6 , 7 , 8 , 9 ] ; var n = arr . length ; fibonacciSubarrays ( arr , n ) ;
inputs: "Nearest prime less than given number n | PHP program to find the nearest prime to n . ; array to store all primes less than 10 ^ 6 ; Utility function of Sieve of Sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x ; This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j ; eliminate indexes which does not produce primes ; Since 2 is a prime number ; Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; modified binary search to find nearest prime less than N ; base condition is , if we are reaching at left corner or right corner of primes [ ] array then return that corner element because before or after that we don 't have any prime number in  primes array ; now if n is itself a prime so it will be present in primes array and here we have to find nearest prime less than n so we will return primes [ mid - 1 ] ; now if primes [ mid ] < n and primes [ mid + 1 ] > n that means we reached at nearest prime ; Driver Code"
Solution in php:
targets: < ? php $ MAX = 10000 ; $ primes = array ( ) ; function Sieve ( ) { global $ MAX , $ primes ; $ n = $ MAX ; $ nNew = ( int ) ( sqrt ( $ n ) ) ; $ marked = array_fill ( 0 , ( int ) ( $ n / 2 + 500 ) , 0 ) ; for ( $ i = 1 ; $ i <= ( $ nNew - 1 ) / 2 ; $ i ++ ) for ( $ j = ( $ i * ( $ i + 1 ) ) << 1 ; $ j <= $ n / 2 ; $ j = $ j + 2 * $ i + 1 ) $ marked [ $ j ] = 1 ; array_push ( $ primes , 2 ) ; for ( $ i = 1 ; $ i <= $ n / 2 ; $ i ++ ) if ( $ marked [ $ i ] == 0 ) array_push ( $ primes , 2 * $ i + 1 ) ; } function binarySearch ( $ left , $ right , $ n ) { global $ primes ; if ( $ left <= $ right ) { $ mid = ( int ) ( ( $ left + $ right ) / 2 ) ; if ( $ mid == 0 || $ mid == count ( $ primes ) - 1 ) return $ primes [ $ mid ] ; if ( $ primes [ $ mid ] == $ n ) return $ primes [ $ mid - 1 ] ; if ( $ primes [ $ mid ] < $ n && $ primes [ $ mid + 1 ] > $ n ) return $ primes [ $ mid ] ; if ( $ n < $ primes [ $ mid ] ) return binarySearch ( $ left , $ mid - 1 , $ n ) ; else return binarySearch ( $ mid + 1 , $ right , $ n ) ; } return 0 ; } Sieve ( ) ; $ n = 17 ; echo binarySearch ( 0 , count ( $ primes ) - 1 , $ n ) ; ? >
inputs: "Sum of the multiples of two numbers below N | C ++ program to find the sum of all the integers below N which are multiples of either A or B ; Function to return the sum of all the integers below N which are multiples of either A or B ; If i is a multiple of a or b ; Driver code"
How can the above be solved in C++?
targets: #include <iostream>
using namespace std ; int findSum ( int n , int a , int b ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( i % a == 0 i % b == 0 ) sum += i ; return sum ; } int main ( ) { int n = 10 , a = 3 , b = 5 ; cout << findSum ( n , a , b ) ; return 0 ; }
inputs: "Find a pair with the given difference | C ++ program to find a pair with the given difference ; The function assumes that the array is sorted ; Initialize positions of two elements ; Search for a pair ; Driver program to test above function"
Solution in C++:
targets: #include <bits/stdc++.h>
using namespace std ; bool findPair ( int arr [ ] , int size , int n ) { int i = 0 ; int j = 1 ; while ( i < size && j < size ) { if ( i != j && arr [ j ] - arr [ i ] == n ) { cout << " Pair ▁ Found : ▁ ( " << arr [ i ] << " , ▁ " << arr [ j ] << " ) " ; return true ; } else if ( arr [ j ] - arr [ i ] < n ) j ++ ; else i ++ ; } cout << " No ▁ such ▁ pair " ; return false ; } int main ( ) { int arr [ ] = { 1 , 8 , 30 , 40 , 100 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int n = 60 ; findPair ( arr , size , n ) ; return 0 ; }
inputs: "Check whether given string can be generated after concatenating given strings | Function that return true if pre is a prefix of str ; While there are characters to match ; If characters differ at any position ; str starts with pre ; Function that return true if suff is a suffix of str ; While there are characters to match ; If characters differ at any position ; str ends with suff ; Function that returns true if str = a + b or str = b + a ; str cannot be generated by concatenating a and b ; If str starts with a i . e . a is a prefix of str ; Check if the rest of the characters are equal to b i . e . b is a suffix of str ; If str starts with b i . e . b is a prefix of str ; Check if the rest of the characters are equal to a i . e . a is a suffix of str ; Driver code"
How can the above be solved in JS?
targets: function startsWith ( str , pre ) { let strLen = str . length ; let preLen = pre . length ; let i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str [ i ] != pre [ j ] ) return false ; i ++ ; j ++ ; } return true ; } function endsWith ( str , suff ) { let i = str . length - 1 ; let j = suff . length - 1 ; while ( i >= 0 && j >= 0 ) { if ( str [ i ] != suff [ j ] ) return false ; i -- ; j -- ; } return true ; } function checkString ( str , a , b ) { if ( str . length != a . length + b . length ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } let str = " " ; let a = " " ; let b = " " ; if ( checkString ( str , a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;
inputs: "Search , insert and delete in a sorted array | C program to implement binary search in sorted array ; function to implement binary search ; low + ( high - low ) / 2 ; ; Driver Code Let us search 3 in below array"
Solution in C:
targets: #include <stdio.h>
int binarySearch ( int arr [ ] , int low , int high , int key ) { if ( high < low ) return -1 ; int mid = ( low + high ) / 2 ; if ( key == arr [ mid ] ) return mid ; if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ; return binarySearch ( arr , low , ( mid - 1 ) , key ) ; } int main ( ) { int arr [ ] = { 5 , 6 , 7 , 8 , 9 , 10 } ; int n , key ; n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; key = 10 ; printf ( " Index : ▁ % d 
 " , binarySearch ( arr , 0 , n - 1 , key ) ) ; return 0 ; }
inputs: "Queries to find the minimum array sum possible by removing elements from either end | C # program for the above approach ; Function to find the minimum sum for each query after removing elements from either ends ; Traverse the query array ; Traverse the array from the front ; If element equals val , then break out of loop ; Traverse the array from rear ; If element equals val , break ; Print the minimum of the two as the answer ; Driver Code ; Function Call"
How can the above be solved in C-Sharp?
targets: using System ; class GFG { static void minSum ( int [ ] arr , int N , int [ ] Q , int M ) { for ( int i = 0 ; i < M ; i ++ ) { int val = Q [ i ] ; int front = 0 , rear = 0 ; for ( int j = 0 ; j < N ; j ++ ) { front += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } for ( int j = N - 1 ; j >= 0 ; j -- ) { rear += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } Console . Write ( Math . Min ( front , rear ) + " ▁ " ) ; } } static public void Main ( ) { int [ ] arr = { 2 , 3 , 6 , 7 , 4 , 5 , 1 } ; int N = arr . Length ; int [ ] Q = { 7 , 6 } ; int M = Q . Length ; minSum ( arr , N , Q , M ) ; } }
inputs: "Number of paths with exactly k coins | A Dynamic Programming based C ++ program to count paths with exactly ' k ' coins ; Base cases ; If this subproblem is already solved ; ( m , n ) can be reached either through ( m - 1 , n ) or through ( m , n - 1 ) ; This function mainly initializes dp [ ] [ ] [ ] and calls pathCountDPRecDP ( ) ; Driver Program to test above functions"
How can the above be solved in C++?
targets: #include <bits/stdc++.h>
#define R  3
#define C  3
#define MAX_K  1000
using namespace std ; int dp [ R ] [ C ] [ MAX_K ] ; int pathCountDPRecDP ( int mat [ ] [ C ] , int m , int n , int k ) { if ( m < 0 n < 0 ) return 0 ; if ( m == 0 && n == 0 ) return ( k == mat [ m ] [ n ] ) ; if ( dp [ m ] [ n ] [ k ] != -1 ) return dp [ m ] [ n ] [ k ] ; dp [ m ] [ n ] [ k ] = pathCountDPRecDP ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountDPRecDP ( mat , m , n - 1 , k - mat [ m ] [ n ] ) ; return dp [ m ] [ n ] [ k ] ; } int pathCountDP ( int mat [ ] [ C ] , int k ) { memset ( dp , -1 , sizeof dp ) ; return pathCountDPRecDP ( mat , R - 1 , C - 1 , k ) ; } int main ( ) { int k = 12 ; int mat [ R ] [ C ] = { { 1 , 2 , 3 } , { 4 , 6 , 5 } , { 3 , 2 , 1 } } ; cout << pathCountDP ( mat , k ) ; return 0 ; }
inputs: "Number of coloured 0 's in an N | Java implementation of the approach ; Function to return the count of coloured 0 s in an n - level hexagon ; Driver code"
Solution in Java:
targets: class GFG { static int count ( int n ) { return n * ( 3 * n - 1 ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( count ( n ) ) ; } }
inputs: "Count prime numbers up to N that can be represented as a sum of two prime numbers | C # program for the above approach ; Function to store all prime numbers up to N using Sieve of Eratosthenes ; Set 0 and 1 as non - prime ; If p is prime ; Set all multiples of p as non - prime ; Function to count prime numbers up to N that can be represented as the sum of two prime numbers ; Stores all the prime numbers ; Update the prime array ; Create a dp array of size n + 1 ; Update dp [ 1 ] = 0 ; Iterate over the range [ 2 , N ] ; Add the previous count value ; Increment dp [ i ] by 1 if i and ( i - 2 ) are both prime ; Print the result ; Driver code"
Solution in C#:
targets: using System ; class GFG { static void SieveOfEratosthenes ( int n , bool [ ] 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 ; } } } } static void countPrime ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) { prime [ i ] = true ; } SieveOfEratosthenes ( n , prime ) ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 0 ; i < dp . Length ; i ++ ) { dp [ i ] = 0 ; } dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] += dp [ i - 1 ] ; if ( prime [ i ] == true && prime [ i - 2 ] == true ) { dp [ i ] ++ ; } } Console . Write ( dp [ n ] ) ; } static void Main ( ) { int N = 6 ; countPrime ( N ) ; } }
inputs: "Count all unique outcomes possible by performing S flips on N coins | Function to recursively count the number of unique outcomes possible S flips are performed on N coins ; Base Cases ; Recursive Calls ; Driver Code"
How can the above be solved in JS?
targets: function numberOfUniqueOutcomes ( N , S ) { if ( S < N ) return 0 ; if ( N == 1 N == S ) return 1 ; return ( numberOfUniqueOutcomes ( N - 1 , S - 1 ) + numberOfUniqueOutcomes ( N - 1 , S - 2 ) ) ; } let N = 3 , S = 4 ; document . write ( numberOfUniqueOutcomes ( N , S ) )
inputs: "Given two strings check which string makes a palindrome first | C # program to check which string makes palindrome first . ; returns winner of two strings ; Count frequencies of characters in both given strings ; Check if there is a character that appears more than once in A and does not appear in B ; Driver Code"
Solution in C#:
targets: using System ; class First_Palin { static int MAX_CHAR = 26 ; static char stringPalindrome ( string A , string B ) { int [ ] countA = new int [ MAX_CHAR ] ; int [ ] countB = new int [ MAX_CHAR ] ; int l1 = A . Length ; int l2 = B . Length ; for ( int i = 0 ; i < l1 ; i ++ ) countA [ A [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) countB [ B [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( ( countA [ i ] > 1 && countB [ i ] == 0 ) ) return ' A ' ; return ' B ' ; } public static void Main ( ) { string a = " abcdea " ; string b = " bcdesg " ; Console . WriteLine ( stringPalindrome ( a , b ) ) ; } }
inputs: "Smallest element in an array that is repeated exactly ' k ' times . | PHP program to find smallest number in array that is repeated exactly ' k ' times . ; Computing frequencies of all elements ; Finding the smallest element with frequency as k ; If frequency of any of the number is equal to k starting from 0 then return the number ; Driver code"
Solution in php:
targets: < ? php $ MAX = 1000 ; function findDuplicate ( $ arr , $ n , $ k ) { global $ MAX ; $ freq = array_fill ( 0 , $ MAX , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] < 1 && $ arr [ $ i ] > $ MAX ) { echo " Out ▁ of ▁ range " ; return -1 ; } $ freq [ $ arr [ $ i ] ] += 1 ; } for ( $ i = 0 ; $ i < $ MAX ; $ i ++ ) { if ( $ freq [ $ i ] == $ k ) return $ i ; } return -1 ; } $ arr = array ( 2 , 2 , 1 , 3 , 1 ) ; $ k = 2 ; $ n = count ( $ arr ) ; echo findDuplicate ( $ arr , $ n , $ k ) ; ? >
inputs: "Minimum number with digits as 4 and 7 only and given sum | Prints minimum number with given digit sum and only allowed digits as 4 and 7. ; Cases where all remaining digits are 4 or 7 ( Remaining sum of digits should be multiple of 4 or 7 ) ; If both 4 s and 7 s are there in digit sum , we subtract a 4. ; Driver code"
How can the above be solved in PHP?
targets: < ? php function findMin ( $ sum ) { $ a = 0 ; $ b = 0 ; while ( $ sum > 0 ) { if ( $ sum % 7 == 0 ) { $ b ++ ; $ sum -= 7 ; } else if ( $ sum % 4 == 0 ) { $ a ++ ; $ sum -= 4 ; } else { $ a ++ ; $ sum -= 4 ; } } if ( $ sum < 0 ) { echo ( " - 1n " ) ; return ; } for ( $ i = 0 ; $ i < $ a ; $ i ++ ) echo ( "4" ) ; for ( $ i = 0 ; $ i < $ b ; $ i ++ ) echo ( "7" ) ; echo ( " 
 " ) ; } findMin ( 15 ) ; ? >
inputs: "Split a Binary String such that count of 0 s and 1 s in left and right substrings is maximum | C ++ program to implement the above approach ; Function to find the maximum sum of count of 0 s in the left substring and count of 1 s in the right substring by splitting the string ; Stores count of 1 s the in binary string ; Traverse the binary string ; If current character is '1' ; Update cntOne ; Stores count of 0 s ; Stores count of 1 s ; Stores maximum sum of count of 0 s and 1 s by splitting the string ; Traverse the binary string ; If current character is '0' ; Update zero ; If current character is '1' ; Update one ; Update res ; Driver Code"
Solution in C++:
targets: #include <bits/stdc++.h>
using namespace std ; int maxSumbySplittingstring ( string str , int N ) { int cntOne = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == '1' ) { cntOne ++ ; } } int zero = 0 ; int one = 0 ; int res = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( str [ i ] == '0' ) { zero ++ ; } else { one ++ ; } res = max ( res , zero + cntOne - one ) ; } return res ; } int main ( ) { string str = "00111" ; int N = str . length ( ) ; cout << maxSumbySplittingstring ( str , N ) ; return 0 ; }
inputs: Given a HUGE number check if it 's a power of two. | C program to find whether a number is power of 2 or not ; returns 1 when str is power of 2 return 0 when str is not a power of 2 ; sum stores the intermediate dividend while dividing . ; if the input is "1" then return 0 because 2 ^ k = 1 where k >= 1 and here k = 0 ; Divide the number until it gets reduced to 1 if we are successfully able to reduce the number to 1 it means input string is power of two if in between an odd number appears at the end it means string is not divisible by two hence not a power of 2. ; if the last digit is odd then string is not divisible by 2 hence not a power of two return 0. ; divide the whole string by 2. i is used to track index in current number . j is used to track index for next iteration . ; if num < 2 then we have to take another digit to the right of A [ i ] to make it bigger than A [ i ] . E . g . 214 / 2 -- > 107 ; if it 's not the first index. E.g 214  then we have to include 0. ; for eg . "124" we will not write 064 so if it is the first index just ignore ; After every division by 2 the length of string is changed . ; if the string reaches to 1 then the str is a power of 2. ; Driver code .
How can the above be solved in C?
targets: #include <stdio.h>
#include <string.h>
int isPowerOf2 ( char * str ) { int len_str = strlen ( str ) ; int num = 0 ; if ( len_str == 1 && str [ len_str - 1 ] == '1' ) return 0 ; while ( len_str != 1 str [ len_str - 1 ] != '1' ) { if ( ( str [ len_str - 1 ] - '0' ) % 2 == 1 ) return 0 ; for ( int i = 0 , j = 0 ; i < len_str ; i ++ ) { num = num * 10 + str [ i ] - '0' ; if ( num < 2 ) { if ( i != 0 ) str [ j ++ ] = '0' ; continue ; } str [ j ++ ] = ( int ) ( num / 2 ) + '0' ; num = ( num ) - ( num / 2 ) * 2 ; } str [ j ] = ' \0' ; len_str = j ; } return 1 ; } int main ( ) { char str1 [ ] = "12468462246684202468024" "6842024662202000002" ; char str2 [ ] = "1" ; char str3 [ ] = "128" ; printf ( " % d % d % d " , isPowerOf2 ( str1 ) , isPowerOf2 ( str2 ) , isPowerOf2 ( str3 ) ) ; return 0 ; }
inputs: "Maximum frequency of a remainder modulo 2 i | C ++ implementation of the approach ; Binary representation of the digits ; Function to return the maximum frequency of s modulo with a power of 2 ; Store the binary representation ; Convert the octal to binary ; Remove the LSB ; If there is 1 in the binary representation ; Find the number of zeroes in between two 1 's in the binary representation ; Driver code"
Solution in C++:
targets: #include <bits/stdc++.h>
using namespace std ; const string bin [ ] = { "000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" } ; int maxFreq ( string s ) { string binary = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { binary += bin [ s [ i ] - '0' ] ; } binary = binary . substr ( 0 , binary . length ( ) - 1 ) ; int count = 1 , prev = -1 , i , j = 0 ; for ( i = binary . length ( ) - 1 ; i >= 0 ; i -- , j ++ ) if ( binary [ i ] == '1' ) { count = max ( count , j - prev ) ; prev = j ; } return count ; } int main ( ) { string octal = "13" ; cout << maxFreq ( octal ) ; return 0 ; }
inputs: "Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum | Java implementation for the above mentioned Dynamic Programming approach ; Function to find the maximum subset sum ; sum of all elements ; bottom up lookup table ; ; initialising dp table with INT_MIN where , INT_MIN means no solution ; Case when diff is 0 ; Putting ith element in g0 ; Putting ith element in g1 ; Ignoring ith element ; Driver code"
How can the above be solved in Java?
targets: class GFG { final static int INT_MIN = Integer . MIN_VALUE ; static int maxSum ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; int limit = 2 * sum + 1 ; int dp [ ] [ ] = new int [ n + 1 ] [ limit ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) dp [ i ] [ j ] = INT_MIN ; } dp [ 0 ] [ sum ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) { if ( ( j - a [ i - 1 ] ) >= 0 && dp [ i - 1 ] [ j - a [ i - 1 ] ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - a [ i - 1 ] ] + a [ i - 1 ] ) ; if ( ( j + a [ i - 1 ] ) < limit && dp [ i - 1 ] [ j + a [ i - 1 ] ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j + a [ i - 1 ] ] ) ; if ( dp [ i - 1 ] [ j ] != INT_MIN ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ sum ] ; } public static void main ( String [ ] args ) { int n = 4 ; int [ ] a = { 1 , 2 , 3 , 6 } ; System . out . println ( maxSum ( a , n ) ) ; } }
inputs: "k | A function to generate prime factors of a given number n and return k - th prime factor ; Find the number of 2 's  that divide k ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , store i and divide n ; This condition is to handle the case where n is a prime number greater than 2 ; Driver Code"
How can the above be solved in PHP?
targets: < ? php function kPrimeFactor ( $ n , $ k ) { while ( $ n % 2 == 0 ) { $ k -- ; $ n = $ n / 2 ; if ( $ k == 0 ) return 2 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i = $ i + 2 ) { while ( $ n % $ i == 0 ) { if ( $ k == 1 ) return $ i ; $ k -- ; $ n = $ n / $ i ; } } if ( $ n > 2 && $ k == 1 ) return $ n ; return -1 ; } { $ n = 12 ; $ k = 3 ; echo kPrimeFactor ( $ n , $ k ) , " 
 " ; $ n = 14 ; $ k = 3 ; echo kPrimeFactor ( $ n , $ k ) ; return 0 ; } ? >
inputs: "Program for addition of two matrices |  ; This function adds A [ ] [ ] and B [ ] [ ] , and stores the result in C [ ] [ ] ; Driver code"
Solution in C:
targets: #include <stdio.h>
#define N  4
void add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) { int i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < N ; j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ; } int main ( ) { int A [ N ] [ N ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int B [ N ] [ N ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int C [ N ] [ N ] ; int i , j ; add ( A , B , C ) ; printf ( " Result ▁ matrix ▁ is ▁ 
 " ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) printf ( " % d ▁ " , C [ i ] [ j ] ) ; printf ( " 
 " ) ; } return 0 ; }
inputs: "Rearrange and update array elements as specified by the given queries | C ++ program to implement the above approach ; Function to perform the given operations ; Dequeue to store the array elements ; Insert all element of the array into the dequeue ; Stores the size of the queue ; Traverse each query ; Query for left shift . ; Extract the element at the front of the queue ; Pop the element at the front of the queue ; Push the element at the back of the queue ; Query for right shift ; Extract the element at the back of the queue ; Pop the element at the back of the queue ; Push the element at the front of the queue ; Query for update ; Query to get the value ; Driver Code ; All possible Queries"
Solution in C++:
targets: #include <bits/stdc++.h>
using namespace std ; void Queries ( int arr [ ] , int N , vector < vector < int > > & Q ) { deque < int > dq ; for ( int i = 0 ; i < N ; i ++ ) { dq . push_back ( arr [ i ] ) ; } int sz = Q . size ( ) ; for ( int i = 0 ; i < sz ; i ++ ) { if ( Q [ i ] [ 0 ] == 0 ) { int front = dq [ 0 ] ; dq . pop_front ( ) ; dq . push_back ( front ) ; } else if ( Q [ i ] [ 0 ] == 1 ) { int back = dq [ N - 1 ] ; dq . pop_back ( ) ; dq . push_front ( back ) ; } else if ( Q [ i ] [ 0 ] == 2 ) { dq [ Q [ i ] [ 1 ] ] = Q [ i ] [ 2 ] ; } else { cout << dq [ Q [ i ] [ 1 ] ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; vector < vector < int > > Q ; Q = { { 0 } , { 1 } , { 3 , 1 } , { 2 , 2 , 54 } , { 3 , 2 } } ; Queries ( arr , N , Q ) ; return 0 ; }
inputs: "Print reverse of a string using recursion | C program to reverse a string using recursion ; Function to print reverse of the passed string ; Driver program to test above function"
Solution in C:
targets: # include <stdio.h>
void reverse ( char * str ) { if ( * str ) { reverse ( str + 1 ) ; printf ( " % c " , * str ) ; } } int main ( ) { char a [ ] = " Geeks ▁ for ▁ Geeks " ; reverse ( a ) ; return 0 ; }
inputs: "Add two numbers without using arithmetic operators | PHP Program to add two numbers without using arithmetic operator ; Iterate till there is no carry ; carry now contains common set bits of x and y ; Sum of bits of x and y where at least one of the bits is not set ; Carry is shifted by one so that adding it to x gives the required sum ; Driver Code"
How can the above be solved in PHP?
targets: < ? php function Add ( $ x , $ y ) { while ( $ y != 0 ) { $ carry = $ x & $ y ; $ x = $ x ^ $ y ; $ y = $ carry << 1 ; } return $ x ; } echo Add ( 15 , 32 ) ; ? >
inputs: Ternary Search | C program to illustrate iterative approach to ternary search ; Function to perform Ternary Search ; Find the mid1 and mid2 ; Check if key is present at any mid ; Since key is not present at mid , check in which region it is present then repeat the Search operation in that region ; The key lies in between l and mid1 ; The key lies in between mid2 and r ; The key lies in between mid1 and mid2 ; Key not found ; Driver code ; Get the array Sort the array if not sorted ; Starting index ; length of array ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result
How can the above be solved in C?
targets: #include <stdio.h>
int ternarySearch ( int l , int r , int key , int ar [ ] ) { while ( r >= l ) { int mid1 = l + ( r - l ) / 3 ; int mid2 = r - ( r - l ) / 3 ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { r = mid1 - 1 ; } else if ( key > ar [ mid2 ] ) { l = mid2 + 1 ; } else { l = mid1 + 1 ; r = mid2 - 1 ; } } return -1 ; } int main ( ) { int l , r , p , key ; int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; printf ( " Index ▁ of ▁ % d ▁ is ▁ % d 
 " , key , p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; printf ( " Index ▁ of ▁ % d ▁ is ▁ % d " , key , p ) ; }
inputs: "Find the repeating and the missing number using two equations | Function to print the required numbers ; Sum of first n natural numbers ; Sum of squares of first n natural numbers ; To store the sum and sum of squares of the array elements ; Driver code"
Solution in php:
targets: < ? php function findNumbers ( $ arr , $ n ) { $ sumN = ( $ n * ( $ n + 1 ) ) / 2 ; $ sumSqN = ( $ n * ( $ n + 1 ) * ( 2 * $ n + 1 ) ) / 6 ; $ sum = 0 ; $ sumSq = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum += $ arr [ $ i ] ; $ sumSq += pow ( $ arr [ $ i ] , 2 ) ; } $ B = ( ( ( $ sumSq - $ sumSqN ) / ( $ sum - $ sumN ) ) + $ sumN - $ sum ) / 2 ; $ A = $ sum - $ sumN + $ B ; echo " A = " , ▁ $ A , ▁ " B = " } $ arr = array ( 1 , 2 , 2 , 3 , 4 ) ; $ n = sizeof ( $ arr ) ; findNumbers ( $ arr , $ n ) ; ? >
inputs: "Counting pairs when a person can form pair with at most one | Python program to find Number of ways in which participant can take part . ; Driver code"
How can the above be solved in Python?
targets: def numberOfWays ( x ) :
	dp = [ ]
	dp . append ( 1 )
	dp . append ( 1 )
	for i in range ( 2 , x + 1 ) :
		dp . append ( dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] )
	return ( dp [ x ] )
x = 3
print ( numberOfWays ( x ) )
inputs: "Sentinel Linear Search | Python3 implementation of the approach Function to search key in the given array ; Function to search x in the given array ; Last element of the array ; Element to be searched is placed at the last index ; Put the last element back ; Driver code"
Solution in Python:
targets: def sentinelSearch ( arr , n , key ) :
def sentinelSearch ( arr , n , key ) :
	last = arr [ n - 1 ]
	arr [ n - 1 ] = key
	i = 0
	while ( arr [ i ] != key ) :
		i += 1
	arr [ n - 1 ] = last
	if ( ( i < n - 1 ) or ( arr [ n - 1 ] == key ) ) :
		print ( key , " is ▁ present ▁ at ▁ index " , i )
	else :
		print ( " Element ▁ Not ▁ found " )
arr = [ 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 ]
n = len ( arr )
key = 180
sentinelSearch ( arr , n , key )
inputs: "Queries to find the minimum array sum possible by removing elements from either end | C # program for the above approach ; Function to find the minimum sum for each query after removing element from either ends till each value Q [ i ] ; Stores the prefix sum from both the ends of the array ; Traverse the array from front ; Insert it into the map m1 ; Traverse the array in reverse ; Insert it into the map m2 ; Traverse the query array ; Print the minimum of the two values as the answer ; Driver Code ; Function Call"
How can the above be solved in C-Sharp?
targets: using System ; using System . Collections . Generic ; class GFG { static void minOperations ( int [ ] arr , int N , int [ ] Q , int M ) { Dictionary < int , int > m1 = new Dictionary < int , int > ( ) ; Dictionary < int , int > m2 = new Dictionary < int , int > ( ) ; int front = 0 , rear = 0 ; for ( int i = 0 ; i < N ; i ++ ) { front += arr [ i ] ; m1 [ arr [ i ] ] = front ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { rear += arr [ i ] ; m2 [ arr [ i ] ] = rear ; } for ( int i = 0 ; i < M ; i ++ ) { Console . Write ( Math . Min ( m1 [ Q [ i ] ] , m2 [ Q [ i ] ] ) + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 2 , 3 , 6 , 7 , 4 , 5 , 1 } ; int N = arr . Length ; int [ ] Q = { 7 , 6 } ; int M = Q . Length ; minOperations ( arr , N , Q , M ) ; } }
inputs: "Sieve of Sundaram to print all primes smaller than n | Prints all prime numbers smaller ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than n , we reduce n to half ; This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j Initialize all elements as not marked ; Main logic of Sundaram . Mark all numbers of the form i + j + 2 ij as true where 1 <= i <= j ; Since 2 is a prime number ; Print other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Driver Code"
Solution in Python:
targets: def SieveOfSundaram ( n ) :
	nNew = int ( ( n - 1 ) / 2 ) ;
	marked = [ 0 ] * ( nNew + 1 ) ;
	for i in range ( 1 , nNew + 1 ) :
		j = i ;
		while ( ( i + j + 2 * i * j ) <= nNew ) :
			marked [ i + j + 2 * i * j ] = 1 ;
			j += 1 ;
	if ( n > 2 ) :
		print ( 2 , end = " ▁ " ) ;
	for i in range ( 1 , nNew + 1 ) :
		if ( marked [ i ] == 0 ) :
			print ( ( 2 * i + 1 ) , end = " ▁ " ) ;
n = 20 ;
SieveOfSundaram ( n ) ;
inputs: Program to find whether a given number is power of 2 |  ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function
How can the above be solved in C?
targets: #include <stdio.h>
#define bool  int
bool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( " Yes 
 " ) : printf ( " No 
 " ) ; isPowerOfTwo ( 64 ) ? printf ( " Yes 
 " ) : printf ( " No 
 " ) ; return 0 ; }
inputs: "Ordered Prime Signature | C # to find total number of divisors of a number , using ordered prime signature ; Finding primes upto entered number ; Finding primes by Sieve of Eratosthenes method ; If prime [ i ] is not changed , then it is prime ; Update all multiples of p ; Forming array of the prime numbers found ; Finding ordered prime signature of the number ; Map to store prime factors and the related exponents ; Declaring an iterator for map ; Finding prime factorization of the number ; Storing the prime factor and its exponent in map ; Storing the exponent in a List ; Sorting the stored exponents ; Printing the prime signature ; Finding total number of divisors of the number ; Adding one to each element present ; in ordered prime signature ; Multiplying the elements ; Driver Code"
Solution in C#:
targets: using System ; using System . Collections . Generic ; class GFG { static List < int > primes ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } List < int > arr = new List < int > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] ) arr . Add ( i ) ; } return arr ; } static List < int > signature ( int n ) { List < int > r = primes ( n ) ; var factor = new Dictionary < int , int > ( ) ; List < int > sort_exp = new List < int > ( ) ; int k , t = n ; for ( int i = 0 ; i < r . Count ; i ++ ) { if ( n % r [ i ] == 0 ) { k = 0 ; while ( n % r [ i ] == 0 ) { n = n / r [ i ] ; k ++ ; } factor . Add ( r [ i ] , k ) ; sort_exp . Add ( k ) ; } } sort_exp . Sort ( ) ; Console . Write ( " ▁ The ▁ Ordered ▁ Prime ▁ Signature ▁ of ▁ " + t + " ▁ is ▁ : ▁ 
 { ▁ " ) ; for ( int i = 0 ; i < sort_exp . Count ; i ++ ) { if ( i != sort_exp . Count - 1 ) Console . Write ( sort_exp [ i ] + " , ▁ " ) ; else Console . Write ( sort_exp [ i ] + " ▁ } 
 " ) ; } return sort_exp ; } static void divisors ( int n ) { int f = 1 , l ; List < int > div = signature ( n ) ; l = div . Count ; for ( int i = 0 ; i < l ; i ++ ) { div [ i ] += 1 ; f *= div [ i ] ; } Console . Write ( " The ▁ total ▁ number ▁ of ▁ divisors ▁ of ▁ " + n + " ▁ is ▁ " + f + " 
 " ) ; } static void Main ( ) { int n = 13 ; divisors ( n ) ; } }
inputs: "Maximum sum in circular array such that no two elements are adjacent | CPP program to find maximum sum in a circular array such that no elements are adjacent in the sum . ; Function to calculate the sum from 0 th position to ( n - 2 ) th position ; copy the element of original array to dp [ ] ; find the maximum element in the array ; start from 2 nd to n - 1 th pos ; traverse for all pairs bottom - up approach ; dp - condition ; find maximum sum ; return the maximum ; Function to find the maximum sum from 1 st position to n - 1 - th position ; Traverse from third to n - th pos ; bootom - up approach ; dp condition ; find max sum ; return max ; Driver Code"
How can the above be solved in C++?
targets: #include <bits/stdc++.h>
using namespace std ; int maxSum1 ( int arr [ ] , int n ) { int dp [ n ] ; int maxi = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { dp [ i ] = arr [ i ] ; if ( maxi < arr [ i ] ) maxi = arr [ i ] ; } for ( int i = 2 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < i - 1 ; j ++ ) { if ( dp [ i ] < dp [ j ] + arr [ i ] ) { dp [ i ] = dp [ j ] + arr [ i ] ; if ( maxi < dp [ i ] ) maxi = dp [ i ] ; } } } return maxi ; } int maxSum2 ( int arr [ ] , int n ) { int dp [ n ] ; int maxi = 0 ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = arr [ i ] ; if ( maxi < arr [ i ] ) maxi = arr [ i ] ; } for ( int i = 3 ; i < n ; i ++ ) { for ( int j = 1 ; j < i - 1 ; j ++ ) { if ( dp [ i ] < arr [ i ] + dp [ j ] ) { dp [ i ] = arr [ i ] + dp [ j ] ; if ( maxi < dp [ i ] ) maxi = dp [ i ] ; } } } return maxi ; } int findMaxSum ( int arr [ ] , int n ) { return max ( maxSum1 ( arr , n ) , maxSum2 ( arr , n ) ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxSum ( arr , n ) ; return 0 ; }
inputs: "Program to find whether a no is power of two |  ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function"
Solution in C:
targets: #include <stdio.h>
#define bool  int
bool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( " Yes 
 " ) : printf ( " No 
 " ) ; isPowerOfTwo ( 64 ) ? printf ( " Yes 
 " ) : printf ( " No 
 " ) ; return 0 ; }
inputs: "Check if permutation of first N natural numbers exists having Bitwise AND of adjacent elements non | Java Program to implement the above approach ; Function to check if a permutation of first N natural numbers exist with Bitwise AND of adjacent elements not equal to 0 ; If n is a power of 2 ; Driver Code"
How can the above be solved in Java?
targets: import java . util . * ; class solution { static void check ( int n ) { if ( ( n & n - 1 ) != 0 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } public static void main ( String args [ ] ) { int n = 5 ; check ( n ) ; } }
inputs: "Side of a regular n | Function to calculate the side of the polygon circumscribed in a circle ; Total sides of the polygon ; Radius of the circumscribing circle"
Solution in php:
targets: < ? php function calculateSide ( $ n , $ r ) { $ theta ; $ theta_in_radians ; $ theta = 360 / $ n ; $ theta_in_radians = $ theta * 3.14 / 180 ; return 2 * $ r * sin ( $ theta_in_radians / 2 ) ; } $ n = 3 ; $ r = 5 ; echo calculateSide ( $ n , $ r ) ; ? >
inputs: "Maximum number of operations required such that no pairs from a Matrix overlap | Function to find maximum count of operations ; Initialize count by 0 ; Iterate over remaining pairs ; Check if first operation is applicable ; Check if 2 nd operation is applicable ; Otherwise ; Return the count of operations ; Driver Code"
How can the above be solved in JS?
targets: function find_max ( v , n ) { let count = 0 ; if ( n >= 2 ) count = 2 ; else count = 1 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( v [ i - 1 ] [ 0 ] < ( v [ i ] [ 0 ] - v [ i ] [ 1 ] ) ) count ++ ; else if ( v [ i + 1 ] [ 0 ] > ( v [ i ] [ 0 ] + v [ i ] [ 1 ] ) ) { count ++ ; v [ i ] [ 0 ] = v [ i ] [ 0 ] + v [ i ] [ 1 ] ; } else continue ; } return count ; } let n = 3 ; let v = [ [ 10 , 20 ] , [ 15 , 10 ] , [ 20 , 16 ] ] ; document . write ( find_max ( v , n ) ) ;
inputs: "Program To Check whether a Triangle is Equilateral , Isosceles or Scalene | Java program for the above approach ; Function to check if the triangle is equilateral or isosceles or scalene ; Check for equilateral triangle ; Check for isosceles triangle ; Otherwise scalene triangle ; Driver Code ; Given sides of triangle ; Function call"
Solution in Java:
targets: class GFG { static void checkTriangle ( int x , int y , int z ) { if ( x == y && y == z ) System . out . println ( " Equilateral ▁ Triangle " ) ; else if ( x == y y == z z == x ) System . out . println ( " Isosceles ▁ Triangle " ) ; else System . out . println ( " Scalene ▁ Triangle " ) ; } public static void main ( String [ ] args ) { int x = 8 , y = 7 , z = 9 ; checkTriangle ( x , y , z ) ; } }