Advertisement
dorucriv

Count of rectangles with area less than the given number

Apr 1st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. public class Solution {
  2.    
  3.     public static int MOD = (int) 1e9 + 7;
  4.    
  5.     public int solve(int[] A, int B) {
  6.         int count = 0;
  7.         int i = 0, j = A.length - 1;
  8.         while (i < A.length && j >= 0) {
  9.             if ((long) A[i] * A[j] >= B) {
  10.                 j--;
  11.             } else {
  12.                 count = (count + j + 1) % MOD;
  13.                 i++;
  14.             }
  15.         }
  16.         return count;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement