Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MaxNetVulnerability {
- static int getMaxNetVulnerability(List<List<Integer>> vulnerability) {
- int n = vulnerability.size();
- int m = vulnerability.get(0).size();
- int maxNetVulnerability = Integer.MIN_VALUE;
- for (int row1 = 0; row1 < n; row1++) {
- for (int row2 = row1 + 1; row2 < n; row2++) {
- List<Integer> row1Data = vulnerability.get(row1);
- List<Integer> row2Data = vulnerability.get(row2);
- int[] maxInColumns = new int[m];
- for (int col = 0; col < m; col++) {
- int max = Math.max(row1Data.get(col), row2Data.get(col));
- maxInColumns[col] = max;
- }
- int minMaxInColumns = Integer.MAX_VALUE;
- for (int max : maxInColumns) {
- minMaxInColumns = Math.min(minMaxInColumns, max);
- }
- maxNetVulnerability = Math.max(maxNetVulnerability, minMaxInColumns);
- }
- }
- return maxNetVulnerability;
- }
- public static void main(String[] args) {
- List<List<Integer>> vulnerability = new ArrayList<>();
- vulnerability.add(Arrays.asList(1, 3, 1));
- vulnerability.add(Arrays.asList(3, 1, 1));
- vulnerability.add(Arrays.asList(1, 2, 2));
- vulnerability.add(Arrays.asList(1, 1, 3));
- int maxVulnerability = getMaxNetVulnerability(vulnerability);
- System.out.println("Maximum possible net vulnerability: " + maxVulnerability);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement