Advertisement
rajeshinternshala

Untitled

Nov 30th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class MaxNetVulnerability {
  4.     static int getMaxNetVulnerability(List<List<Integer>> vulnerability) {
  5.         int n = vulnerability.size();
  6.         int m = vulnerability.get(0).size();
  7.  
  8.         int maxNetVulnerability = Integer.MIN_VALUE;
  9.  
  10.         for (int row1 = 0; row1 < n; row1++) {
  11.             for (int row2 = row1 + 1; row2 < n; row2++) {
  12.                 List<Integer> row1Data = vulnerability.get(row1);
  13.                 List<Integer> row2Data = vulnerability.get(row2);
  14.  
  15.                 int[] maxInColumns = new int[m];
  16.  
  17.                 for (int col = 0; col < m; col++) {
  18.                     int max = Math.max(row1Data.get(col), row2Data.get(col));
  19.                     maxInColumns[col] = max;
  20.                 }
  21.  
  22.                 int minMaxInColumns = Integer.MAX_VALUE;
  23.                 for (int max : maxInColumns) {
  24.                     minMaxInColumns = Math.min(minMaxInColumns, max);
  25.                 }
  26.  
  27.                 maxNetVulnerability = Math.max(maxNetVulnerability, minMaxInColumns);
  28.             }
  29.         }
  30.  
  31.         return maxNetVulnerability;
  32.     }
  33.  
  34.     public static void main(String[] args) {
  35.         List<List<Integer>> vulnerability = new ArrayList<>();
  36.         vulnerability.add(Arrays.asList(1, 3, 1));
  37.         vulnerability.add(Arrays.asList(3, 1, 1));
  38.         vulnerability.add(Arrays.asList(1, 2, 2));
  39.         vulnerability.add(Arrays.asList(1, 1, 3));
  40.  
  41.         int maxVulnerability = getMaxNetVulnerability(vulnerability);
  42.         System.out.println("Maximum possible net vulnerability: " + maxVulnerability);
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement