- Online Game Wipro previous year coding question

Problem : 

You are playing an online game. In the game a list of N numbers is given. The player has to arrange the numbers so that all the odd numbers of the list come after the even number write an algorithm to arrange the given list such that all the odd numbers of the list come after the even no

Input: 

The first line of the input consists of an integer and Num representing the size of the list(n) the second line of the input consists of in space separated integers representing the values of the list 


Output: 

Print n space separated integers such that all the odd numbers of the list come after the even no.

Sample Input

8

10 98 3 33 12 22 21 11

Sample Output :

 10 98 12 22 3 33 21 11

Program:

Python 3:

n=int(input())
list1=list(map(int,input().split()))

list2=[item for item in list1 if item%2==0]

list3=[item for item in list1 if item%2!=0]

for item in list2:
print(item)

for item in list3:
print(item)

Post a Comment

Previous Post Next Post