Menu Close

Return maximum number of operations performed on array.

Given an array numbs of integers, you can perform operations on the array. If each operations, you pick any nums[i] and delete it to earn nums[i] points.
After, you must delete every element equal to nums[i]-1 or nums[i]+1.

You start with 0 points. Return the maximum number of points you can earn by applying such operations.

numb=list(map(int,input('Enter the array numbers: ').split(' ')))

a=int(len(numb)/2)
for i in range(0,len(numb)):
    if(a<len(numb)):
        for j in range(0,len(numb)):
            if(a<len(numb)):
                if((numb[j]== numb[a]-1) or (numb[j]==numb[a]+1)):
                    numb[j]=0
        if(a<len(numb)):
            a+=1
points=0
for i in range(len(numb)):
    points+=numb[i]
print(points)

Input:
         Enter the array numbers: 3 4 2
Output:
         6


Output:
Enter the array numbers: 3 4 2
6

Output:
Enter the array numbers: 6 5 2 0
13

Output:
Enter the array numbers: 8 9 5 6 2
24

Output:
Enter the array numbers: 10 100 1000 20
1130

Output:
Enter the array numbers: 65 20 30
115

Output:
Enter the array numbers: 1 1 2 1
2

Output:
Enter the array numbers: 0 1 2 3 4 5
8

Output:
Enter the array numbers: 1 2 3 4 5
8

Output:
Enter the array numbers: 3 2 100
102



More Codes to Fcuk