Shift Largest Digit - Sum

 Coding Problem Keys 

 Shift Largest Digit - Sum 

 Problem Statement 

The program must accept N integers as the input. For each integer X among the N integers, the program must shift the largest digit in X to the left. If the largest digit occurs more than once in an integer, the program must shift the last occurring largest digit to the left. Then the program must print the sum of the N modified integers as the output.

 Input Format 

The first line contains N.
The second line contains N integers separated by a space.

 Output Format 

The first line contains an integer representing the sum of the N modified integers.

 Boundary Condition(s) 

2 <= K <= N
 <= 1000
1 <= Each integer value <= 10

 Example Input/Output 1 

 Input 

4
4613 234 6969 2990

 Output 

25822

 Explanation 

Here N = 4.
After shifting the largest digit in each integer to the left, the integers become 6413 423 9696 9290
The sum of the 4 modified integers is 25822.
So 25822 is printed as the output.

 Example Input/Output 2 

 Input 

7
62 511 808 264 590 5 3453

 Output 

8375

 Max Execution Time Limit: 50 millisecs 

 Solution 

 Programming Language: Python 3 Language 

n=int(input())
l=list(map(list,input().split()))
k=[]
for i in range(n):
    c=max(l[i])
    f=0;s=""
    l[i]=l[i][::-1]
    for j in range(len(l[i])):
        if(l[i][j]==c and f==0):
            f+=1
            pass
        else:
            s+=l[i][j]
    k.append(int(c+s[::-1]))
print(sum(k))

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Reverse Column - First and Last

Unit Digit from 1 to 5

Sort the Binary Values

Matrix Unit Digit Swap

Search String S2 in S1 Character Matrix

Alphabetical Order Pattern