Advertisement
rajeshinternshala

Untitled

Nov 30th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1.     static int getMaxNetVulnerability(List<List<Integer>> vulnerability) {
  2.         int n = vulnerability.size();
  3.         int m = vulnerability.get(0).size();
  4.  
  5.         int maxNetVulnerability = Integer.MIN_VALUE;
  6.  
  7.         // Iterate through all combinations of m - 1 rows
  8.         for (int row1 = 0; row1 < n - 1; row1++) {
  9.             for (int row2 = row1 + 1; row2 < n; row2++) {
  10.                 List<Integer> row1Data = vulnerability.get(row1);
  11.                 List<Integer> row2Data = vulnerability.get(row2);
  12.  
  13.                 int[] maxInColumns = new int[m];
  14.  
  15.                 // Calculate the maximum vulnerability for each column
  16.                 for (int col = 0; col < m; col++) {
  17.                     int max = Math.max(row1Data.get(col), row2Data.get(col));
  18.                     maxInColumns[col] = max;
  19.                 }
  20.  
  21.                 // Find the minimum vulnerability among the maximums of each column
  22.                 int minMaxInColumns = Arrays.stream(maxInColumns).min().orElse(Integer.MAX_VALUE);
  23.  
  24.                 maxNetVulnerability = Math.max(maxNetVulnerability, minMaxInColumns);
  25.             }
  26.         }
  27.  
  28.         return maxNetVulnerability;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement