|
| 1 | +<h2>1640. Check Array Formation Through Concatenation</h2><h3>Easy</h3><hr><div><p>You are given an array of <strong>distinct</strong> integers <code>arr</code> and an array of integer arrays <code>pieces</code>, where the integers in <code>pieces</code> are <strong>distinct</strong>. Your goal is to form <code>arr</code> by concatenating the arrays in <code>pieces</code> <strong>in any order</strong>. However, you are <strong>not</strong> allowed to reorder the integers in each array <code>pieces[i]</code>.</p> |
| 2 | + |
| 3 | +<p>Return <code>true</code> <em>if it is possible </em><em>to form the array </em><code>arr</code><em> from </em><code>pieces</code>. Otherwise, return <code>false</code>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong>Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre><strong>Input:</strong> arr = [85], pieces = [[85]] |
| 9 | +<strong>Output:</strong> true |
| 10 | +</pre> |
| 11 | + |
| 12 | +<p><strong>Example 2:</strong></p> |
| 13 | + |
| 14 | +<pre><strong>Input:</strong> arr = [15,88], pieces = [[88],[15]] |
| 15 | +<strong>Output:</strong> true |
| 16 | +<strong>Explanation:</strong> Concatenate <code>[15]</code> then <code>[88]</code> |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong>Example 3:</strong></p> |
| 20 | + |
| 21 | +<pre><strong>Input:</strong> arr = [49,18,16], pieces = [[16,18,49]] |
| 22 | +<strong>Output:</strong> false |
| 23 | +<strong>Explanation:</strong> Even though the numbers match, we cannot reorder pieces[0]. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong>Example 4:</strong></p> |
| 27 | + |
| 28 | +<pre><strong>Input:</strong> arr = [91,4,64,78], pieces = [[78],[4,64],[91]] |
| 29 | +<strong>Output:</strong> true |
| 30 | +<strong>Explanation:</strong> Concatenate <code>[91]</code> then <code>[4,64]</code> then <code>[78]</code></pre> |
| 31 | + |
| 32 | +<p><strong>Example 5:</strong></p> |
| 33 | + |
| 34 | +<pre><strong>Input:</strong> arr = [1,3,5,7], pieces = [[2,4,6,8]] |
| 35 | +<strong>Output:</strong> false |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li><code>1 <= pieces.length <= arr.length <= 100</code></li> |
| 43 | + <li><code>sum(pieces[i].length) == arr.length</code></li> |
| 44 | + <li><code>1 <= pieces[i].length <= arr.length</code></li> |
| 45 | + <li><code>1 <= arr[i], pieces[i][j] <= 100</code></li> |
| 46 | + <li>The integers in <code>arr</code> are <strong>distinct</strong>.</li> |
| 47 | + <li>The integers in <code>pieces</code> are <strong>distinct</strong> (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).</li> |
| 48 | +</ul> |
| 49 | +</div> |
0 commit comments