nikunjsoni

565

Sep 9th, 2021
847
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int arrayNesting(vector<int>& A) {
  4.         int res = 0, n = A.size();
  5.         vector<bool> seen(n);
  6.         for (int i: A) {
  7.             int cnt = 0;
  8.             while (!seen[i]) {
  9.                 seen[i] = true;
  10.                 cnt++;
  11.                 i = A[i];
  12.             }
  13.             res = max(res, cnt);
  14.         }
  15.         return res;
  16.     }
  17. };
RAW Paste Data