Given an integer array instructions, you are tasked with constructing a sorted array nums by inserting elements from instructions one by one, starting from an empty array nums.
For each element instructions[i] from left to right, insert it into nums such that nums remains sorted in nondecreasing order. The cost of inserting each element is defined as the minimum of:
The number of elements currently in nums that are strictly less than instructions[i].
The number of elements currently in nums that are strictly greater than instructions[i].
Return the total cost to insert all elements into nums. Since the answer may be large, return it modulo
Constraints:
instructions.length
instructions[i]
Given an integer array instructions, you are tasked with constructing a sorted array nums by inserting elements from instructions one by one, starting from an empty array nums.
For each element instructions[i] from left to right, insert it into nums such that nums remains sorted in nondecreasing order. The cost of inserting each element is defined as the minimum of:
The number of elements currently in nums that are strictly less than instructions[i].
The number of elements currently in nums that are strictly greater than instructions[i].
Return the total cost to insert all elements into nums. Since the answer may be large, return it modulo
Constraints:
instructions.length
instructions[i]