Implement a function that calculates the minimum number of operations required to sort a stack of cards labeled with integers in descending order. The operations allowed are popping the top card from the stack.
The function should take a list of integers a, representing the labels on the cards in a stack, and an integer n, representing the number of cards.
The function should reverse the order of the input list to represent the cards being stacked in reverse (the top card is the last element of the list).
It should then compute how many cards can remain in the stack in a consecutive decreasing sequence starting from the top.
Finally, it should return the difference between the total number of cards (n) and the length of this consecutive sequence, which denotes the minimum number of operations needed to sort the cards.
Input/Output Requirements
Input:
a (List[int]): A list of integers where ( 1 \leq |a| \leq 1000) (the card labels).
n (int): An integer representing the number of cards in the stack, where ( n = |a| ).
Output:
Returns an integer representing the minimum number of operations required to sort the stack of cards.
Example
python
# Example Input
a = [3, 2, 1, 5, 4]
n = 5
# Example Output
result = min_operations_to_sort_cards(a, n) # Output: 2
Implementation Instructions
Create a file named solution.py within the /app directory.
Write the function min_operations_to_sort_cards as per the above specifications.