Company: Infosys sp role_26april
Difficulty: medium
You are given a permutation P of the integers from 1 to N . A fixed point of a permutation is an index i (1-indexed) such that P[i] = i . You are required to perform exactly one swap of two elements at different indices i and j (1 ≤ i, j ≤ N , i ≠ j ). Your goal is to choose the indices i and j such that the number of fixed points in the resulting permutation is maximized. Find the maximum number of fixed points possible after performing exactly one such swap. Input Format The first line contains a integer, N , denoting 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 initial permutation has one fixed point (P[1]=1). Swapping P[2] and P[3] (values 3 and 2) creates two new fixed points (P[2]=2, P[3]=3), resulting in a maximum total of 3 fixed points. Case 2 Input: 3 2 3 1 Output: 1 Explanat