Product of maximum in first array and minimum in second | Practice | GeeksforGeeks

Given two arrays of A and B respectively of sizes N1 and N2, the task is to calculate the product of the maximum element of the first array and minimum element of the second array.
Example 1:
Input : A[] = {5, 7, 9, 3, 6, 2}, 
        B[] = {1, 2, 6, -1, 0, 9}
Output : -9
Explanation:
The first array is 5 7 9 3 6 2. 
The max element among these elements is 9.
The second array is 1 2 6 -1 0 9.
The min element among these elements is -1.
The product of 9 and -1 is 9*-1=-9.


Example 2:
Input : A[] = {0, 0, 0, 0}, 
           B[] = {1, -1, 2}
Output : 0


Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function find_multiplication() that takes an array of integer (A), another array of integer (B), size of array A(n), size of array B(m) and return the product of the max element of the first array and the minimum element of the second array. The driver code takes care of the printing.
Expected Time Complexity: O(N + M).
Expected Auxiliary Space: O(1).
 
Output:
For each test case, output the product of the max element of the first array and the minimum element of the second array.
Constraints:
1 ≤ N, M ≤ 106
-108 ≤ Ai, Bi ≤ 108
0
visionsameer393 days ago
class Solution:   def find_multiplication (self, arr, brr, n, m) :        arr.sort()       brr.sort()       a1=arr[-1]       b1=brr[0]       return a1*b1
+1
harshscode1 week ago
        long long int ma=INT_MIN,mi=INT_MAX;
        for(int i=0;i<n;i++)
        if(a[i]>ma)
        ma=a[i];
        for(int i=0;i<m;i++)
        if(b[i]<mi)
        mi=b[i];
        return (mi*ma);
0
vinayreddy222vr2 weeks ago
a=max(arr)       b=min(brr)       return a*b 
0
mayank180919993 weeks ago
      long long find_multiplication(int a[], int b[], int n, int m)
    {
        // Complete the function
        sort(a,a+n);
        sort(b,b+m);
        return a[n-1]*b[0];
    }
0
somawatpravin021 month ago
class Solution:   def find_multiplication (self, arr, brr, n, m) :        #Complete the function       arr.sort()       brr.sort()       return (arr[n-1]*brr[0])
0
sakesai301 month ago
class Solution{      // Function for finding maximum and value pair   public static long find_multiplication (int arr[], int brr[], int n, int m) {       sort(arr,0,n-1,n-1);       sort(brr,0,m-1,0);       return arr[n-1]*brr[0];   }      static void sort(int[] arr,int lo,int hi,int key){       int pivot = arr[lo];       int lt = lo;       int gt = hi;       int i = lo;       while(i<=gt){           if(arr[i]<pivot){               swap(arr,i,lt);               lt++;               i++;           }else if(arr[i]>pivot){               swap(arr,i,gt);               gt--;           }else{               i++;           }       }       if(lt>key){           sort(arr,lo,lt-1,key);       }else if(gt<key){           sort(arr,gt+1,hi,key);       }else{           return;       }   }      static void swap(int[] arr,int lo,int hi){       int temp = arr[lo];       arr[lo] = arr[hi];       arr[hi] = temp;   }      }
0
rahulp00rtx1 month ago
Simple JavaScipt, 0.6
class Solution{   find_multiplication(a,n,b,m){       //code here       let mx = a[0],mn = b[0];       for(let i = 0; i<n; i++){           if(a[i] > mx)           mx = a[i];       }       for(let i =0; i<m; i++){           if(b[i] < mn)           mn = b[i];       }       return  mn * mx;   }} 
0
hasnainraza1998hr1 month ago
C++, 0.4
long long find_multiplication(int a[], int b[], int n, int m)   {       int maxNum = *max_element(a,a+n);       int minNum = *min_element(b,b+m);       return maxNum*minNum;   }
0
kanchanikirankumarreddyPremium2 months ago
c++:
class Solution{   public:       long long find_multiplication(int a[], int b[], int n, int m)   {       int max=*max_element(a,a+n);       int min=*min_element(b,b+m);       return min*max;   }};
0
aakasshuit2 months ago
//Java Solution

        Arrays.sort(arr);
        Arrays.sort(brr);
        return (arr[n-1]*brr[0]);
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.