Skip to main content

Flipkart

Flipkart OA 2023 - Networking Company Sequence Selection


A networking company is devising processes to control network traffic. The server in the network is connected to N devices (numbered from 0 to N-1). Recently, the team devised a process where the server receives messages from these N devices for transmission.
The process generates M possible sequences of messages from all devices, and one sequence will be used during the initial iteration. In every sequence, a count of messages is selected for each device from the received messages.

Your task is to select a sequence based on the following criteria:

  1. For every device, determine the highest count of messages among all sequences.
  2. Select the sequence with the highest count of messages for the maximum number of devices.
  3. If more than one sequence meets this condition, select the sequence with the higher average of received messages.

Input Format:

  • The first line contains two space-separated integers:
    • msgGrid_row (M): The number of sequences.
    • msgGrid_col (N): The number of devices.
  • The next M lines consist of N space-separated integers representing the count of messages for each device in a sequence.

Output Format:

  • Print two space-separated integers representing:
    1. The ID of the selected sequence.
    2. The number of devices for which the count of messages is highest in that sequence.

Example:

Input:

4 5
7 2 6 6 14
1 4 2 3 17
1 2 3 4 17
1 1 5 0 9

Output:

1 2

Explanation:

  • Maximum count of messages for each device among all sequences:
    • Device 0: 7 (from sequence 0)
    • Device 1: 4 (from sequence 1)
    • Device 2: 6 (from sequence 0)
    • Device 3: 6 (from sequence 0)
    • Device 4: 17 (from sequences 1 and 2)
  • Step 1: Determine maximum counts per sequence:
    • Sequence 0: Highest for 3 devices (Devices 0, 2, and 3).
    • Sequence 1: Highest for 2 devices (Devices 1 and 4).
    • Sequence 2: Highest for 1 device (Device 4).
    • Sequence 3: Highest for 0 devices.
  • Step 2: Average of counts (if tie-breaking is needed):
    • Sequence 0: Average = (7 + 2 + 6 + 6 + 14) / 5 = 7
    • Sequence 1: Average = (1 + 4 + 2 + 3 + 17) / 5 = 5.4

Since sequence 0 has the highest count of messages for 3 devices, it is selected. Thus, the output is 0 3.


Constraints:

  • (0 < msgGrid_row, msgGrid_col < 10^4)
  • (0 <= {count of messages for a device in a sequence} <= 10^4)