package leetcode;

/**
 * https://leetcode.com/problems/check-array-formation-through-concatenation/
 */
public class Problem1640 {
    public boolean canFormArray(int[] arr, int[][] pieces) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1640 prob = new Problem1640();
        System.out.println(prob.canFormArray(new int[]{85}, new int[][]{{85}})); // true
        System.out.println(prob.canFormArray(new int[]{15,88}, new int[][]{{88},{15}})); // true
        System.out.println(prob.canFormArray(new int[]{49,18,16}, new int[][]{{8516,18,49}})); // false
        System.out.println(prob.canFormArray(new int[]{91,4,64,78}, new int[][]{{78},{4,64},{91}})); // true
        System.out.println(prob.canFormArray(new int[]{1,3,5,7}, new int[][]{{2,4,6,8}})); // false
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -224,36 +224,923 @@
     
-// TODO%0A        return false
+Arrays.sort(pieces, (a, b) -%3E %7B%0A            int cmp = Integer.compare(b.length, a.length);%0A            if (cmp == 0) %7B%0A                return Integer.compare(Arrays.toString(b).length(), Arrays.toString(a).length());%0A            %7D%0A            return cmp;%0A        %7D);%0A        String str = toString(arr);%0A        for (int%5B%5D piece : pieces) %7B%0A            String s = toString(piece);%0A            int index = str.indexOf(s);%0A            if (index %3C 0) %7B%0A                return false;%0A            %7D%0A            str = str.substring(0, index) + str.substring(index + s.length());%0A        %7D%0A        return true;%0A    %7D%0A%0A    private static String toString(int%5B%5D arr) %7B%0A        StringBuilder sb = new StringBuilder();%0A        for (int a : arr) %7B%0A            if (sb.length() == 0) %7B%0A                sb.append(a);%0A            %7D else %7B%0A                sb.append(%22,%22).append(a);%0A            %7D%0A        %7D%0A        return sb.toString()
 ;%0A  
@@ -1500,18 +1500,16 @@
 nt%5B%5D%5B%5D%7B%7B
-85
 16,18,49
@@ -1691,51 +1691,599 @@
 t%5B%5D%7B
-1,3,5,7%7D, new int%5B%5D%5B%5D%7B%7B2,4,6,8%7D%7D)); // fals
+91,4,64,78%7D, new int%5B%5D%5B%5D%7B%7B78%7D,%7B64,4%7D,%7B91%7D%7D)); // false%0A        System.out.println(prob.canFormArray(new int%5B%5D%7B1,3,5,7%7D, new int%5B%5D%5B%5D%7B%7B2,4,6,8%7D%7D)); // false%0A        System.out.println(prob.canFormArray(new int%5B%5D%7B4,56,4%7D, new int%5B%5D%5B%5D%7B%7B4%7D, %7B4,56%7D%7D)); // true%0A        System.out.println(prob.canFormArray(new int%5B%5D%7B32,66,73,15,3,70,53%7D, new int%5B%5D%5B%5D%7B%7B66,73%7D,%7B15%7D,%7B3%7D,%7B32%7D,%7B70%7D,%7B53%7D%7D)); // true%0A        System.out.println(prob.canFormArray(new int%5B%5D%7B75,1,60,91,84,55,5,39,19,52,38,66,14,17,49%7D,%0A            new int%5B%5D%5B%5D%7B%7B60%7D,%7B52,38%7D,%7B66%7D,%7B39%7D,%7B19%7D,%7B1%7D,%7B84,55%7D,%7B17%7D,%7B14%7D,%7B49%7D,%7B91%7D,%7B5%7D,%7B75%7D%7D)); // tru
 e%0A  

Update problem 1640