 MISIMP - EDITORIAL

Setter: Medhavi Sinha, Huzaifa Khilawala
Tester: Manasi Varaiya

Easy

PROBLEM:

You are sending Tom Cruise on a secret mission to Switzerland. You are in search of secret packages scattered around N mountain ranges. Each mountain range has 5 mountains and the highest peak of each mountain range contains a package each.

Unfortunately, Tom already left for Switzerland and you need to tell him how to get to the packages. Since the message can get intercepted in transmission by enemies, you need to form a code by concatenating the height of the mountains the packages are at. To be extra secure, reverse this code.

EXPLANATION:

It is given that each range has 5 mountains. We can transverse through each range one by one and get the height of the highest peak of that particular range. We maintain a string where we append this maximum height for each range. Finally we reverse this string to get the desired code.

TIME COMPLEXITY:

The time complexity is O(N)

SOLUTION:

Setter's Solution
for _ in range(int(input())):
ans = ""
for N in range(int(input())):
ms = list(map(int,input().split()))
ans += str(max(ms))
print(ans[::-1])
Tester's Solution
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.time.Duration;
import java.time.Instant;
import org.apache.commons.lang3.time.StopWatch;
public class peak {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int col = 5;
for (int i = 0; i < t; i++) {
int row = in.nextInt();
int[][] matrix = prepareMatrix(row, col, in);
findMaxInEachRow(matrix);
}
}
private static int[][] prepareMatrix(int row, int column, Scanner sc) {
int matrix[][] = new int[row][column];
for (int i = 0; i < row; i++)
for (int j = 0; j < column; j++)
matrix[i][j] = sc.nextInt();
return matrix;
}
private static void findMaxInEachRow(int[][] matrix) {
int[] tempArray = new int[matrix.length];
for (int i = 0; i < matrix.length; i++) {
int max = matrix[i];
for (int j = 0; j < matrix[i].length; j++) {
if (max < matrix[i][j])
max = matrix[i][j];
tempArray[i] = max;
}
}
for (int i = tempArray.length - 1; i >= 0; i--) {
System.out.print((new StringBuilder(String.valueOf(tempArray[i]))).reverse());
}
}
}