Make Two Arrays Equal by Reversing Subarrays
EasyArrays & Hashinghashing
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two integer arrays target and arr of the same length. In one move you may pick any contiguous, non-empty subarray of arr and reverse it. You may make as many moves as you like.
Return true if arr can be turned into target this way, and false otherwise.
Examples
Input: target = [1,2,3,4], arr = [2,4,1,3]
Output: true
Reversing lengths-2 windows can swap any adjacent pair, so any rearrangement is reachable.
Input: target = [3,7,9], arr = [3,7,11]
Output: false
`arr` has no 9, so it can never match `target`.
Constraints
- target.length == arr.length
- 1 <= target.length <= 1000
- 1 <= target[i], arr[i] <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.