codeparrot/xlcost-text-to-code huggingface dataset:
Find the last element after repeatedly removing every second element from either end alternately | Java program for the above approach ; Function to find the last element remaining in the array after performing the given operations ; Checks if traversal is from left to right or vice versa ; Store the elements currently present in the array ; Store the distance between 2 consecutive array elements ; Store the first element of the remaining array ; Iterate while elements are greater than 1 ; If left to right turn ; Update head ; Otherwise , check if the remaining elements are odd ; If true , update head ; Eleminate half of the array elements ; Double the steps after each turn ; Alter the turn ; Print the remaining element ; Driver code
import java . lang . * ; class GFG { public static void printLastElement ( int arr [ ] , int N ) { boolean leftTurn = true ; int remainElements = N ; int step = 1 ; int head = 1 ; while ( remainElements > 1 ) { if ( leftTurn ) { head = head + step ; } else { if ( remainElements % 2 == 1 ) head = head + step ; } remainElements = remainElements / 2 ; step = step * 2 ; leftTurn = ! leftTurn ; } System . out . print ( arr [ head - 1 ] ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 2 , 3 , 5 , 6 } ; int N = arr . length ; printLastElement ( arr , N ) ; } }
Distributed C candies among N boys such that difference between maximum and minimum candies received is K | Java program for the above approach ; Function to calculate the maximum and minimum number of candies a boy can possess ; All candies will be given to one boy ; All the candies will be given to 1 boy ; Give K candies to 1 st boy initially ; Count remaining candies ; If the last candy of remaining candies is given to the last boy , i . e Nth boy ; Increase minimum count ; Driver code
class GFG { static void max_min ( int N , int C , int K ) { int maximum , minimum ; if ( N == 1 ) { maximum = minimum = C ; } else if ( K >= C ) { maximum = C ; minimum = 0 ; } else { maximum = K ; minimum = 0 ; int remain_candy = C - K ; maximum += remain_candy / N ; minimum = remain_candy / N ; if ( remain_candy % N == N - 1 ) { minimum ++ ; } } System . out . println ( " Maximum ▁ = ▁ " + maximum ) ; System . out . println ( " Minimum ▁ = ▁ " + minimum ) ; } public static void main ( String [ ] args ) { int N = 4 ; int C = 12 ; int K = 3 ; max_min ( N , C , K ) ; } }
Length of smallest subarray required to be removed to make remaining elements consecutive | Java program for the above approach ; Function to find the length of the smallest subarray to be removed to make remaining array elements consecutive ; Store the ending index of the longest prefix consecutive array ; Traverse the array to find the longest prefix consecutive sequence ; A [ 0. . . left_index ] is the prefix consecutive sequence ; Store the starting index of the longest suffix consecutive sequence ; Traverse the array to find the longest suffix consecutive sequence ; A [ right_index ... N - 1 ] is the consecutive sequence ; Store the smallest subarray required to be removed ; Check if subarray from the middle can be removed ; Update the right index s . t . A [ 0 , N - 1 ] is consecutive ; If updated_right < N , then update the minimumLength ; Print the required result ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void shortestSubarray ( int A [ ] , int N ) { int i ; int left_index ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] + 1 != A [ i + 1 ] ) break ; } left_index = i ; int right_index ; for ( i = N - 1 ; i >= 1 ; i -- ) { if ( A [ i ] != A [ i - 1 ] + 1 ) break ; } right_index = i ; int updated_right ; int minLength = Math . min ( N - left_index - 1 , right_index ) ; if ( A [ right_index ] <= A [ left_index ] + 1 ) { updated_right = right_index + A [ left_index ] - A [ right_index ] + 1 ; if ( updated_right < N ) minLength = Math . min ( minLength , updated_right - left_index - 1 ) ; } System . out . println ( minLength ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 7 , 4 , 3 , 5 } ; int N = arr . length ; shortestSubarray ( arr , N ) ; } }
Check if a string can be split into 3 substrings such that one of them is a substring of the other two | Java program for the above approach ; Function to check if string S contains any character with frequency >= 3 or not ; Stores frequency of characters ; Iterate over the string ; Update the frequency of current character ; Iterate over the hash array ; If any character has frequency >= 3 ; Otherwise ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String freqCheck ( String S , int N ) { int hash [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { hash [ S . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( hash [ i ] > 2 ) { return " Yes " ; } } return " No " ; } public static void main ( String [ ] args ) { String S = " geekseekforgeeks " ; int N = S . length ( ) ; System . out . println ( freqCheck ( S , N ) ) ; } }
Minimize length of a string by removing suffixes and prefixes of same characters | Java program for the above approach ; Function to find the minimum length of the string after removing the same characters from the end and front of the two strings after dividing into 2 substrings ; Initialize two pointers ; Traverse the string S ; Current char on left pointer ; Shift i towards right ; Shift j towards left ; Return the minimum possible length of string ; Driver Code
import java . lang . * ; import java . util . * ; class GFG { static int minLength ( String s ) { int i = 0 , j = s . length ( ) - 1 ; for ( ; i < j && s . charAt ( i ) == s . charAt ( j ) ; ) { char d = s . charAt ( i ) ; while ( i <= j && s . charAt ( i ) == d ) i ++ ; while ( i <= j && s . charAt ( j ) == d ) j -- ; } return j - i + 1 ; } public static void main ( String [ ] args ) { String S = " aacbcca " ; System . out . println ( minLength ( S ) ) ; } }
Number of Binary Search Trees of height H consisting of H + 1 nodes | Java program for the above approach ; Function to calculate x ^ y modulo 1000000007 in O ( log y ) ; Stores the value of x ^ y ; Update x if it exceeds mod ; If x is divisible by mod ; If y is odd , then multiply x with result ; Divide y by 2 ; Update the value of x ; Return the value of x ^ y ; Function to count the number of of BSTs of height H consisting of ( H + 1 ) nodes ; Driver code
class GFG { static int mod = 1000000007 ; static long power ( long x , int y ) { long res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } static long CountBST ( int H ) { return power ( 2 , H ) ; } public static void main ( String [ ] args ) { int H = 2 ; System . out . print ( CountBST ( H ) ) ; } }
Check if any pair of consecutive 1 s can be separated by at most M 0 s by circular rotation of a Binary String | Java program for the above approach ; Function to check if any pair of consecutive 1 s can be separated by at most M 0 s by circular rotation of string S ; Stores the indices of all 1 s ; Store the number of pairs separated by at least M 0 s ; Traverse the string ; Store the current index ; Traverse the array containing indices ; If the number of 0 s > M , then increment cnt by 1 ; Increment cnt ; Check if at least M '0' s lie between the first and last occurrence of '1' ; Increment cnt ; If the value of cnt <= 1 , then rotation of string is possible ; Otherwise ; Driver Code
class GFG { static void rotateString ( int n , int m , String s ) { int v [ ] = new int [ n ] ; int cnt = 0 ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) { v [ j ] = i ; j += 1 ; } } for ( int i = 1 ; i < j ; i ++ ) { if ( ( v [ i ] - v [ i - 1 ] - 1 ) > m ) { cnt ++ ; } } if ( j >= 2 && ( n - ( v [ j - 1 ] - v [ 0 ] ) - 1 ) > m ) { cnt ++ ; } if ( cnt <= 1 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } public static void main ( String [ ] args ) { String S = "101001" ; int M = 1 ; int N = S . length ( ) ; rotateString ( N , M , S ) ; } }
Number obtained by reducing sum of digits of 2 N into a single digit | Java program for the above approach ; Function to find the number obtained by reducing sum of digits of 2 ^ N into a single digit ; Stores answers for different values of N ; Driver Code
import java . util . * ; class GFG { static int findNumber ( int N ) { int [ ] ans = { 1 , 2 , 4 , 8 , 7 , 5 } ; return ans [ N % 6 ] ; } public static void main ( String args [ ] ) { int N = 6 ; System . out . println ( findNumber ( N ) ) ; } }
Check if two piles of coins can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other | Java program for above approach ; Function to check if two given piles can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other ; If maximum of A & B exceeds the twice of minimum of A & B ; Not possible to empty the piles ; If sum of both the coins is divisible by 3 , then print Yes ; Otherwise , print " No " ; Driver Code
import java . util . * ; class GFG { static void canBeEmptied ( int A , int B ) { if ( Math . max ( A , B ) > 2 * Math . min ( A , B ) ) { System . out . println ( " No " ) ; return ; } if ( ( A + B ) % 3 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int A = 1 , B = 2 ; canBeEmptied ( A , B ) ; } }
Maximum index a pointer can reach in N steps by avoiding a given index B | Set 2 | Java program for the above approach ; Function to find the maximum index the pointer can reach ; Initialize two pointers ; Stores number of steps ; Stores sum of first N natural numbers ; Increment i with j ; Increment j with 1 ; Increment count ; If i points to B ; Break ; Print the pointer index ; Driver Code ; Given value of N & B ; Function call to find maximum index the pointer can reach
class GFG { static void maximumIndex ( int N , int B ) { int i = 0 , j = 1 ; int cnt = 0 ; int sum = N * ( N + 1 ) / 2 ; boolean flag = false ; while ( cnt < N ) { i += j ; j ++ ; cnt ++ ; if ( i == B ) { flag = true ; break ; } } if ( ! flag == true ) { System . out . print ( sum ) ; } else { System . out . print ( sum - 1 ) ; } } public static void main ( String [ ] args ) { int N = 4 , B = 6 ; maximumIndex ( N , B ) ; } }
Generate longest possible array with product K such that each array element is divisible by its previous adjacent element | java program for the above approach ; Function to construct longest array with product K such that each element is divisible by its previous element ; Stores the prime factors of K ; Stores the power to which primefactor i is raised ; Sort prime factors in descending order ; Stores the final array ; Multiply the last element by K ; Print the constructed array ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findLongestArray ( int K ) { ArrayList < int [ ] > primefactors = new ArrayList < > ( ) ; int K_temp = K ; for ( int i = 2 ; i * i <= K ; i ++ ) { int count = 0 ; while ( K_temp % i == 0 ) { K_temp /= i ; count ++ ; } if ( count > 0 ) primefactors . add ( new int [ ] { count , i } ) ; } if ( K_temp != 1 ) primefactors . add ( new int [ ] { 1 , K_temp } ) ; Collections . sort ( primefactors , ( x , y ) -> { if ( x [ 0 ] != y [ 0 ] ) return y [ 0 ] - x [ 0 ] ; return y [ 1 ] - x [ 1 ] ; } ) ; int n = primefactors . get ( 0 ) [ 0 ] ; int val = primefactors . get ( 0 ) [ 1 ] ; int answer [ ] = new int [ n ] ; Arrays . fill ( answer , val ) ; answer [ n - 1 ] *= K ; for ( int i = 0 ; i < n ; i ++ ) { answer [ n - 1 ] /= val ; } System . out . print ( " { " ) ; for ( int i = 0 ; i < answer . length ; i ++ ) { if ( i == answer . length - 1 ) System . out . print ( answer [ i ] + " } " ) ; else System . out . print ( answer [ i ] + " , ▁ " ) ; } } public static void main ( String [ ] args ) { int K = 4 ; findLongestArray ( K ) ; } }
Minimum number of steps required to place all 1 s at a single index | Java program for the above approach ; Function to print minimum steps required to shift all 1 s to a single index in a binary array ; Size of array ; Used to store cumulative sum ; Initialize count ; Traverse the array in forward direction ; Steps needed to store all previous ones to ith index ; Count number of 1 s present till i - th index ; Initialize count ; Traverse the array in backward direction ; Steps needed to store all 1 s to the right of i at current index ; Count number of 1 s present after i - th index ; Print the number of steps required ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static void minsteps ( int [ ] A ) { int n = A . length ; int [ ] left = new int [ n ] ; Arrays . fill ( left , 0 ) ; int [ ] right = new int [ n ] ; Arrays . fill ( right , 0 ) ; int [ ] res = new int [ n ] ; Arrays . fill ( res , 0 ) ; int count = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { left [ i ] = left [ i - 1 ] + count ; count += A [ i ] ; } count = A [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { right [ i ] = right [ i + 1 ] + count ; count += A [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { res [ i ] = left [ i ] + right [ i ] ; System . out . print ( res [ i ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 0 , 1 , 0 } ; minsteps ( A ) ; } }
Minimize flips on K | Java program for the above approach ; Function to find the minimum number K - length subarrays required to be flipped to make all array elements 1 ; Stores whether an element can be flipped or not ; Store the required number of flips ; Traverse the array , A [ ] ; Find the prefix sum for the indices i > 0 ; Check if the current element is required to be flipped ; If subarray of size K is not possible , then print - 1 and return ; Increment ans by 1 ; Change the current state of the element ; Decrement isFlipped [ i + K ] ; If subarray of size K is not possible , then print - 1 and return ; Increment ans by 1 ; Change the current state of the element ; Decrement isFlipped [ i + K ] ; Print the result ; Driver Code
class GFG { static void minimumOperations ( int [ ] A , int K ) { int [ ] isflipped = new int [ A . length + 1 ] ; int ans = 0 ; for ( int i = 0 ; i < A . length ; i ++ ) { if ( i > 0 ) { isflipped [ i ] += isflipped [ i - 1 ] ; isflipped [ i ] %= 2 ; } if ( A [ i ] == 0 && isflipped [ i ] == 0 ) { if ( ( A . length - i + 1 ) <= K ) { System . out . println ( - 1 ) ; return ; } ans ++ ; isflipped [ i ] ++ ; isflipped [ i + K ] -- ; } else if ( A [ i ] == 1 && isflipped [ i ] != 0 ) { if ( ( A . length - i + 1 ) <= K ) { System . out . println ( - 1 ) ; return ; } ans ++ ; isflipped [ i ] ++ ; isflipped [ i + K ] -- ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 0 } ; int K = 1 ; minimumOperations ( arr , K ) ; } }
Calculate sum of scores after N days based on given conditions | Java Program to implement the above approach ; Function to c sum of calculate sum of scores after n days ; Store the required sum ; Store the score on previous monday and current day respectively ; Iterate over the range [ 1 , n ] ; If the current day is monday ; Increment score of prev_monday by 1 ; Update score of current day ; Add score of current day and increment score for next day ; Print the result ; Driver Code
import java . io . * ; class GFG { static void findScoreSum ( int n ) { int total = 0 ; int prev_monday = 0 , curr_day = 0 ; for ( int day = 1 ; day <= n ; day ++ ) { if ( day % 7 == 1 ) { prev_monday ++ ; curr_day = prev_monday ; } total += curr_day ++ ; } System . out . println ( total ) ; } public static void main ( String [ ] args ) { int N = 8 ; findScoreSum ( N ) ; } }
Calculate sum of scores after N days based on given conditions | Java program for the above approach ; Function to calculate sum of scores after n days ; Store the number of full weeks ; Stores the remaining days in the last week ; Store the sum of scores in the first F full weeks ; Store the sum of scores in the last week ; Print the result ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findScoreSum ( int n ) { int F = n / 7 ; int D = n % 7 ; int fullWeekScore = ( 49 + 7 * F ) * F / 2 ; int lastNonFullWeekScore = ( 2 * F + D + 1 ) * D / 2 ; System . out . println ( fullWeekScore + lastNonFullWeekScore ) ; } public static void main ( String [ ] args ) { int N = 8 ; findScoreSum ( N ) ; } }
Largest number up to N whose modulus with X is equal to Y modulo X | Java program for the above approach ; Function to print the largest number upto N whose modulus with X is same as Y % X ; Stores the required number ; Update num as the result ; Return the resultant number ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static long maximumNum ( long X , long Y , long N ) { long num = 0 ; if ( N - N % X + Y <= N ) { num = N - N % X + Y ; } else { num = N - N % X - ( X - Y ) ; } return num ; } public static void main ( String [ ] args ) { long X = 10 ; long Y = 5 ; long N = 15 ; System . out . println ( maximumNum ( X , Y , N ) ) ; } }
Generate an N | Java program for the above approach ; Function to calculate GCD of two integers ; Function to calculate GCD of a given array ; Utility function to check for all the possible combinations ; If an N - length sequence is obtained ; If GCD of the sequence is K ; Otherwise ; Add an element from the first array ; Recursively proceed further ; If combination satisfies the necessary condition ; Remove the element from the combination ; Add an element from the second array ; Recursive proceed further ; If combination satisfies the necessary condition ; Remove the element from the combination ; Function to check all the possible combinations ; Stores the subsequence ; If GCD is not equal to K for any combination ; Driver code ; Given arrays ; Given value of K ; Function call to generate the required subsequence
import java . util . * ; import java . lang . * ; class GFG { static int GCD ( int a , int b ) { if ( b < 1 ) return a ; return GCD ( b , a % b ) ; } static int GCDArr ( ArrayList < Integer > a ) { int ans = a . get ( 0 ) ; for ( int i : a ) ans = GCD ( ans , i ) ; return ans ; } static boolean findSubseqUtil ( ArrayList < Integer > a , ArrayList < Integer > b , ArrayList < Integer > ans , int k , int i ) { if ( ans . size ( ) == a . size ( ) ) { if ( GCDArr ( ans ) == k ) { System . out . print ( " [ " ) ; int m = ans . size ( ) ; for ( int j = 0 ; j < m - 1 ; j ++ ) System . out . print ( ans . get ( j ) + " , ▁ " ) ; System . out . print ( ans . get ( m - 1 ) + " ] " ) ; return true ; } else return false ; } ans . add ( a . get ( i ) ) ; boolean temp = findSubseqUtil ( a , b , ans , k , i + 1 ) ; if ( temp ) return true ; ans . remove ( ans . size ( ) - 1 ) ; ans . add ( b . get ( i ) ) ; temp = findSubseqUtil ( a , b , ans , k , i + 1 ) ; if ( temp ) return true ; ans . remove ( ans . size ( ) - 1 ) ; return false ; } static void findSubseq ( ArrayList < Integer > A , ArrayList < Integer > B , int K , int i ) { ArrayList < Integer > ans = new ArrayList < Integer > ( ) ; findSubseqUtil ( A , B , ans , K , i ) ; if ( ans . size ( ) < 1 ) System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { ArrayList < Integer > A = new ArrayList < > ( ) ; A . add ( 5 ) ; A . add ( 3 ) ; A . add ( 6 ) ; A . add ( 2 ) ; A . add ( 9 ) ; ArrayList < Integer > B = new ArrayList < Integer > ( ) ; B . add ( 21 ) ; B . add ( 7 ) ; B . add ( 14 ) ; B . add ( 12 ) ; B . add ( 28 ) ; int K = 3 ; findSubseq ( A , B , K , 0 ) ; } }
Minimize count of swaps of adjacent elements required to make an array increasing | Java program for the above approach ; Function to count minimum number of operations required to obtain an increasing array from given array A [ ] ; Store the required result ; Traverse the array A [ ] ; If the current element is not in its correct position ; Check if it is present at index i - 1 ; Check if it is present at index i - 2 ; Otherwise , print - 1 ( Since A [ i ] can not be swapped more than twice ) ; Print the result ; Driver code ; Given array ; Store the size of the array
import java . util . * ; import java . lang . * ; class GFG { static void minimumOperations ( int A [ ] , int n ) { int cnt = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( A [ i ] != ( i + 1 ) ) { if ( ( ( i - 1 ) >= 0 ) && A [ i - 1 ] == ( i + 1 ) ) { cnt ++ ; int t = A [ i ] ; A [ i ] = A [ i - 1 ] ; A [ i - 1 ] = t ; } else if ( ( ( i - 2 ) >= 0 ) && A [ i - 2 ] == ( i + 1 ) ) { cnt += 2 ; A [ i - 2 ] = A [ i - 1 ] ; A [ i - 1 ] = A [ i ] ; A [ i ] = i + 1 ; } else { System . out . println ( - 1 ) ; return ; } } } System . out . println ( cnt ) ; } public static void main ( String [ ] args ) { int A [ ] = { 7 , 3 , 2 , 1 , 4 } ; int n = A . length ; minimumOperations ( A , n ) ; } }
Count occurrences of an element in a matrix of size N * N generated such that each element is equal to product of its indices | Set | Java program for the above approach ; Function to count the occurrences of X in the generated square matrix ; Store the required result ; Iterate over the range [ 1 , N ] ; Check if x is a multiple of i or not ; Check if the other multiple exists in the range or not ; Print the result ; Driver Code
class GFG { static void countOccurrences ( int n , int x ) { int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( x % i == 0 ) { if ( x / i <= n ) count ++ ; } } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int N = 7 , X = 12 ; countOccurrences ( N , X ) ; } }
Reduce all array elements to zero by performing given operations thrice | Java program for the above approach ; Function to reduce all array elements to zero ; If size of array is 1 ; First operation ; 2 nd Operation ; 3 rd Operation ; Otherwise ; 1 st Operation ; 2 nd Operation ; 3 rd Operation ; Driver code ; Input ; Function call to make all array elements equal to 0
import java . util . * ; class GFG { static void ConvertArray ( int arr [ ] , int N ) { if ( N == 1 ) { System . out . println ( " Operation ▁ 1 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + - 1 * arr [ 0 ] ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 2 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + 1 * arr [ 0 ] ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 3 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + - 1 * arr [ 0 ] ) ; } else { System . out . println ( " Operation ▁ 1 ▁ : ▁ " + 1 + " ▁ " + N ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( - 1 * arr [ i ] * N + " ▁ " ) ; } System . out . println ( ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 2 ▁ : ▁ " + 1 + " ▁ " + ( N - 1 ) ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { System . out . print ( arr [ i ] * ( N - 1 ) + " ▁ " ) ; } System . out . println ( ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 3 ▁ : ▁ " + N + " ▁ " + N ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; System . out . println ( arr [ N - 1 ] * ( N - 1 ) ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 4 } ; int N = arr . length ; ConvertArray ( arr , N ) ; } }