Sum - Odd Number of Digits

 Coding Problem Keys 

 Sum - Odd Number of Digits 

 Problem Statement 

The program must accept N integers as the input. The program must print the sum of integers having odd number of digits in the given N integers. If there is no such integer, the program must print -1 as the output.

 Boundary Condition(S) 

1 <= N <= 100
1 <= Each integer value <= 10⁹

 Input Format 

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

 Output Format 

The first line contains the sum of integers having odd number of digits in the given N integers or -1.

 Example Input/Output 1 

 Input 

5
12 488 1 78 200

 Output 

689

 Explanation 

The integers with odd number of digits are 488, 1 and 200.
So their sum is 689 (488 + 1 + 200).

 Example Input/Output 2 

 Input 

4
98 45 5000 11

 Output 

-1

 Note: Max Execution Time Limit: 500 millisecs 

 Solution 

 Programming Language: Python 3 Language 

n=int(input())
l=list(map(str,input().split()))
s=0
for i in l:
    if(len(i)%2!=0):
        s+=int(i)
if(s>0): print(s)
else: print("-1")

# 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

Count Number of Occurrences of a Character

Print Prime Numbers from 2 to N

Cities and Population

K Palindrome Integers

Most Vowels in Row

Sum of Numbers - XOR and OR