Make Two Arrays Equal by Reversing

Easy

Description

Given two integer arrays target and arr, return true if you can make arr equal to target by reversing any subarray of arr any number of times.

Examples

Input:target = [1,2,3,4], arr = [2,4,1,3]
Output:true
Explanation:

Can rearrange to match.

Input:target = [7], arr = [7]
Output:true
Explanation:

Both arrays are identical with a single element [7].

Input:target = [3,7,9], arr = [3,7,11]
Output:false
Explanation:

arr contains 11 which is not in target (which has 9). Reversing subarrays cannot change element values.

Constraints

  • 1 ≤ target.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!