codeparrot/xlcost-text-to-code huggingface dataset:
Smallest indexed array element required to be flipped to make sum of array equal to 0 | Java program for above approach ; Function to find the smallest indexed array element required to be flipped to make sum of the given array equal to 0 ; Stores the required index ; Stores the sum of the array ; Traverse the given array ; Update ArrSum ; Traverse the given array ; If sum of array elements double the value of the current element ; Update pos ; Driver function
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int smallestIndexArrayElementsFlip ( int arr [ ] , int N ) { int pos = - 1 ; int ArrSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ArrSum += arr [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { if ( 2 * arr [ i ] == ArrSum ) { pos = i ; break ; } } return pos ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , - 5 , 3 , 4 } ; int N = arr . length ; System . out . println ( smallestIndexArrayElementsFlip ( arr , N ) ) ; } }
Check if a string can be converted to another given string by removal of a substring | Java program to implement the above approach ; Function to check if S can be converted to T by removing at most one subString from S ; Check if S can be converted to T by removing at most one subString from S ; Stores length of String T ; Stores length of String S ; Iterate over the range [ 0 , M - 1 ] ; Stores Length of the subString { S [ 0 ] , ... , S [ i ] } ; Stores Length of the subString { S [ 0 ] , ... , S [ i ] } ; Stores prefix subString ; Stores suffix subString ; Checking if prefix + suffix == T ; Driver Code ; Given String S and T ; Function call
import java . util . * ; class GFG { static String make_String_S_to_T ( String S , String T ) { boolean possible = false ; int M = T . length ( ) ; int N = S . length ( ) ; for ( int i = 0 ; i <= M ; i ++ ) { int prefix_length = i ; int suffix_length = M - i ; String prefix = S . substring ( 0 , prefix_length ) ; String suffix = S . substring ( N - suffix_length , N ) ; if ( ( prefix + suffix ) . equals ( T ) ) { possible = true ; break ; } } if ( possible ) return " YES " ; else return " NO " ; } public static void main ( String [ ] args ) { String S = " ababcdcd " ; String T = " abcd " ; System . out . print ( make_String_S_to_T ( S , T ) ) ; } }
Sum of maximum of all subarrays by adding even frequent maximum twice | Java program for the above approach ; Function to calculate sum of maximum of all subarrays ; Stores the sum of maximums ; Traverse the array ; Store the frequency of the maximum element in subarray ; Finding maximum ; Increment frequency by 1 ; If new maximum is obtained ; If frequency of maximum is even , then add 2 * maxNumber . Otherwise , add maxNumber ; Print the sum obtained ; Driver Code ; Function Call
import java . io . * ; class GFG { public static void findSum ( int a [ ] ) { int ans = 0 ; for ( int low = 0 ; low < a . length ; low ++ ) { for ( int high = low ; high < a . length ; high ++ ) { int count = 0 ; int maxNumber = 0 ; for ( int i = low ; i <= high ; i ++ ) { if ( a [ i ] == maxNumber ) count ++ ; else if ( a [ i ] > maxNumber ) { maxNumber = a [ i ] ; count = 1 ; } } ans += maxNumber * ( ( count % 2 == 0 ) ? 2 : 1 ) ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 4 , 4 , 2 } ; findSum ( arr ) ; } }
Count pairs of indices having equal prefix and suffix sums | Java program for the above approach ; Function to find the count of index pairs having equal prefix and suffix sums ; Maps indices with prefix sums ; Traverse the array ; Update prefix sum ; Update frequency in Map ; Traverse the array in reverse ; Update suffix sum ; Check if any prefix sum of equal value exists or not ; Print the obtained count ; Driver code ; Given array ; Given size ; Function Call
import java . util . * ; class GFG { static void countPairs ( int [ ] arr , int n ) { HashMap < Integer , Integer > mp1 = new HashMap < Integer , Integer > ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( mp1 . containsKey ( sum ) ) { mp1 . put ( sum , mp1 . get ( sum ) + 1 ) ; } else { mp1 . put ( sum , 1 ) ; } } sum = 0 ; int ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; if ( mp1 . containsKey ( sum ) ) { ans += mp1 . get ( sum ) ; } } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 1 , 1 } ; int n = arr . length ; countPairs ( arr , n ) ; } }
Queries to count Composite Magic Numbers from a given range [ L , R ] | Java program to implement the above approach ; Check if a number is magic number or not ; Check number is composite number or not ; Corner cases ; Check if the number is a multiple of 2 or 3 ; Check for multiples of remaining primes ; Function to find Composite Magic Numbers in given ranges ; dp [ i ] : Stores the count of composite Magic numbers up to i ; Traverse in the range [ 1 , 1e5 ) ; Check if number is Composite number as well as a Magic number or not ; Print results for each query ; Driver Code
class GFG { static boolean isMagic ( int num ) { return ( num % 9 == 1 ) ; } static boolean isComposite ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } static void find ( int L [ ] , int R [ ] , int q ) { int dp [ ] = new int [ 1000005 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; for ( int i = 1 ; i < 1000005 ; i ++ ) { if ( isComposite ( i ) && isMagic ( i ) == true ) { dp [ i ] = dp [ i - 1 ] + 1 ; } else dp [ i ] = dp [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) System . out . println ( dp [ R [ i ] ] - dp [ L [ i ] - 1 ] ) ; } public static void main ( String [ ] args ) { int L [ ] = { 10 , 3 } ; int R [ ] = { 100 , 2279 } ; int Q = 2 ; find ( L , R , Q ) ; } }
Smallest positive integer that divides all array elements to generate quotients with sum not exceeding K | Java program to implement the above approach ; Function to find the smallest positive integer that divides array elements to get the sum <= K ; Stores minimum possible of the smallest positive integer satisfying the condition ; Stores maximum possible of the smallest positive integer satisfying the condition ; Apply binary search over the range [ left , right ] ; Stores middle element of left and right ; Stores sum of array elements ; Traverse the array ; Update sum ; If sum is greater than K ; Update left ; Update right ; Driver code
import java . util . * ; class GFG { static int findSmallestInteger ( int arr [ ] , int N , int K ) { int left = 1 ; int right = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; while ( left < right ) { int mid = ( left + right ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += ( arr [ i ] + mid - 1 ) / mid ; } if ( sum > K ) { left = mid + 1 ; } else { right = mid ; } } return left ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 5 , 9 } ; int N = arr . length ; int K = 6 ; System . out . println ( findSmallestInteger ( arr , N , K ) ) ; } }
Minimum Deci | Java program to implement the above approach ; Function to find the count of minimum Deci - Binary numbers required to obtain S ; Stores the minimum count ; Iterate over the string s ; Convert the char to its equivalent integer ; If current character is the maximum so far ; Update the maximum digit ; Print the required result ; Driver Code
class GFG { static int minimum_deci_binary_number ( String s ) { int m = Integer . MIN_VALUE ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int temp = s . charAt ( i ) - '0' ; if ( temp > m ) { m = temp ; } } return m ; } public static void main ( String [ ] args ) { String S = "31" ; System . out . println ( minimum_deci_binary_number ( S ) ) ; } }
Make all the elements of array odd by incrementing odd | Java program for the above approach ; Function to count minimum subarrays whose odd - indexed elements need to be incremented to make array odd ; Stores the minimum number of operations required ; Iterate over even - indices ; Check if the current element is odd ; If true , continue ; Otherwise , mark the starting of the subarray and iterate until i < n and arr [ i ] is even ; Increment number of operations ; Iterate over odd indexed positions of arr [ ] ; Check if the current element is odd ; If true , continue ; Otherwise , mark the starting of the subarray and iterate until i < n and arr [ i ] is even ; Increment the number of operations ; Print the number of operations ; Driver Code ; Function Call
import java . util . * ; class GFG { static void minOperations ( int arr [ ] , int n ) { int flips = 0 ; for ( int i = 0 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } for ( int i = 1 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } System . out . println ( flips ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 3 , 5 , 3 , 2 } ; int N = arr . length ; minOperations ( arr , N ) ; } }
Minimum substring reversals required to make given Binary String alternating | Java program for the above approach ; Function to count the minimum number of substrings required to be reversed to make the string S alternating ; Store count of consecutive pairs ; Stores the count of 1 s and 0 s ; Traverse through the string ; Increment 1 s count ; Increment 0 s count ; Increment K if consecutive same elements are found ; Increment 1 s count ; else Increment 0 s count ; Check if it is possible or not ; Otherwise , print the number of required operations ; Driver code ; Function Call
import java . util . * ; import java . lang . * ; class GFG { static int minimumReverse ( String s , int n ) { int k = 0 , l = 0 ; int sum1 = 0 , sum0 = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) sum1 ++ ; else sum0 ++ ; if ( s . charAt ( i ) == s . charAt ( i - 1 ) && s . charAt ( i ) == '0' ) k ++ ; else if ( s . charAt ( i ) == s . charAt ( i - 1 ) && s . charAt ( i ) == '1' ) l ++ ; } if ( s . charAt ( 0 ) == '1' ) sum1 ++ ; sum0 ++ ; if ( Math . abs ( sum1 - sum0 ) > 1 ) return - 1 ; return Math . max ( k , l ) ; } public static void main ( String [ ] args ) { String S = "10001" ; int N = S . length ( ) ; System . out . print ( minimumReverse ( S , N ) ) ; } }
Count pairs with Even Product from two given arrays | Java program to implement the above approach ; Function to count pairs ( arr [ i ] , brr [ j ] ) whose product is an even number ; Stores count of odd numbers in arr [ ] ; Stores count of odd numbers in brr [ ] ; Traverse the array , arr [ ] ; If arr [ i ] is an odd number ; Update cntOddArr ; Traverse the array , brr [ ] ; If brr [ i ] is an odd number ; Update cntOddArr ; Return pairs whose product is an even number ; Driver Code
import java . util . * ; class GFG { static int cntPairsInTwoArray ( int arr [ ] , int brr [ ] , int N , int M ) { int cntOddArr = 0 ; int cntOddBrr = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { cntOddArr += 1 ; } } for ( int i = 0 ; i < M ; i ++ ) { if ( brr [ i ] % 2 == 1 ) { cntOddBrr += 1 ; } } return ( N * M ) - ( cntOddArr * cntOddBrr ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int N = arr . length ; int brr [ ] = { 1 , 2 } ; int M = brr . length ; System . out . print ( cntPairsInTwoArray ( arr , brr , N , M ) ) ; } }
Maximize frequency of an element by at most one increment or decrement of all array elements | Java program to implement the above approach ; Function to maximize the frequency of an array element by incrementing or decrementing array elements at most once ; Stores the largest array element ; Stores the smallest array element ; freq [ i ] : Stores frequency of ( i + Min ) in the array ; Traverse the array ; Update frequency of arr [ i ] ; Stores maximum frequency of an array element by incrementing or decrementing array elements ; Iterate all the numbers over the range [ Min , Max ] ; Stores sum of three consecutive numbers ; Update maxSum ; Print maxSum ; Driver Code ; Function call
import java . util . Arrays ; class GFG { static void max_freq ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int Max = arr [ N - 1 ] ; int Min = arr [ 0 ] ; int freq [ ] = new int [ Max - Min + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { freq [ arr [ i ] - Min ] ++ ; } int maxSum = 0 ; for ( int i = 0 ; i < ( Max - Min - 1 ) ; i ++ ) { int val = freq [ i ] + freq [ i + 1 ] + freq [ i + 2 ] ; maxSum = Math . max ( maxSum , val ) ; } System . out . println ( maxSum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 1 , 4 , 1 , 5 , 9 , 2 } ; int N = arr . length ; max_freq ( arr , N ) ; } }
Longest increasing subsequence consisting of elements from indices divisible by previously selected indices | Java program for the above approach ; Function to find length of longest subsequence generated that satisfies the specified conditions ; Stores the length of longest subsequences of all lengths ; Iterate through the given array ; Iterate through the multiples i ; Update dp [ j ] as maximum of dp [ j ] and dp [ i ] + 1 ; Return the maximum element in dp [ ] as the length of longest subsequence ; Driver Code ; Function Call
import java . util . * ; class GFG { static int findMaxLength ( int N , int [ ] arr ) { int [ ] dp = new int [ N + 1 ] ; Arrays . fill ( dp , 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 2 * i ; j <= N ; j += i ) { if ( arr [ i - 1 ] < arr [ j - 1 ] ) { dp [ j ] = Math . max ( dp [ j ] , dp [ i ] + 1 ) ; } } } return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int N = arr . length ; System . out . print ( findMaxLength ( N , arr ) ) ; } }
Queries to check if any pair exists in an array having values at most equal to the given pair | Java program for above approach ; Function that performs binary search to find value less than or equal to first value of the pair ; Perform binary search ; Find the mid ; Update the high ; Else update low ; Return the low index ; Function to modify the second value of each pair ; start from index 1 ; Function to evaluate each query ; Find value less than or equal to the first value of pair ; check if we got the required pair or not ; Function to find a pair whose values is less than the given pairs in query ; Find the size of the vector ; sort the vector based on the first value ; Function Call to modify the second value of each pair ; Traverse each queries ; Evaluate each query ; Print the result ; Driver function ; Function Call
import java . util . * ; import java . lang . * ; class GFG { static int binary_search ( int [ ] [ ] vec , int n , int a ) { int low , high , mid ; low = 0 ; high = n - 1 ; while ( low < high ) { mid = low + ( high - low + 1 ) / 2 ; if ( vec [ mid ] [ 0 ] > a ) { high = mid - 1 ; } else if ( vec [ mid ] [ 1 ] <= a ) { low = mid ; } } return low ; } static void modify_vec ( int [ ] [ ] v , int n ) { for ( int i = 1 ; i < n ; i ++ ) { v [ i ] [ 1 ] = Math . min ( v [ i ] [ 1 ] , v [ i - 1 ] [ 1 ] ) ; } } static int evaluate_query ( int [ ] [ ] v , int n , int m1 , int m2 ) { int temp = binary_search ( v , n , m1 ) ; if ( ( v [ temp ] [ 0 ] <= m1 ) && ( v [ temp ] [ 1 ] <= m2 ) ) { return 1 ; } return 0 ; } static void checkPairs ( int [ ] [ ] v , int [ ] [ ] queries ) { int n = v . length ; Arrays . sort ( v , ( a , b ) -> a [ 0 ] - b [ 0 ] ) ; modify_vec ( v , n ) ; int k = queries . length ; for ( int i = 0 ; i < k ; i ++ ) { int m1 = queries [ i ] [ 0 ] ; int m2 = queries [ i ] [ 1 ] ; int result = evaluate_query ( v , n , m1 , m2 ) ; if ( result > 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 3 , 5 } , { 2 , 7 } , { 2 , 3 } , { 4 , 9 } } ; int [ ] [ ] queries = { { 3 , 4 } , { 3 , 2 } , { 4 , 1 } , { 3 , 7 } } ; checkPairs ( arr , queries ) ; } }
Sort a stream of integers | Java program for the above approach ; Function to sort a stream of integers ; Stores the position of array elements ; Traverse through the array ; If any element is found to be greater than the current element ; If an element > num is not present ; Otherwise , place the number at its right position ; Function to print the sorted stream of integers ; Stores the sorted stream of integers ; Traverse the array ; Function Call ; Print the array after every insertion ; Driver Code
import java . util . * ; class GFG { static void Sort ( Vector < Integer > ans , int num ) { int pos = - 1 ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { if ( ans . get ( i ) >= num ) { pos = i ; break ; } } if ( pos == - 1 ) ans . add ( num ) ; else ans . add ( pos , num ) ; } static void sortStream ( int arr [ ] , int N ) { Vector < Integer > ans = new Vector < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Sort ( ans , arr [ i ] ) ; for ( int j = 0 ; j < ans . size ( ) ; j ++ ) { System . out . print ( ans . get ( j ) + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 1 , 7 , 6 , 2 } ; int N = arr . length ; sortStream ( arr , N ) ; } }
Count ways to split array into two equal sum subarrays by changing sign of any one array element | Java program for the above approach ; Function to count ways of splitting the array in two subarrays of equal sum by changing sign of any 1 element ; Stores the count of elements in prefix and suffix of array ; Stores the total sum of array ; Traverse the array ; Increase the frequency of current element in suffix ; Stores prefix sum upto an index ; Stores sum of suffix from an index ; Stores the count of ways to split the array in 2 subarrays having equal sum ; Traverse the array ; Modify prefix sum ; Add arr [ i ] to prefix Map ; Calculate suffix sum by subtracting prefix sum from total sum of elements ; Remove arr [ i ] from suffix Map ; Store the difference between the subarrays ; Check if diff is even or not ; Count number of ways to split array at index i such that subarray sums are same ; Update the count ; Return the count ; Driver Code ; Function Call
import java . util . * ; class GFG { static int countSubArraySignChange ( int arr [ ] , int N ) { HashMap < Integer , Integer > prefixCount = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > suffixCount = new HashMap < Integer , Integer > ( ) ; int total = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { total += arr [ i ] ; if ( suffixCount . containsKey ( arr [ i ] ) ) { suffixCount . put ( arr [ i ] , suffixCount . get ( arr [ i ] ) + 1 ) ; } else { suffixCount . put ( arr [ i ] , 1 ) ; } } int prefixSum = 0 ; int suffixSum = 0 ; int count = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { prefixSum += arr [ i ] ; if ( prefixCount . containsKey ( arr [ i ] ) ) { prefixCount . put ( arr [ i ] , prefixCount . get ( arr [ i ] ) + 1 ) ; } else { prefixCount . put ( arr [ i ] , 1 ) ; } suffixSum = total - prefixSum ; if ( suffixCount . containsKey ( arr [ i ] ) ) { suffixCount . put ( arr [ i ] , suffixCount . get ( arr [ i ] ) - 1 ) ; } int diff = prefixSum - suffixSum ; if ( diff % 2 == 0 ) { int x = ( prefixCount . containsKey ( diff / 2 ) ? prefixCount . get ( diff / 2 ) : 0 ) + ( suffixCount . containsKey ( - diff / 2 ) ? suffixCount . get ( - diff / 2 ) : 0 ) ; count = count + x ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , - 3 , 3 } ; int N = arr . length ; System . out . print ( countSubArraySignChange ( arr , N ) ) ; } }
Partition string into two substrings having maximum number of common non | Java program to implement the above approach ; Function to count maximum common non - repeating characters that can be obtained by partitioning the String into two non - empty subStrings ; Stores count of non - repeating characters present in both the subStrings ; Stores distinct characters in left subString ; Stores distinct characters in right subString ; Traverse left subString ; Insert S [ i ] into ls ; Traverse right subString ; Insert S [ i ] into rs ; Traverse distinct characters of left subString ; If current character is present in right subString ; Update cnt ; Return count ; Function to partition the String into two non - empty subStrings in all possible ways ; Stores maximum common distinct characters present in both the subString partitions ; Traverse the String ; Update ans ; Print count of maximum common non - repeating characters ; Driver Code
import java . util . * ; class GFG { static int countCommonChar ( int ind , String S ) { int cnt = 0 ; HashSet < Character > ls = new HashSet < Character > ( ) ; HashSet < Character > rs = new HashSet < Character > ( ) ; for ( int i = 0 ; i < ind ; ++ i ) { ls . add ( S . charAt ( i ) ) ; } for ( int i = ind ; i < S . length ( ) ; ++ i ) { rs . add ( S . charAt ( i ) ) ; } for ( char v : ls ) { if ( rs . contains ( v ) ) { ++ cnt ; } } return cnt ; } static void partitionStringWithMaxCom ( String S ) { int ans = 0 ; for ( int i = 1 ; i < S . length ( ) ; ++ i ) { ans = Math . max ( ans , countCommonChar ( i , S ) ) ; } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { String str = " aabbca " ; partitionStringWithMaxCom ( str ) ; } }
Partition string into two substrings having maximum number of common non | Java program to implement the above approach ; Function to count maximum common non - repeating characters that can be obtained by partitioning the String into two non - empty subStrings ; Stores distinct characters of S in sorted order ; Stores maximum common distinct characters present in both the partitions ; Stores frequency of each distinct character n the String S ; Traverse the String ; Update frequency of S [ i ] ; Traverse the String ; Decreasing frequency of S [ i ] ; If the frequency of S [ i ] is 0 ; Remove S [ i ] from Q ; Insert S [ i ] into Q ; Stores count of distinct characters in Q ; Update res ; Driver Code ; Function call
import java . util . * ; class GFG { static void countMaxCommonChar ( char [ ] S ) { LinkedHashSet < Character > Q = new LinkedHashSet < > ( ) ; int res = 1 ; HashMap < Character , Integer > freq = new HashMap < > ( ) ; for ( int i = 0 ; i < S . length ; i ++ ) { if ( freq . containsKey ( S [ i ] ) ) { freq . put ( S [ i ] , freq . get ( S [ i ] ) + 1 ) ; } else { freq . put ( S [ i ] , 1 ) ; } } for ( int i = 0 ; i < S . length ; i ++ ) { if ( freq . containsKey ( S [ i ] ) ) { freq . put ( S [ i ] , freq . get ( S [ i ] ) - 1 ) ; } if ( ! freq . containsKey ( S [ i ] ) ) { Q . remove ( S [ i ] ) ; } else { Q . add ( S [ i ] ) ; } int curr = Q . size ( ) - 1 ; res = Math . max ( res , curr ) ; } System . out . print ( res + "NEW_LINE"); } public static void main ( String [ ] args ) { String str = " aabbca " ; countMaxCommonChar ( str . toCharArray ( ) ) ; } }