tygarian

count pairs

Feb 19th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Solution {
  2. public:
  3. // Time Complexity:- O(N^2)
  4. // Space Complexity:- O(1)
  5. int countPairs(vector<int>& nums, int k) {
  6. int n = nums.size(),count_of_pairs = 0;
  7. for(int i=0;i<n;i++){
  8. for(int j = i + 1;j<n;j++){
  9. if(nums[i]==nums[j]){
  10. int product = i * j;
  11. if(product%k==0){
  12. count_of_pairs++;
  13. }
  14. }
  15. }
  16. }
  17. return count_of_pairs;
  18. }
  19. };
Add Comment
Please, Sign In to add comment