Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int getMaxNetVulnerability(List<List<Integer>> vulnerability) {
- int n = vulnerability.size();
- int m = vulnerability.get(0).size();
- int maxNetVulnerability = Integer.MIN_VALUE;
- // Iterate through all combinations of m - 1 rows
- for (int row1 = 0; row1 < n - 1; 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];
- // Calculate the maximum vulnerability for each column
- for (int col = 0; col < m; col++) {
- int max = Math.max(row1Data.get(col), row2Data.get(col));
- maxInColumns[col] = max;
- }
- // Find the minimum vulnerability among the maximums of each column
- int minMaxInColumns = Arrays.stream(maxInColumns).min().orElse(Integer.MAX_VALUE);
- maxNetVulnerability = Math.max(maxNetVulnerability, minMaxInColumns);
- }
- }
- return maxNetVulnerability;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement