Sum of Digits - Largest Integer

 Coding Problem Keys 

 Sum of Digits - Largest Integer 

 Problem Statement 

The program must accept an integer N as the input. The program must print the sum of the digits of the largest integer among the N integers as the output.

 Input Format 

The first line contains the value of integer N.
The second line contains N integers separated by space(s).

 Output Format 

The first line contains the sum of the digits of the largest integer among N integers.

 Boundary Condition(s) 

1 <= N <= 100
1 <= Each Integer Value <= 1000

 Example Input/Output 1 

 Input 

6
98 74 85 23 58 21

 Output 

17

 Explanation 

The largest integer is 98.
So the sum of the digits of 98 is 17 (9 + 8).
Hence the output is 17.

 Example Input/Output 2 

 Input 

9
401 884 8 203 123 950 475 520 193

 Output 

14

 Max Execution Time Limit: 4000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

n=int(input())
l=list(map(int,input().split()))
k=max(l);s=0
while(k>0):
    s+=(k%10)
    k//=10
print(s)

# 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

Cut Down & Plant - Trees

Both Adjacent Elements - Odd or Even

Shortest Path in Tree

Unique Element

K'th Largest Number

Number of Profitable Days