Problem Β· Array

Get Maximum Pairs πŸ‰

Learn this problem
● EasyAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

An AWS client wants to deploy multiple applications and needs two servers, one for their frontend and another for their backend. They have a list of integers representing the quality of servers in terms of availability. The client's preference is that the availability of an application's frontend server must be greater than that of its backend.

Two arrays of same size n, frontend[n] and backend[n] where elements represent the quality of the servers, create pairs of elements (frontend[i], backend[i]) such that frontend[i] > backend[i] in each pair. Each element from an array can be picked only once to form a pair, Find the maximum number pairs that can be formed.

Function

getMaxPairs(frontend: int[], backend: int[]) β†’ int

Complete the function getMaxPairs in the editor.

getMaxPairs has the following parameters:

  1. int frontend[n]: frontend server qualities
  2. int backend[n]: backend server qualities

Returns

int: the maximum number of pairs that can be formed

Examples

Example 1

frontend = [1, 2, 3]backend = [1, 2, 1]return = 2
The possible valid pairs which can be made are:
  • (frontend[1], backend[0])=(2, 1) and (frontend[2], backend[2])=(3, 1) are valid pairs.
  • (frontend[1], backend[0])=(2, 1) and (frontend[2], backend[1])=(3, 2) are valid pairs.
  • It can be seen that a maximum of 2 valid pairs can be made at a time. So the maximum number of pairs that can be formed is 2. Return 2.

    More Amazon problems

    drafts saved locally
    public int getMaxPairs(int[] frontend, int[] backend) {
        // write your code here
    }
    
    frontend[1, 2, 3]
    backend[1, 2, 1]
    expected2
    checking account