Company: Infosys sp role_26april
Difficulty: medium
You are given a permutation P of the integers from 1 to N . An index i (1-indexed) is called a fixed point of the permutation when P[i] = i . You must perform exactly one swap between two elements at different indices i and j (1 ≤ i, j ≤ N , i ≠ j ). Choose i and j so that the resulting permutation has as many fixed points as possible. Report the largest number of fixed points achievable after exactly one such swap. Input Format The first line contains a integer, N , giving the size of the permutation. Each line i of the N subsequent lines (where 0 ≤ i < N ) contains a integer, P[i] . Constraints 1 ≤ N ≤ 10 5 1 ≤ P[i] ≤ N Sample Test Cases Case 1 Input: 5 1 3 2 5 4 Output: 3 Explanation: The starting permutation has a single fixed point (P[1]=1). Swapping P[2] and P[3] (values 3 and 2) introduces two more fixed points (P[2]=2, P[3]=3), giving a maximum total of 3 fixed points. Case 2 Input: 3 2 3 1 Output: 1 Explanation: The starting permutation has zero fixe