package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/equal-sum-arrays-with-minimum-number-of-operations/
 */
public class Problem1775 {
    public int minOperations(int[] nums1, int[] nums2) {
        if (nums1.length < nums2.length && 6 * nums1.length < nums2.length) {
            return -1;
        } else if (nums1.length > nums2.length && nums1.length > 6 * nums2.length) {
            return -1;
        }
        int sum1 = 0;
        for (int num : nums1) {
            sum1 += num;
        }
        int sum2 = 0;
        for (int num : nums2) {
            sum2 += num;
        }
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int answer = 0;
        return answer;
    }

    public static void main(String[] args) {
        Problem1775 prob = new Problem1775();
//        System.out.println(prob.minOperations(new int[]{1,2,3,4,5,6}, new int[]{1,1,2,2,2,2})); // 3
//        System.out.println(prob.minOperations(new int[]{1,1,1,1,1,1,1}, new int[]{6})); // -1
//        System.out.println(prob.minOperations(new int[]{6,6}, new int[]{1})); // 3
//        System.out.println(prob.minOperations(new int[]{6,6,5}, new int[]{1,1})); // 3
//        System.out.println(prob.minOperations(new int[]{1,1}, new int[]{6,6,5})); // 3
//        System.out.println(prob.minOperations(new int[]{6,6,5}, new int[]{1,1,1})); // 3
        System.out.println(prob.minOperations(new int[]{5,6,4,3,1,2}, new int[]{6,3,3,1,4,5,3,4,1,3,4})); // 4
    }
}

@@ -704,784 +704,759 @@
     
-return answer;
+if (sum1 %3C sum2) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1775 prob = new Problem1775();%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B1,2,3,4,5,6%7D, new int%5B%5D%7B1,1,2,2,2,2%7D)); // 3%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B1,1,1,1,1,1,1%7D, new int%5B%5D%7B6%7D)); // -1%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B6,6%7D, new int%5B%5D%7B1%7D)); // 3%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B6,6,5%7D, new int%5B%5D%7B1,1%7D)); // 3%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B1,1%7D, new int%5B%5D%7B6,6,5%7D)); // 3%0A//        System.out.println(prob.minOperations(new int%5B%5D%7B6,6,5%7D, new int%5B%5D%7B1,1,1%7D)); // 3%0A        System.out.println(prob.minOperations(new int%5B%5D%7B5,6,4,3,1,2%7D, new int%5B%5D%7B6,3,3,1,4,5,3,4,1,3,4%7D)); // 4
+    int i = 0;%0A            int j = nums2.length - 1;%0A            while (sum1 %3C sum2) %7B%0A                if (i %3C nums1.length && 6 - nums1%5Bi%5D %3E= nums2%5Bj%5D - 1) %7B%0A                    sum1 += 6 - nums1%5Bi++%5D;%0A                %7D else %7B%0A                    sum2 -= nums2%5Bj--%5D - 1;%0A                %7D%0A                answer++;%0A            %7D%0A        %7D else if (sum1 %3E sum2) %7B%0A            int i = nums1.length - 1;%0A            int j = 0;%0A            while (sum1 %3E sum2) %7B%0A                if (i %3E= 0 && nums1%5Bi%5D - 1 %3E= 6 - nums2%5Bj%5D) %7B%0A                    sum1 -= nums1%5Bi--%5D - 1;%0A                %7D else %7B%0A                    sum2 += 6 - nums2%5Bj++%5D;%0A                %7D%0A                answer++;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1775