Advertisement
rajeshinternshala

Untitled

Mar 8th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.     static int solve(List<Integer> login, List<Integer> logout) {
  2.         int max = 0;
  3.         for (int x : logout) {
  4.             max = Math.max(x, max);
  5.         }
  6.         int dp[] = new int[max + 2];
  7.         for (int x : login) {
  8.             dp[x]++;
  9.         }
  10.         for (int x : logout) {
  11.             dp[x + 1]--;
  12.         }
  13.         int maxNumber = 0;
  14.         for (int i = 2; i < dp.length; i++) {
  15.             dp[i] += dp[i - 1];
  16.             maxNumber = Math.max(dp[i], maxNumber);
  17.         }
  18.         int ans = 0;
  19.         for (int x : dp) {
  20.             if (x == maxNumber) ans++;
  21.         }
  22.         return ans;
  23.  
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement