Even Integers - Even Positions
Coding Problem Keys
Even Integers - Even Positions
Problem Statement
The program must accept N integers as the input. The program must print all the even integers which are at the even positions as the output. If there is no even integer are even positions then the program must print -1 as the output.Input Format
The first line contains the value N.The second line contains N integers separated by space(s).
Output Format
The first line contains the even integers which have occurred at the even positions each separated by space(s).Boundary Condition(s)
1 <= N <= 10⁵-99999 <= Each Integer Value <= 99999
Example Input/Output 1
Input
743 -49 -22 16 -86 78 77
Output
16 78
Explanation
The integers present at even positions are -49, 16 and 78. So the even integers are 16 and 78.
Hence the output is 16 and 78.
Example Input/Output 2
Input
524 -45 38 -13 37
Output
-1
Max Execution Time Limit: 2000 millisecs
Solution
Programming Language: Python 3 Language
n=int(input())
l=list(map(int,input().split()))
k=[]
for i in range(len(l)):
if(i%2!=0 and l[i]%2==0):
k.append(l[i])
if len(k)>0:
print(*k)
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