codeparrot/xlcost-text-to-code huggingface dataset:
Minimize flips to make binary string as all 1 s by flipping characters in substring of size K repeatedly | Java program for the above approach ; Function to find the minimum number of operations required to convert all the characters to 1 by flipping the substrings of size K ; Stores the minimum number of operations required ; Traverse the string S ; If the character is 0 ; Flip the substrings of size K starting from i ; Increment the minimum count of operations required ; After performing the operations check if string S contains any 0 s ; If S contains only 1 's ; Driver Code
public class GFG { static void minOperation ( String S , int K , int N ) { int min = 0 ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == '0' && i + K <= N ) { for ( int j = i ; j < i + K ; j ++ ) { if ( S . charAt ( j ) == '1' ) S = S . substring ( 0 , j ) + '0' + S . substring ( j + 1 ) ; else S = S . substring ( 0 , j ) + '1' + S . substring ( j + 1 ) ; } min ++ ; } } for ( i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == '0' ) break ; } if ( i == N ) System . out . println ( min ) ; else System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { String S = "00010110" ; int K = 3 ; int N = S . length ( ) ; minOperation ( S , K , N ) ; } }
Check if string S1 can be formed using repeated insertions of another string S2 | Java program for the above approach ; Function to check a valid insertion ; Store the size of string ; Maintain a stack for characters ; Iterate through the string ; push the current character on top of the stack ; If the current character is the last character of string S2 then pop characters until S2 is not formed ; index of last character of the string S2 ; pop characters till 0 - th index ; Check if stack in non - empty ; Driver code
import java . io . * ; import java . util . * ; class GFG { static boolean validInsertionstring ( String S1 , String S2 ) { int N = S1 . length ( ) ; int M = S2 . length ( ) ; Stack < Character > st = new Stack < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { st . push ( S1 . charAt ( i ) ) ; if ( S1 . charAt ( i ) == S2 . charAt ( M - 1 ) ) { int idx = M - 1 ; while ( idx >= 0 ) { if ( st . size ( ) == 0 ) { return false ; } char c = st . peek ( ) ; st . pop ( ) ; if ( c != S2 . charAt ( idx ) ) { return false ; } idx -- ; } } } if ( st . size ( ) > 0 ) { return false ; } else { return true ; } } public static void main ( String [ ] args ) { String S1 = " aabb " ; String S2 = " ab " ; if ( validInsertionstring ( S1 , S2 ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Check if rearranging Array elements can form a Palindrome or not | Java implementation of the above approach ; Function to check whether elements of an array can form a palindrome ; create an empty string to append elements of an array ; append each element to the string str to form a string so that we can solve it in easy way ; Create a freq array and initialize all values as 0 ; For each character in formed string , increment freq in the corresponding freq array ; Count odd occurring characters ; Return true if odd count is 0 or 1 , ; Drive code
import java . io . * ; import java . util . Arrays ; class GFG { static int MAX = 256 ; static boolean can_form_palindrome ( int [ ] arr , int n ) { String str = " " ; for ( int i = 0 ; i < n ; i ++ ) { str += arr [ i ] ; } int freq [ ] = new int [ MAX ] ; Arrays . fill ( freq , 0 ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { freq [ str . charAt ( i ) ] ++ ; } int count = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( ( freq [ i ] & 1 ) != 0 ) { count ++ ; } if ( count > 1 ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 1 , 2 } ; int n = arr . length ; if ( can_form_palindrome ( arr , n ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }
Minimum number of flips to make a Binary String increasing | Java program for the above approach ; ; Function to find the minimum number of flips required to make String increasing ; Length of s ; Total number of zero in s ; Stores count of 1 s till ith index ; stors the minimum count of flip ; Traverse the given String ; Update the value of res and count of 1 s ; Return the minimum number of flips ; Utility count ; Driver code ; Given String ; function call
import java . util . * ; class GFG { static int minimumFlips ( String s ) { int n = s . length ( ) ; int cnt0 = count ( s , '0' ) ; int cnt1 = 0 ; int res = n - cnt0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '0' ) { cnt0 -= 1 ; } else if ( s . charAt ( i ) == '1' ) { res = Math . min ( res , cnt1 + cnt0 ) ; cnt1 ++ ; } } return res ; } private static int count ( String s , char c ) { int ans = 0 ; for ( char i : s . toCharArray ( ) ) if ( c == i ) ans ++ ; return ans ; } public static void main ( String [ ] args ) { String S = "000110" ; System . out . print ( minimumFlips ( S ) ) ; } }
Lexicographically shortest string of length at most K which is not a substring of given String | Java implementation for above approach ; Function to return a set of all subStrings of given String which have length less than or equal to k ; Function to print the lexicographically smallest subString of length atmost k which is not present in given String s ; All subStrings of length atmost k present in String s are stored in this set ; Loop to change length of subString ; String with length = len which has all characters as ' a ' ; If the subStrings set does not contain this String then we have found the answer ; Changing the likes of ' azz ' and ' daz ' to ' baa ' and ' dba ' respectively ; Reached a String like ' zz ' or ' zzz ' increase the length of the subString ; Driver Code ; Given Input ; Function Call
import java . util . * ; class GFG { static HashSet < String > presentSubString ( String s , int k ) { HashSet < String > st = new HashSet < String > ( ) ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s1 = " " ; for ( int j = 0 ; j < k && i + j < n ; j ++ ) { s1 += s . charAt ( i + j ) ; st . add ( s1 ) ; } } return st ; } static String smallestSubString ( String s , int k ) { HashSet < String > st = new HashSet < String > ( ) ; st = presentSubString ( s , k ) ; int index ; for ( int len = 1 ; len <= k ; len ++ ) { String t = " " ; for ( int i = 0 ; i < len ; i ++ ) t += ' a ' ; while ( true ) { if ( ! st . contains ( t ) ) { return t ; } index = len - 1 ; while ( index >= 0 && t . charAt ( index ) == ' z ' ) { t = t . substring ( 0 , index ) + ' a ' + t . substring ( index + 1 ) ; index -- ; } if ( index >= 0 ) t = t . substring ( 0 , index ) + ( char ) ( ( t . charAt ( index ) ) + 1 ) + t . substring ( index + 1 ) ; else break ; } } return " - 1" ; } public static void main ( String [ ] args ) { String s = " sdhaacbdefghijklmnopqrstuvwxyz " ; int K = 3 ; System . out . print ( smallestSubString ( s , K ) + "NEW_LINE"); } }
Maximum length of a substring required to be flipped repeatedly to make all characters of binary string equal to 0 | Java code for above approach ; Function to find the maximum value of K such that flipping substrings of size at least K make all characters 0 s ; Stores the maximum value of K ; Traverse the given string S ; Store the minimum of the maximum of LHS and RHS length ; Flip performed ; If no flips performed ; Return the possible value of K ; Driver Code
import java . util . * ; class GFG { static int maximumK ( String S ) { int N = S . length ( ) ; int ans = N ; int flag = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( i + 1 ) ) { flag = 1 ; ans = Math . min ( ans , Math . max ( i + 1 , N - i - 1 ) ) ; } } if ( flag == 0 ) return 0 ; return ans ; } public static void main ( String [ ] args ) { String S = "010" ; System . out . print ( maximumK ( S ) ) ; } }
Minimum moves to make count of lowercase and uppercase letters equal | Java program for the above approach ; Function to calculate minimum number of moves required to convert the string ; Stores Count of upper and lower case characters ; Traverse the string S ; If current character is uppercase ; Increment count of Uppercase characters ; Otherwise , ; Increment count of Lowercase characters ; Stores minimum number of moves needed ; If there are more upper case characters ; Iterate until upper is greater than N / 2 ; Convert uppercase into lowercase until upper = N / 2 ; Increment the pointer ; If there are more lower case characters ; Iterate until lower is greater than N / 2 ; Convert lowercase into uppercase until lower = N / 2 ; Increment the pointer ; Print moves required ; Print resultant string ; Driver code ; Given string ; Function call
class GFG { static void minimumTimeToConvertString ( String S , int N ) { int upper = 0 , lower = 0 ; for ( int i = 0 ; i < N ; i ++ ) { char c = S . charAt ( i ) ; if ( Character . isUpperCase ( c ) ) { upper ++ ; } else { lower ++ ; } } int moves = 0 ; if ( upper > N / 2 ) { int i = 0 ; while ( upper > N / 2 && i < N ) { if ( Character . isUpperCase ( S . charAt ( i ) ) ) { S = S . substring ( 0 , i ) + ( char ) ( S . charAt ( i ) + 32 ) + S . substring ( i + 1 ) ; moves ++ ; upper -- ; lower ++ ; } i ++ ; } } else if ( lower > N / 2 ) { int i = 0 ; while ( lower > N / 2 && i < N ) { if ( Character . isLowerCase ( S . charAt ( i ) ) ) { S = S . substring ( 0 , i ) + ( char ) ( S . charAt ( i ) - 32 ) + S . substring ( i + 1 ) ; moves ++ ; upper ++ ; lower -- ; } i ++ ; } } System . out . println ( moves ) ; System . out . println ( S ) ; } public static void main ( String [ ] args ) { String S = " AbcdEf " ; int N = S . length ( ) ; minimumTimeToConvertString ( S , N ) ; } }
Program to print a string in vertical zigzag manner | Java program for the above approach ; Function to print any string in zigzag fashion ; Store the gap between the major columns ; Traverse through rows ; Store the step value for each row ; Iterate in the range [ 1 , N - 1 ] ; Print the character ; Print the spaces before character s [ j + step ] ; Print the character ; Print the spaces after character after s [ j + step ] ; Print the spaces for first and last rows ; Driver Code ; Given Input ; Function Call
public class GFG { static void zigzag ( String s , int rows ) { int interval = 2 * rows - 2 ; for ( int i = 0 ; i < rows ; i ++ ) { int step = interval - 2 * i ; for ( int j = i ; j < s . length ( ) ; j = j + interval ) { System . out . print ( s . charAt ( j ) ) ; if ( step > 0 && step < interval && step + j < s . length ( ) ) { for ( int k = 0 ; k < ( interval - rows - i ) ; k ++ ) System . out . print ( " ▁ " ) ; System . out . print ( s . charAt ( j + step ) ) ; for ( int k = 0 ; k < i - 1 ; k ++ ) System . out . print ( " ▁ " ) ; } else { for ( int k = 0 ; k < ( interval - rows ) ; k ++ ) System . out . print ( " ▁ " ) ; } } System . out . println ( ) ; } } public static void main ( String args [ ] ) { String s = "123456789ABCDEFGHIJKLM " + " NOPQRSTUVWXYZabcdefghi " + " jklmnopqrstuvwxyz " ; int rows = 9 ; zigzag ( s , rows ) ; } }
Number of substrings with each character occurring even times | Java program for the above approach ; Function to count substrings having even frequency of each character ; Stores the count of a character ; Stores bitmask ; Stores the count of substrings with even count of each character ; Traverse the string S ; Flip the ord ( i ) - 97 bits in pre ; Increment the count by hash [ pre ] ; Increment count of pre in hash ; Return the total count obtained ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static int subString ( String s , int n ) { Map < Integer , Integer > hash = new HashMap < > ( ) ; hash . put ( 0 , 1 ) ; int pre = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { pre ^= ( 1 << ( int ) ( s . charAt ( i ) - 97 ) ) ; count += hash . getOrDefault ( pre , 0 ) ; hash . put ( pre , hash . getOrDefault ( pre , 0 ) + 1 ) ; } return count ; } public static void main ( String [ ] args ) { String S = " abbaa " ; int N = S . length ( ) ; System . out . print ( subString ( S , N ) ) ; } }
Count number of substrings having at least K distinct characters | Java program for the above approach ; Function to count number of substrings having atleast k distinct characters ; Stores the size of the string ; Initialize a HashMap ; Stores the start and end indices of sliding window ; Stores the required result ; Iterate while the end pointer is less than n ; Include the character at the end of the window ; Increment end pointer by 1 ; Iterate until count of distinct characters becomes less than K ; Remove the character from the beginning of window ; If its frequency is 0 , remove it from the map ; Update the answer ; Print the result ; Driver code
import java . util . * ; class GFG { static void atleastkDistinctChars ( String s , int k ) { int n = s . length ( ) ; Map < Character , Integer > mp = new HashMap < > ( ) ; int begin = 0 , end = 0 ; int ans = 0 ; while ( end < n ) { char c = s . charAt ( end ) ; mp . put ( c , mp . getOrDefault ( c , 0 ) + 1 ) ; end ++ ; while ( mp . size ( ) >= k ) { char pre = s . charAt ( begin ) ; mp . put ( pre , mp . getOrDefault ( pre , 0 ) - 1 ) ; if ( mp . get ( pre ) == 0 ) { mp . remove ( pre ) ; } ans += s . length ( ) - end + 1 ; begin ++ ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String S = " abcca " ; int K = 3 ; atleastkDistinctChars ( S , K ) ; } }
Rearrange characters of a string to make it a concatenation of palindromic substrings | Java program for the above approach ; Function to check if a string can be modified such that it can be split into palindromic substrings of length >= 2 ; Stores frequencies of characters ; Traverse the string ; Update frequency of each character ; Traverse the frequency array ; Update values of odd and eve ; Print the result ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void canSplit ( String S ) { int frequency [ ] = new int [ 26 ] ; int cnt_singles = 0 ; int k = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) frequency [ S . charAt ( i ) - ' a ' ] ++ ; int odd = 0 , eve = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( frequency [ i ] != 0 ) { odd += ( frequency [ i ] & 1 ) ; eve += frequency [ i ] / 2 ; } } if ( eve >= odd ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " aaabbbccc " ; canSplit ( S ) ; } }
Maximize count of occurrences of S2 in S1 as a subsequence by concatenating N1 and N2 times respectively | Java program for the above approach ; Function to count maximum number of occurrences of s2 as subsequence in s1 by concatenating s1 , n1 times and s2 , n2 times ; Stores number of times s1 is traversed ; Stores number of times s2 is traversed ; Mapping index of s2 to number of times s1 and s2 are traversed ; Stores index of s1 circularly ; Stores index of s2 circularly ; Traverse the string s1 , n1 times ; If current character of both the string are equal ; Update j ; Update i ; If j is length of s2 ; Update j for circular traversal ; Update s2_reps ; If i is length of s1 ; Update i for circular traversal ; Update s1_reps ; If already mapped j to ( s1_reps , s2_reps ) ; Mapping j to ( s1_reps , s2_reps ) ; If s1 already traversed n1 times ; Otherwis , traverse string s1 by multiple of s1_reps and update both s1_reps and s2_reps ; Update s2_reps ; Update s1_reps ; If s1 is traversed less than n1 times ; If current character in both the string are equal ; Update j ; Update i ; If i is length of s1 ; Update i for circular traversal ; Update s1_reps ; If j is length of ss ; Update j for circular traversal ; Update s2_reps ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int getMaxRepetitions ( String s1 , int n1 , String s2 , int n2 ) { int temp1 [ ] = new int [ 26 ] , temp2 [ ] = new int [ 26 ] ; for ( char i : s1 . toCharArray ( ) ) temp1 [ i - ' a ' ] ++ ; for ( char i : s2 . toCharArray ( ) ) temp2 [ i - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( temp2 [ i ] > temp1 [ i ] ) return 0 ; } int s1_reps = 0 ; int s2_reps = 0 ; HashMap < Integer , int [ ] > s2_index_to_reps = new HashMap < > ( ) ; s2_index_to_reps . put ( 0 , new int [ ] { 0 , 0 } ) ; int i = 0 ; int j = 0 ; while ( s1_reps < n1 ) { if ( s1 . charAt ( i ) == s2 . charAt ( j ) ) j += 1 ; i += 1 ; if ( j == s2 . length ( ) ) { j = 0 ; s2_reps += 1 ; } if ( i == s1 . length ( ) ) { i = 0 ; s1_reps += 1 ; if ( ! s2_index_to_reps . containsKey ( j ) ) break ; s2_index_to_reps . put ( j , new int [ ] { s1_reps , s2_reps } ) ; } } if ( s1_reps == n1 ) return s2_reps / n2 ; int initial_s1_reps = s2_index_to_reps . get ( j ) [ 0 ] , initial_s2_reps = s2_index_to_reps . get ( j ) [ 1 ] ; int loop_s1_reps = s1_reps - initial_s1_reps ; int loop_s2_reps = s2_reps - initial_s2_reps ; int loops = ( n1 - initial_s1_reps ) ; s2_reps = initial_s2_reps + loops * loop_s2_reps ; s1_reps = initial_s1_reps + loops * loop_s1_reps ; while ( s1_reps < n1 ) { if ( s1 . charAt ( i ) == s2 . charAt ( j ) ) j += 1 ; i += 1 ; if ( i == s1 . length ( ) ) { i = 0 ; s1_reps += 1 ; } if ( j == s2 . length ( ) ) { j = 0 ; s2_reps += 1 ; } } return s2_reps / n2 ; } public static void main ( String [ ] args ) { String s1 = " acb " ; int n1 = 4 ; String s2 = " ab " ; int n2 = 2 ; System . out . println ( getMaxRepetitions ( s1 , n1 , s2 , n2 ) ) ; } }
Shortest string possible after removal of all pairs of similar adjacent characters | Java program for the above approach ; Function to delete pair of adjacent characters which are equal ; Base Case ; Stores the update string ; Traverse the string s ; If two unequal pair of adjacent characters are found ; If two equal pair of adjacent characters are found ; Append the remaining string after removing the pair ; Return the final String ; Function to find the shortest string after repeatedly removing pairs of adjacent characters which are equal ; Stores the resultant String ; Keeps track of previously iterated string ; Update the result after deleting adjacent pair of characters which are similar ; Termination Conditions ; Update pre variable with the value of result ; Case for " Empty ▁ String " ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String removeAdjacent ( String s ) { if ( s . length ( ) == 1 ) return s ; StringBuilder sb = new StringBuilder ( " " ) ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { char c = s . charAt ( i ) ; char d = s . charAt ( i + 1 ) ; if ( c != d ) { sb . append ( c ) ; if ( i == s . length ( ) - 2 ) { sb . append ( d ) ; } } else { for ( int j = i + 2 ; j < s . length ( ) ; j ++ ) sb . append ( s . charAt ( j ) ) ; return sb . toString ( ) ; } } return sb . toString ( ) ; } public static void reduceString ( String s ) { String result = " " ; String pre = s ; while ( true ) { result = removeAdjacent ( pre ) ; if ( result . equals ( pre ) ) break ; pre = result ; } if ( result . length ( ) != 0 ) System . out . println ( result ) ; else System . out . println ( " Empty ▁ String " ) ; } public static void main ( String [ ] args ) { String S = " aaabccddd " ; reduceString ( S ) ; } }
Minimum removals required such that a string can be rearranged to form a palindrome | Java program for the above approach ; Function to find the number of deletions required such that characters of the string can be rearranged to form a palindrome ; Stores frequency of characters ; Store the frequency of each character in frequency array ; Count number of characters with odd frequency ; If count is 1 or 0 , return 0 ; Otherwise , return count - 1 ; Driver Code ; Function call to find minimum number of deletions required
public class GFG { static int minDeletions ( String str ) { int fre [ ] = new int [ 26 ] ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { fre [ str . charAt ( i ) - ' a ' ] += 1 ; } int count = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( fre [ i ] % 2 == 1 ) { count += 1 ; } } if ( count == 0 count == 1 ) { return 0 ; } else { return count - 1 ; } } public static void main ( String [ ] args ) { String str = " ababbccca " ; System . out . println ( minDeletions ( str ) ) ; } }
Calculate score of parentheses from a given string | Java program for the above approach ; Function to calculate the score of the parentheses using stack ; To keep track of the score ; Initially , push 0 to stack ; Traverse the string s ; If ' ( ' is encountered , then push 0 to stack ; Otherwise ; Balance the last ' ( ' , and store the score of inner parentheses ; If tmp is not zero , it means inner parentheses exists ; Otherwise , it means no inner parentheses exists ; Pass the score of this level to parent parentheses ; Print the score ; Driver code ; Function call
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void scoreOfParentheses ( String s ) { Stack < Integer > stack = new Stack < > ( ) ; stack . push ( 0 ) ; for ( char c : s . toCharArray ( ) ) { if ( c == ' ( ' ) stack . push ( 0 ) ; else { int tmp = stack . pop ( ) ; int val = 0 ; if ( tmp > 0 ) val = tmp * 2 ; else val = 1 ; stack . push ( stack . pop ( ) + val ) ; } } System . out . println ( stack . peek ( ) ) ; } public static void main ( String [ ] args ) { String S = " ( ( ) ( ( ) ) ) " ; scoreOfParentheses ( S ) ; } }
Count unique substrings of a string S present in a wraparound string | Java program for the above approach ; Function to find the count of non - empty substrings of p present in s ; Stores the required answer ; Stores the length of substring present in p ; Stores the current length of substring that is present in string s starting from each character of p ; Iterate over the characters of the string ; Check if the current character can be added with previous substring to form the required substring ; Increment current length ; To avoid repetition ; Update arr [ cur ] ; Print the answer ; Driver Code ; Function call to find the count of non - empty substrings of p present in s
import java . util . * ; class GFG { static void findSubstringInWraproundString ( String p ) { int ans = 0 ; int curLen = 0 ; int arr [ ] = new int [ 26 ] ; for ( int i = 0 ; i < p . length ( ) ; i ++ ) { int curr = p . charAt ( i ) - ' a ' ; if ( i > 0 && ( p . charAt ( i - 1 ) != ( ( curr + 26 - 1 ) % 26 + ' a ' ) ) ) { curLen = 0 ; } curLen ++ ; if ( curLen > arr [ curr ] ) { ans += ( curLen - arr [ curr ] ) ; arr [ curr ] = curLen ; } } System . out . println ( ans ) ; } public static void main ( String args [ ] ) { String p = " zab " ; findSubstringInWraproundString ( p ) ; } }
Minimize sum of given array by removing all occurrences of a single digit | Java program for the above approach ; Function to remove each digit from the given integer ; Convert into string ; Stores final string ; Traverse the string ; Append it to the final string ; Return integer value ; Function to find the minimum sum by removing occurences of each digit ; Iterate in range [ 0 , 9 ] ; Traverse the array ; Update the minimum sum ; Print the minimized sum ; Driver Code
import java . util . * ; class GFG { static int remove ( int N , int digit ) { String strN = String . valueOf ( N ) ; String ans = " " ; for ( char i : strN . toCharArray ( ) ) { if ( ( i - '0' ) == digit ) { continue ; } ans += i ; } return Integer . parseInt ( ans ) ; } static void getMin ( int [ ] arr ) { int minSum = Integer . MAX_VALUE ; for ( int i = 0 ; i < 10 ; i ++ ) { int curSum = 0 ; for ( int num : arr ) curSum += remove ( num , i ) ; minSum = Math . min ( minSum , curSum ) ; } System . out . print ( minSum ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 34 , 23 , 85 , 93 } ; getMin ( arr ) ; } }