Create Sorted Array through Instructions
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 build a sorted container by inserting the elements of instructions one at a time, left to right, starting from an empty container.
Inserting a value x costs min(a, b), where a is the number of elements already in the container that are **strictly less** than x, and b is the number that are **strictly greater** than x. Equal elements count toward neither.
Return the total cost of all insertions **modulo** 10^9 + 7. Aim for O(n log m) where m is the maximum value.
Examples
Constraints
- `1 <= instructions.length <= 10^5`
- `1 <= instructions[i] <= 10^5`
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.