Description

Append Sort

Design a hardware module that implements append sort: given an array, repeatedly append the next integer in sequence if it creates a sorted array. Determine the minimum number of appends needed to make the array sorted, considering optimal digit modifications.

Example: For [100,7,10], determine minimum appends needed to make array sorted, considering digit modifications.

Source: Google Code Jam 2021 Round 1A - Problem A: Append Sort

Input

x

Stream of 32-bit Unsigned Integer
Initial array to make sorted by appending.

Output

32-bit Unsigned Integer
Minimum appends needed for sorted array.