#1460
Easy Algorithms Make two arrays equal by reversing subarrays
Array Hash Table Sorting
75.8% acceptance
Feb 25, 2026
1523
164
Given two integer arrays of equal length target and arr.
In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps.
Return true if you can make arr equal to target, or false otherwise.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn can_be_equal(mut target: Vec<i32>, mut arr: Vec<i32>) -> bool {
target.sort_unstable();
arr.sort_unstable();
target == arr
}
}