2022-09-17 21:23:12 +08:00
< 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 >
< 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 >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-09-17 21:23:12 +08:00
< pre >
< strong > Input:< / strong > target = [1,2,3,4], arr = [2,4,1,3]
< strong > Output:< / strong > true
< strong > Explanation:< / strong > You can follow the next steps to convert arr to target:
1- Reverse subarray [2,4,1], arr becomes [1,4,2,3]
2- Reverse subarray [4,2], arr becomes [1,2,4,3]
3- Reverse subarray [4,3], arr becomes [1,2,3,4]
There are multiple ways to convert arr to target, this is not the only way to do so.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-09-17 21:23:12 +08:00
< pre >
< strong > Input:< / strong > target = [7], arr = [7]
< strong > Output:< / strong > true
< strong > Explanation:< / strong > arr is equal to target without any reverses.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-09-17 21:23:12 +08:00
< pre >
< strong > Input:< / strong > target = [3,7,9], arr = [3,7,11]
< strong > Output:< / strong > false
< strong > Explanation:< / strong > arr does not have value 9 and it can never be converted to target.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > target.length == arr.length< / code > < / li >
< li > < code > 1 < = target.length < = 1000< / code > < / li >
< li > < code > 1 < = target[i] < = 1000< / code > < / li >
< li > < code > 1 < = arr[i] < = 1000< / code > < / li >
< / ul >