Min Ops to Collect Elements

Remove elements from the end of an array until all numbers 1 through k have been collected at least once. Return the minimum number of removal operations needed, or -1 if impossible.

Examples
Input: [[3,1,5,4,2],2]
Output: 4
Hints

Min Ops to Collect Elements

Remove elements from the end of an array until all numbers 1 through k have been collected at least once. Return the minimum number of removal operations needed, or -1 if impossible.