package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * https://leetcode.com/problems/random-point-in-non-overlapping-rectangles/
 */
public class Problem497 {
    private static class Solution {
        private final List<int[]> rects = new ArrayList<>();
        private final Random random = new Random();

        public Solution(int[][] rects) {
            for (int i = 0; i < rects.length; i++) {
                int area = area(rects[i]);
                if (area > 0) {
                    this.rects.add(rects[i]);
                }
            }
        }

        public int[] pick() {
            int index = random.nextInt(rects.size());
            int[] rect = rects.get(index);
            return null;
        }

        private static int area(int[] rect) {
            return (rect[0] - rect[2]) * (rect[1] * rect[3]);
        }
    }

    public static void main(String[] args) {

    }
}

@@ -36,24 +36,49 @@
 .ArrayList;%0A
+import java.util.Arrays;%0A
 import java.
@@ -485,19 +485,20 @@
         
-int
+long
  area = 
@@ -777,19 +777,359 @@
     
-return null
+int minX = Integer.min(rect%5B0%5D, rect%5B2%5D);%0A            int maxX = Integer.max(rect%5B0%5D, rect%5B2%5D);%0A            int minY = Integer.min(rect%5B1%5D, rect%5B3%5D);%0A            int maxY = Integer.max(rect%5B1%5D, rect%5B3%5D);%0A%0A            int x = random.nextInt(maxX - minX) + minX;%0A            int y = random.nextInt(maxY - minY) + minY;%0A            return new int%5B%5D%7Bx, y%7D
 ;%0A  
@@ -1160,19 +1160,20 @@
  static 
-int
+long
  area(in
@@ -1200,23 +1200,94 @@
     
-return 
+long minX = Integer.min(rect%5B0%5D, rect%5B2%5D);%0A            long maxX = Integer.max
 (rect%5B0%5D
  - r
@@ -1282,18 +1282,17 @@
 (rect%5B0%5D
- -
+,
  rect%5B2%5D
@@ -1296,94 +1296,486 @@
 %5B2%5D)
- * (rect%5B1%5D * rect%5B3%5D);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A
+;%0A            long minY = Integer.min(rect%5B1%5D, rect%5B3%5D);%0A            long maxY = Integer.max(rect%5B1%5D, rect%5B3%5D);%0A            return (maxX - minX) * (maxY * minY);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Solution solution = new Solution(new int%5B%5D%5B%5D%7B%7B1, 1, 5, 5%7D%7D);%0A        System.out.println(Arrays.toString(solution.pick()));%0A        System.out.println(Arrays.toString(solution.pick()));%0A        System.out.println(Arrays.toString(solution.pick()));
 %0A   

Update problem 497