1460. Make Two Arrays Equal by Reversing Sub-arrays Easy
1/**
2 * [1460] Make Two Arrays Equal by Reversing Sub-arrays
3 *
4 * You are 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.
5 * Return true if you can make arr equal to target or false otherwise.
6 *
7 * Example 1:
8 *
9 * Input: target = [1,2,3,4], arr = [2,4,1,3]
10 * Output: true
11 * Explanation: You can follow the next steps to convert arr to target:
12 * 1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3]
13 * 2- Reverse sub-array [4,2], arr becomes [1,2,4,3]
14 * 3- Reverse sub-array [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 *
17 * Example 2:
18 *
19 * Input: target = [7], arr = [7]
20 * Output: true
21 * Explanation: arr is equal to target without any reverses.
22 *
23 * Example 3:
24 *
25 * Input: target = [3,7,9], arr = [3,7,11]
26 * Output: false
27 * Explanation: arr does not have value 9 and it can never be converted to target.
28 *
29 *
30 * Constraints:
31 *
32 * target.length == arr.length
33 * 1 <= target.length <= 1000
34 * 1 <= target[i] <= 1000
35 * 1 <= arr[i] <= 1000
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/
41// discuss: https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn can_be_equal(target: Vec<i32>, arr: Vec<i32>) -> bool {
47 false
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1460() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.