codeparrot/xlcost-text-to-code huggingface dataset:
Lexicographical concatenation of all substrings of a string | C # Program to create concatenation of all substrings in lexicographic order . ; Creating an array to store substrings ; finding all substrings of string ; Sort all substrings in lexicographic order ; Concatenating all substrings ; Driver code
using System ; class GFG { static String lexicographicSubConcat ( String s ) { int n = s . Length ; int sub_count = n * ( n + 1 ) / 2 ; String [ ] arr = new String [ sub_count ] ; int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) { arr [ index ++ ] = s . Substring ( i , len ) ; } Array . Sort ( arr ) ; String res = " " ; for ( int i = 0 ; i < sub_count ; i ++ ) res += arr [ i ] ; return res ; } public static void Main ( String [ ] args ) { String s = " abc " ; Console . WriteLine ( lexicographicSubConcat ( s ) ) ; } }
Insertion Sort by Swapping Elements | Iterative C # program to sort an array by swapping elements ; Utility function to print a Vector ; Function performs insertion sort on vector V ; Insert V [ i ] into list 0. . i - 1 ; Swap V [ j ] and V [ j - 1 ] ; Decrement j by 1 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void printVector ( List < int > V ) { for ( int i = 0 ; i < V . Count ; i ++ ) { Console . Write ( V [ i ] + " ▁ " ) ; } Console . WriteLine ( ) ; } static void insertionSort ( List < int > V ) { int N = V . Count ; int i , j ; for ( i = 1 ; i < N ; i ++ ) { j = i ; while ( j > 0 && V [ j ] < V [ j - 1 ] ) { int temp = V [ j ] ; V [ j ] = V [ j - 1 ] ; V [ j - 1 ] = temp ; j -= 1 ; } } } public static void Main ( String [ ] args ) { List < int > A = new List < int > ( ) ; A . Insert ( 0 , 9 ) ; A . Insert ( 1 , 8 ) ; A . Insert ( 2 , 7 ) ; A . Insert ( 3 , 5 ) ; A . Insert ( 4 , 2 ) ; A . Insert ( 5 , 1 ) ; A . Insert ( 6 , 2 ) ; A . Insert ( 7 , 3 ) ; Console . Write ( " Array : ▁ STRNEWLINE " ) ; printVector ( A ) ; Console . Write ( " After ▁ Sorting ▁ : STRNEWLINE " ) ; insertionSort ( A ) ; printVector ( A ) ; } }
Program to sort string in descending order | C # program to sort a string in descending order using library function ; Driver code ; descOrder ( s ) ; function call
using System ; class GFG { static void descOrder ( char [ ] s ) { Array . Sort ( s ) ; reverse ( s ) ; } static void reverse ( char [ ] a ) { int i , n = a . Length ; char t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } public static void Main ( String [ ] args ) { char [ ] s = " geeksforgeeks " . ToCharArray ( ) ; Console . WriteLine ( String . Join ( " " , s ) ) ; } }
Smallest element in an array that is repeated exactly ' k ' times . | C # program to find smallest number in array that is repeated exactly ' k ' times . ; finds the smallest number in arr [ ] that is repeated 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
using System ; public class GFG { static int MAX = 1000 ; static int findDuplicate ( int [ ] arr , int n , int k ) { int [ ] freq = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 1 && arr [ i ] > MAX ) { Console . WriteLine ( " Out ▁ of ▁ range " ) ; return - 1 ; } freq [ arr [ i ] ] += 1 ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == k ) return i ; } return - 1 ; } public static void Main ( ) { int [ ] arr = { 2 , 2 , 1 , 3 , 1 } ; int k = 2 ; int n = arr . Length ; Console . WriteLine ( findDuplicate ( arr , n , k ) ) ; } }
Check whether a given array is a k sorted array or not | C # implementation to check whether the given array is a k sorted array or not ; function to check whether the given array is a ' k ' sorted array or not ; auxiliary array ' aux ' ; copy elements of ' arr ' to ' aux ' ; sort ' aux ' ; for every element of ' arr ' at index ' i ' , find its index ' j ' in ' aux ' ; index of arr [ i ] in sorted array ' aux ' ; if abs ( i - j ) > k , then that element is not at - most k distance away from its target position . Thus , ' arr ' is not a k sorted array ; ' arr ' is a k sorted array ; Driver method
using System ; using System . Collections ; class GFG { static String isKSortedArray ( int [ ] arr , int n , int k ) { int [ ] aux = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) aux [ i ] = arr [ i ] ; Array . Sort ( aux ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = Array . BinarySearch ( aux , arr [ i ] ) ; if ( Math . Abs ( i - j ) > k ) return " No " ; } return " Yes " ; } public static void Main ( ) { int [ ] arr = { 3 , 2 , 1 , 5 , 6 , 4 } ; int k = 2 ; Console . WriteLine ( " Is ▁ it ▁ a ▁ k ▁ sorted ▁ array ▁ ? : ▁ " + isKSortedArray ( arr , arr . Length , k ) ) ; } }
TimSort | C # program to perform TimSort . ; This function sorts array from left index to to right index which is of size atmost RUN ; merge function merges the sorted runs ; original array is broken in two parts left and right array ; After comparing , we merge those two array in larger sub array ; Copy remaining elements of left , if any ; Copy remaining element of right , if any ; Iterative Timsort function to sort the array [ 0. . . n - 1 ] ( similar to merge sort ) ; Sort individual subarrays of size RUN ; Start merging from size RUN ( or 32 ) . It will merge to form size 64 , then 128 , 256 and so on ... . ; Pick starting point of left sub array . We are going to merge arr [ left . . left + size - 1 ] and arr [ left + size , left + 2 * size - 1 ] After every merge , we increase left by 2 * size ; Find ending point of left sub array mid + 1 is starting point of right sub array ; Merge sub array arr [ left ... . . mid ] & arr [ mid + 1. ... right ] ; Utility function to print the Array ; Driver program to test above function ; Function Call
using System ; class GFG { public const int RUN = 32 ; public static void insertionSort ( int [ ] arr , int left , int right ) { for ( int i = left + 1 ; i <= right ; i ++ ) { int temp = arr [ i ] ; int j = i - 1 ; while ( j >= left && arr [ j ] > temp ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } public static void merge ( int [ ] arr , int l , int m , int r ) { int len1 = m - l + 1 , len2 = r - m ; int [ ] left = new int [ len1 ] ; int [ ] right = new int [ len2 ] ; for ( int x = 0 ; x < len1 ; x ++ ) left [ x ] = arr [ l + x ] ; for ( int x = 0 ; x < len2 ; x ++ ) right [ x ] = arr [ m + 1 + x ] ; int i = 0 ; int j = 0 ; int k = l ; while ( i < len1 && j < len2 ) { if ( left [ i ] <= right [ j ] ) { arr [ k ] = left [ i ] ; i ++ ; } else { arr [ k ] = right [ j ] ; j ++ ; } k ++ ; } while ( i < len1 ) { arr [ k ] = left [ i ] ; k ++ ; i ++ ; } while ( j < len2 ) { arr [ k ] = right [ j ] ; k ++ ; j ++ ; } } public static void timSort ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i += RUN ) insertionSort ( arr , i , Math . Min ( ( i + RUN - 1 ) , ( n - 1 ) ) ) ; for ( int size = RUN ; size < n ; size = 2 * size ) { for ( int left = 0 ; left < n ; left += 2 * size ) { int mid = left + size - 1 ; int right = Math . Min ( ( left + 2 * size - 1 ) , ( n - 1 ) ) ; if ( mid < right ) merge ( arr , left , mid , right ) ; } } } public static void printArray ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . Write ( " STRNEWLINE " ) ; } public static void Main ( ) { int [ ] arr = { - 2 , 7 , 15 , - 14 , 0 , 15 , 0 , 7 , - 7 , - 4 , - 13 , 5 , 8 , - 14 , 12 } ; int n = arr . Length ; Console . Write ( " Given ▁ Array ▁ is STRNEWLINE " ) ; printArray ( arr , n ) ; timSort ( arr , n ) ; Console . Write ( " After ▁ Sorting ▁ Array ▁ is STRNEWLINE " ) ; printArray ( arr , n ) ; } }
Program to print an array in Pendulum Arrangement | C # program for pendulum arrangement of numbers ; Prints pendulum arrangement of arr [ ] ; sorting the elements ; Auxiliary array to store output ; calculating the middle index ; storing the minimum element in the middle i is index for output array and j is for input array . ; adjustment for when no . of elements is even ; Printing the pendulum arrangement ; Driver code ; input Array ; calling pendulum function
using System ; class Test { static void pendulumArrangement ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int [ ] op = new int [ n ] ; int mid = ( n - 1 ) / 2 ; int j = 1 , i = 1 ; op [ mid ] = arr [ 0 ] ; for ( i = 1 ; i <= mid ; i ++ ) { op [ mid + i ] = arr [ j ++ ] ; op [ mid - i ] = arr [ j ++ ] ; } if ( n % 2 == 0 ) op [ mid + i ] = arr [ j ] ; Console . Write ( " Pendulum ▁ arrangement : " ) ; for ( i = 0 ; i < n ; i ++ ) Console . Write ( op [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( ) { int [ ] arr = { 14 , 6 , 19 , 21 , 12 } ; pendulumArrangement ( arr , arr . Length ) ; } }
Maximum width of a binary tree | C # program to calculate width of binary tree ; A binary tree node has data , pointer to left child and a pointer to right child ; Function to get the maximum width of a binary tree ; Create an array that will store count of nodes at each level ; Fill the count array using preorder traversal ; Return the maximum value from count array ; A function that fills count array with count of nodes at every level of given binary tree ; Compute the " height " of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node . ; compute the height of each subtree ; use the larger one ; Return the maximum value from count array ; Driver program to test above functions ; Constructed bunary tree is : 1 / \ 2 3 / \ \ 4 5 8 / \ 6 7
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; int getMaxWidth ( Node node ) { int width ; int h = height ( node ) ; int [ ] count = new int [ 10 ] ; int level = 0 ; getMaxWidthRecur ( node , count , level ) ; return getMax ( count , h ) ; } void getMaxWidthRecur ( Node node , int [ ] count , int level ) { if ( node != null ) { count [ level ] ++ ; getMaxWidthRecur ( node . left , count , level + 1 ) ; getMaxWidthRecur ( node . right , count , level + 1 ) ; } } int height ( Node node ) { if ( node == null ) return 0 ; else { int lHeight = height ( node . left ) ; int rHeight = height ( node . right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } int getMax ( int [ ] arr , int n ) { int max = arr [ 0 ] ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } return max ; } public static void Main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . right = new Node ( 8 ) ; tree . root . right . right . left = new Node ( 6 ) ; tree . root . right . right . right = new Node ( 7 ) ; Console . WriteLine ( " Maximum ▁ width ▁ is ▁ " + tree . getMaxWidth ( tree . root ) ) ; } }
Minimize the sum of product of two arrays with permutations allowed | C # program to calculate minimum sum of product of two arrays . ; Returns minimum sum of product of two arrays with permutations allowed ; Sort A and B so that minimum and maximum value can easily be fetched . ; Multiplying minimum value of A and maximum value of B ; Driven Code
using System ; class GFG { static long minValue ( int [ ] a , int [ ] b , int n ) { Array . Sort ( a ) ; Array . Sort ( b ) ; long result = 0 ; for ( int i = 0 ; i < n ; i ++ ) result += ( a [ i ] * b [ n - i - 1 ] ) ; return result ; } public static void Main ( ) { int [ ] a = { 3 , 1 , 1 } ; int [ ] b = { 6 , 5 , 4 } ; int n = a . Length ; Console . Write ( minValue ( a , b , n ) ) ; } }
Count of numbers in range [ L , R ] which can be represented as sum of two perfect powers | C # program for the above approach ; Function to find the number of numbers that can be expressed in the form of the sum of two perfect powers ; Stores all possible powers ; Push 1 and 0 in it ; Iterate over all the exponents ; Iterate over all possible numbers ; This loop will run for a maximum of sqrt ( R ) times ; Push this power in the array pows [ ] ; Increase the number ; Stores if i can be expressed as the sum of perfect power or not ; Iterate over all possible pairs of the array pows [ ] ; The number is valid ; Find the prefix sum of the array ok [ ] ; Return the count of required number ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int TotalPerfectPowerSum ( long L , long R ) { List < long > pows = new List < long > ( ) ; pows . Add ( 0 ) ; pows . Add ( 1 ) ; for ( int p = 2 ; p < 25 ; p ++ ) { long num = 2 ; while ( ( long ) ( Math . Pow ( num , p ) + 0.5 ) <= R ) { pows . Add ( ( long ) ( Math . Pow ( num , p ) + 0.5 ) ) ; num ++ ; } } int [ ] ok = new int [ R + 2 ] ; for ( int i = 0 ; i < pows . Count ; i ++ ) { for ( int j = 0 ; j < pows . Count ; j ++ ) { if ( pows [ i ] + pows [ j ] <= R && pows [ i ] + pows [ j ] >= L ) { ok [ pows [ i ] + pows [ j ] ] = 1 ; } } } for ( int i = 1 ; i <= R ; i ++ ) { ok [ i ] += ok [ i - 1 ] ; } return ok [ R ] - ok [ L - 1 ] ; } public static void Main ( ) { int L = 5 , R = 8 ; Console . WriteLine ( TotalPerfectPowerSum ( L , R ) ) ; } }
Minimize absolute difference between sum of subtrees formed after splitting Binary tree into two | C # implementation for the above approach ; Structure of Node ; Function to calculate minimum absolute difference of subtrees after splitting the tree into two parts ; Reference variable to store the answer ; Function to store sum of values of current node , left subtree and right subtree in place of current node 's value ; Function to perform every possible split and calculate absolute difference of subtrees ; Absolute difference in subtrees if left edge is broken ; Absolute difference in subtrees if right edge is broken ; Update minDiff if a difference lesser than it is found ; Driver code ; Construct the tree ; Print the output
using System ; public class GFG { class Node { public Node left , right ; public int val ; } static Node newNode ( int data ) { Node newNode = new Node ( ) ; newNode . val = data ; newNode . left = null ; newNode . right = null ; return newNode ; } static int minAbsDiff ( Node root ) { int [ ] minDiff = new int [ 1 ] ; minDiff [ 0 ] = Int32 . MaxValue ; postOrder ( root ) ; preOrder ( root , minDiff ) ; return minDiff [ 0 ] ; } static int postOrder ( Node root ) { if ( root == null ) return 0 ; root . val += postOrder ( root . left ) + postOrder ( root . right ) ; return root . val ; } static void preOrder ( Node root , int [ ] minDiff ) { if ( root == null ) return ; int leftDiff = Math . Abs ( root . left . val - ( root . val - root . left . val ) ) ; int rightDiff = Math . Abs ( root . right . val - ( root . val - root . right . val ) ) ; minDiff [ 0 ] = Math . Min ( minDiff [ 0 ] , Math . Min ( leftDiff , rightDiff ) ) ; return ; } public static void Main ( ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; Console . Write ( minAbsDiff ( root ) ) ; } }
Vertical width of Binary tree | Set 1 | C # program to print vertical width of a tree ; A Binary Tree Node ; get vertical width ; traverse left ; if curr is decrease then get value in minimum ; if curr is increase then get value in maximum ; traverse right ; 1 is added to include root in the width ; Utility function to create a new tree node ; Driver Code
using System ; class GFG { public class Node { public int data ; public Node left , right ; } ; static int maximum = 0 , minimum = 0 ; static void lengthUtil ( Node root , int curr ) { if ( root == null ) return ; lengthUtil ( root . left , curr - 1 ) ; if ( minimum > curr ) minimum = curr ; if ( maximum < curr ) maximum = curr ; lengthUtil ( root . right , curr + 1 ) ; } static int getLength ( Node root ) { maximum = 0 ; minimum = 0 ; lengthUtil ( root , 0 ) ; return ( Math . Abs ( minimum ) + maximum ) + 1 ; } static Node newNode ( int data ) { Node curr = new Node ( ) ; curr . data = data ; curr . left = curr . right = null ; return curr ; } public static void Main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; Console . WriteLine ( getLength ( root ) ) ; } }
Maximize Array sum after changing sign of any elements for exactly M times | C # implementation of the above approach ; Function to find the maximum sum with M flips ; Declare a priority queue i . e . min heap ; Declare the sum as zero ; Push all elements of the array in it ; Iterate for M times ; Get the top element ; Flip the sign of the top element ; Remove the top element ; Update the sum ; Push the temp into the queue ; Driver Code ; Given input
using System ; using System . Collections . Generic ; public class GFG { static void findMaximumSumWithMflips ( int [ ] arr , int N , int M ) { List < int > minHeap = new List < int > ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { minHeap . Add ( arr [ i ] ) ; sum += arr [ i ] ; } minHeap . Sort ( ) ; while ( M -- > 0 ) { sum -= minHeap [ 0 ] ; int temp = - 1 * minHeap [ 0 ] ; minHeap . RemoveAt ( 0 ) ; sum += temp ; minHeap . Add ( temp ) ; minHeap . Sort ( ) ; } Console . WriteLine ( sum ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 3 , 7 , - 1 , - 5 , - 3 } ; int M = 4 , N = 5 ; findMaximumSumWithMflips ( arr , N , M ) ; } }
Minimum operations to make Array equal by repeatedly adding K from an element and subtracting K from other | C # program for the above approach ; Function to find the minimum number of operations to make all the elements of the array equal ; Store the sum of the array arr [ ] ; Traverse through the array ; If it is not possible to make all array element equal ; Store the minimum number of operations needed ; Traverse through the array ; Finally , print the minimum number operation to make array elements equal ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static void miniOperToMakeAllEleEqual ( int [ ] arr , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } if ( sum % n != 0 ) { Console . WriteLine ( - 1 ) ; return ; } int valueAfterDivision = sum / n ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . Abs ( valueAfterDivision - arr [ i ] ) % k != 0 ) { Console . WriteLine ( - 1 ) ; return ; } count += Math . Abs ( valueAfterDivision - arr [ i ] ) / k ; } Console . WriteLine ( ( int ) count / 2 ) ; } static void Main ( ) { int n = 3 , k = 3 ; int [ ] arr = { 5 , 8 , 11 } ; miniOperToMakeAllEleEqual ( arr , n , k ) ; } }
Minimum operations to make product of adjacent element pair of prefix sum negative | C # code for the above approach ; Function to find minimum operations needed to make the product of any two adjacent elements in prefix sum array negative ; Stores the minimum operations ; Stores the prefix sum and number of operations ; Traverse the array ; Update the value of sum ; Check if i + r is odd ; Check if prefix sum is not positive ; Update the value of ans and sum ; Check if prefix sum is not negative ; Update the value of ans and sum ; Update the value of res ; Print the value of res ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void minOperations ( List < int > a ) { int res = Int32 . MaxValue ; int N = a . Count ; for ( int r = 0 ; r < 2 ; r ++ ) { int sum = 0 , ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( ( i + r ) % 2 == 1 ) { if ( sum <= 0 ) { ans += - sum + 1 ; sum = 1 ; } } else { if ( sum >= 0 ) { ans += sum + 1 ; sum = - 1 ; } } } res = Math . Min ( res , ans ) ; } Console . Write ( res ) ; } public static void Main ( ) { List < int > a = new List < int > ( ) { 1 , - 3 , 1 , 0 } ; minOperations ( a ) ; } }
Minimize sum of product of same | C # Program to implement the above approach ; Function to print the arrays ; Function to reverse the subarray ; Function to calculate the minimum product of same - indexed elements of two given arrays ; Calculate initial product ; Traverse all odd length subarrays ; Remove the previous product ; Add the current product ; Check if current product is minimum or not ; Traverse all even length subarrays ; Remove the previous product ; Add to the current product ; Check if current product is minimum or not ; Update the pointers ; Reverse the subarray ; Print the subarray ; Driver Code
using System ; public class GFG { static void print ( long [ ] a , long [ ] b ) { long minProd = 0 ; for ( int i = 0 ; i < a . Length ; ++ i ) { Console . Write ( a [ i ] + " ▁ " ) ; } Console . WriteLine ( ) ; for ( int i = 0 ; i < b . Length ; ++ i ) { Console . Write ( b [ i ] + " ▁ " ) ; minProd += a [ i ] * b [ i ] ; } Console . WriteLine ( ) ; Console . WriteLine ( minProd ) ; } static void reverse ( int left , int right , long [ ] arr ) { while ( left < right ) { long temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; ++ left ; -- right ; } } static void minimumProdArray ( long [ ] a , long [ ] b , int l ) { long total = 0 ; for ( int i = 0 ; i < a . Length ; ++ i ) { total += a [ i ] * b [ i ] ; } long min = Int32 . MaxValue ; int first = 0 ; int second = 0 ; for ( int i = 0 ; i < a . Length ; ++ i ) { int left = i - 1 ; int right = i + 1 ; long total1 = total ; while ( left >= 0 && right < a . Length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } for ( int i = 0 ; i < a . Length ; ++ i ) { int left = i ; int right = i + 1 ; long total1 = total ; while ( left >= 0 && right < a . Length ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } if ( min < total ) { reverse ( first , second , a ) ; print ( a , b ) ; } else { print ( a , b ) ; } } public static void Main ( string [ ] args ) { int n = 4 ; long [ ] a = { 2 , 3 , 1 , 5 } ; long [ ] b = { 8 , 2 , 4 , 3 } ; minimumProdArray ( a , b , n ) ; } }