Minimum number of deletions to make a sorted sequence#

Given an array of n integers. The task is to remove or delete the minimum number of elements from the array so that when the remaining elements are placed in the same sequence order to form an increasing sorted sequence.

Examples :

Input : {5, 6, 1, 7, 4} Output : 2 Removing 1 and 4 leaves the remaining sequence order as 5 6 7 which is a sorted sequence.

Input : {30, 40, 2, 5, 1, 7, 45, 50, 8} Output : 4

class Solution:
    def min_deletions(self, arr):
        n = len(arr)
        lis = [1] * n
        for i in range(1, n):
            for j in range(i):
                if arr[i] > arr[j]:
                    lis[i] = max(lis[i], lis[j] + 1)
        return n - max(lis)
Solution().min_deletions([5, 6, 1, 7, 4])
2