Thursday, 25 November 2021

IQ Test Problem !!!

 PROBLEM 9: IQ test


Problem Reference : Codeforces 

Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

Input:

The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.


Output:

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.


Solution:

n = int(input())

  1. x = [int(x) for x in input().split()]
  2. a = 0
  3. b = 0
  4. a1 = 0
  5. b1 = 0
  6. for i in range(0,n):
  7. if x[i] % 2 == 0:
  8. a+=1
  9. b = i
  10. if x[i] % 2 == 1:
  11. a1+=1
  12. b1 = i
  13. if a > a1:
  14. print(b1+1)
  15. else:
  16. print(b+1)




This above solution is in python language.



Examples
input
5
2 4 7 8 10
output
3
input
4
1 2 1 1
output
2


No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...