Date: 2026-06-06
Time: 17:31
This file solves LeetCode 1460: Make Two Arrays Equal by Reversing Subarrays. It determines whether arr can be transformed into target using any number of subarray reversals.
The key insight is that reversing subarrays is equivalent to arbitrary reordering — you can sort any array using a sequence of subarray reversals (this is essentially selection sort). So the problem reduces to: do the two arrays contain the same elements with the same frequencies?
Solution.makeTwoArraysEqualByReversingSubarrays — Takes two integer lists, returns a bool. The entire logic is a single-line multiset equality check via sorting.
sorted(a) == sorted(b) is the standard Python one-liner for multiset equality. An alternative would be Counter(target) == Counter(arr), which is O(n) instead of O(n log n) but has higher constant factors for small inputs.Imports: typing.List — used only for type annotations in the LeetCode function signature.
Imported by: The massive importedby list is misleading — it reflects the test runner infrastructure, not actual code coupling. Only make-two-arrays-equal-by-reversing-subarrays/testsolution.py actually tests this solution. The other test files import the same Solution pattern from their own directories.
1. Both target and arr are sorted independently (producing new lists, not mutating the originals).
2. The sorted lists are compared element-by-element via ==.
3. The boolean result is returned directly.
No iteration, no branching, no mutation.
sorted() returns new lists.None. The function trusts the caller to provide valid inputs per LeetCode's contract. Passing arrays of different lengths returns False naturally (sorted lists of different lengths aren't equal).
make-two-arrays-equal-by-reversing-subarrays/test_solution.py — See what edge cases the test suite covers (empty arrays, single elements, duplicates)make-two-arrays-equal-by-reversing-subarrays/review.md — The code review likely discusses the sort-vs-Counter tradeoffsubarray-reversal-sorting-equivalence — Why arbitrary subarray reversals give you full permutation power (pancake sorting theorem)check-array-formation-through-concatenation/solution.py:Solution — A related array rearrangement problem with stricter constraints where sorting alone doesn't workreversal-equals-reorder — Any permutation of an array is reachable via a sequence of subarray reversals, so the problem reduces to multiset equalitysorted-comparison-correctness — sorted(a) == sorted(b) returns True iff a and b contain the same elements with the same multiplicitiesno-mutation — The solution never modifies the input arrays; sorted() allocates new liststime-complexity-nlogn — The solution runs in O(n log n) due to two sorts; an O(n) Counter-based approach exists but isn't used