FARR - Editorial

Author : codechef_ciem | CodeChef CIEM Chapter

Problem link : Fixed Point Array | CodeChef

Problem Statement :
A fixed point in an array is an element whose value is equal to its index. Given an array of distinct elements, return all the fixed points, only if the sum of all fixed points is multiple of 4. Otherwise, return ′False′.

Solution :

t = int(input())
for _ in range(t):
    n = int(input())
    arr = [int(x) for x in input().split()]
    lst = []
    for i in range(n):
        if(arr[i]==i):
            lst.append(i)
    if(sum(lst)%4 == 0 and len(lst)>0):
        for i in lst:
            print(i, end=' ')
    else:
        print('False')