Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- // Time Complexity:- O(N^2)
- // Space Complexity:- O(1)
- int countPairs(vector<int>& nums, int k) {
- int n = nums.size(),count_of_pairs = 0;
- for(int i=0;i<n;i++){
- for(int j = i + 1;j<n;j++){
- if(nums[i]==nums[j]){
- int product = i * j;
- if(product%k==0){
- count_of_pairs++;
- }
- }
- }
- }
- return count_of_pairs;
- }
- };
Add Comment
Please, Sign In to add comment