Given N doors and N persons. The doors are numbered from 1 to N and persons are given id’s numbered from 1 to N. Each door can have only two statuses i.e. open (1) or closed (0) . Initially all the doors have status closed. Find the final status of all the doors, when all the persons have changed the status of the doors of which they are authorized. i.e. if status open then change the status to closed and vice versa. A person with id ‘i’ is authorized to change the status of door numbered ‘j’ if ‘j’ is a multiple of ‘i’.
Note: A person has to change the current status of all the doors for which he is authorized exactly once.
Input: N = 3 Output: 1 0 0 Explanation: Initiall status of rooms - 0 0 0. Person with id 2 changes room 2 to open, i.e. (0 1 0). Person with id 1 changes room 1, 2, 3 status (1 0 1). Person with id 3 changes room 3 status i.e. (1 0 0).
Input: N = 2 Output: 1 0 Explanation: Initiall status of rooms - 0 0. Person with id 2 changes room 2 to open, i.e. (0 1). Person with id 1 changes room 1, 2 status (1 0).
You don't need to read input or print anything. Your task is to complete the function checkDoorStatus() which takes an Integer N as input and returns an array as the answer.
Expected Time Complexity: O(N*sqrt(N))
Expected Auxiliary Space: O(N)
1 <= N <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes