Relative Sort Array
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 arr1 and arr2. The values in arr2 are distinct, and every value of arr2 also occurs in arr1.
Reorder arr1 so that values appearing in arr2 come first, grouped together, in the same relative order as in arr2 (all copies of arr2[0], then all copies of arr2[1], and so on). Values that do not appear in arr2 go at the end in ascending order.
Return the reordered array.
Examples
Constraints
- 1 <= arr1.length, arr2.length <= 1000
- 0 <= arr1[i], arr2[i] <= 1000
- All values of `arr2` are distinct and each appears in `arr1`
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.