Advertisement
rajeshinternshala

Untitled

Jul 30th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.  public static long countInvestablePeriods(int[] price, int maxPrice, int minPrice) {
  2.         int n = price.length;
  3.         long count = 0;
  4.         for (int i = 0; i < n; i++) {
  5.             int max = price[i];
  6.             int min = price[i];
  7.             for (int j = i + 1; j < n; j++) {
  8.                 max = Math.max(max, price[j]);
  9.                 min = Math.min(min, price[j]);
  10.                 if (max == maxPrice && min == minPrice) {
  11.                     count++;
  12.                 }
  13.             }
  14.         }
  15.         return count;
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement