|
| 1 | +<h2><a href="https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays">1460. Make Two Arrays Equal by Reversing Subarrays</a></h2><h3>Easy</h3><hr><p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> |
| 2 | + |
| 3 | +<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em> equal to </em><code>target</code><em> or </em><code>false</code><em> otherwise</em>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> target = [1,2,3,4], arr = [2,4,1,3] |
| 10 | +<strong>Output:</strong> true |
| 11 | +<strong>Explanation:</strong> You can follow the next steps to convert arr to target: |
| 12 | +1- Reverse subarray [2,4,1], arr becomes [1,4,2,3] |
| 13 | +2- Reverse subarray [4,2], arr becomes [1,2,4,3] |
| 14 | +3- Reverse subarray [4,3], arr becomes [1,2,3,4] |
| 15 | +There are multiple ways to convert arr to target, this is not the only way to do so. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> target = [7], arr = [7] |
| 22 | +<strong>Output:</strong> true |
| 23 | +<strong>Explanation:</strong> arr is equal to target without any reverses. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong class="example">Example 3:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> target = [3,7,9], arr = [3,7,11] |
| 30 | +<strong>Output:</strong> false |
| 31 | +<strong>Explanation:</strong> arr does not have value 9 and it can never be converted to target. |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>target.length == arr.length</code></li> |
| 39 | + <li><code>1 <= target.length <= 1000</code></li> |
| 40 | + <li><code>1 <= target[i] <= 1000</code></li> |
| 41 | + <li><code>1 <= arr[i] <= 1000</code></li> |
| 42 | +</ul> |
0 commit comments