Most-Efficient O(N) 2-pointer approach using C++
\nclass Solution {\npublic:\n    int countPairs(vector<int>& v, int k) {\n        int i = 0 ;\n        int j = v.size() - 1 ;\n        int n = 0 ;\n        whil
```\nclass Solution {\npublic:\n    int countPairs(vector<int>& v, int k) {\n        int i = 0 ;\n        int j = v.size() - 1 ;\n        int n = 0 ;\n        while ( i < j ) {\n            if( v[i] == v[j] and (i*j)%k == 0 ) n++ ;\n            if ( j == i+1 ) {\n                i++ ;\n                j = v.size() - 1 ;\n            }\n            else j-- ;\n        }\n        return n ;\n    }\n};\n```\n**Upvote**.\n*Thank You.*
['C']