Practice Create Sorted Array through Instructions
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Create Sorted Array through Instructions
Problem Statement
Process instructions from left to right, inserting each value into an initially empty sorted collection. Its insertion cost is the smaller of the number of existing elements strictly below it and the number strictly above it; equal values count toward neither side. Return the total cost modulo 10^9 + 7.
Source: Create Sorted Array through Instructions on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
instructions = [1,5,6,2]
1
# Example 2
instructions = [1,2,3,6,5,4]
3
# Example 3
instructions = [1,3,3,3,2,4,2,1,2]
4
Constraints
Related LeetCode Problems
Practice more problems similar to Create Sorted Array through Instructions.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.