id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
530 | <p>Given the <code>root</code> of a Binary Search Tree (BST), return <em>the minimum absolute difference between the values of any two different nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n\n int n = nums.size();\n sort(nums.begin(), nums.end());\n\n int i = 0, j = 1;\n int ans = 0;\n\n \n\n while (j < n) {\n if ((nums[j] - nums[i]) == k) {\n while((i<... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n\n int n = nums.size();\n sort(nums.begin(), nums.end());\n\n int i = 0, j = 1;\n int ans = 0;\n\n if (k == 0) {\n for (int i = 0; i < nums.size() - 1; i++) {\n if (nums[i]... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n int count = 0;\n for (int i = 0; i < n; i++) {\n \n //unqiue\n if(i>0 && nums[i]==nums[i-1]){\n conti... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int binarysearch(vector<int>& vec, int num, int min) {\n int low = min + 1, high = vec.size() - 1, mid;\n while (high >= low) {\n mid = (high + low) / 2;\n if (num > vec[mid]) {\n low = mid + 1;\n } else if (num < ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int binarysearch(vector<int>& vec, int num, int min) {\n int low = min + 1, high = vec.size() - 1, mid;\n while (high >= low) {\n mid = (high + low) / 2;\n if (num > vec[mid]) {\n low = mid + 1;\n } else if (num < ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int target) {\n if(target < 0) return 0;\n int start = 0;\n int end = 1;\n int n = nums.size();\n int count = 0;\nsort(nums.begin() , nums.end());\n while(end < n){\n \n if(nums[en... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int left = 0, right = 1, count = 0;\n while (right < nums.size()) {\n if (left == right || nums[right] - nums[left] < k) {\n right++;\n } else if (nums[right] - ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n\n int k_diff_pairs = 0;\n\n pair<int,int> last_pair = {INT_MIN,INT_MIN};\n\n int i=0;\n int j=1;\n\n while(j<nums.size()){\n if(i==j)j++;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n int i=0;\n int j=i+1;\n int n=nums.size();\n int cnt=0;\n\n\n while(j<n)\n {\n if(nums[j]-nums[i]==k)\n {\n... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n \n int ans=0;\n if(k==0){\n unordered_map<int,int> mp;\n for(auto i: nums) mp[i]++;\n for(auto i: mp) if(i.second>1) ans++;\n return ans;\n }\n sort(nu... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& v1, int k) {\n sort(v1.begin(),v1.end());\n int ans=0;\n vector<int>v;\n if(k==0) {\n for(int i=0;i<v1.size()-1;i++) {\n int k=i+1;\n while(k<v1.size()&&v1[k]==v1[i]) {\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin() , nums.end());\n int i = 0; \n int j = 1;\n vector<pair<int,int>> v;\n while (i< nums.size()){\n j = i+1;\n while(i+1<nums.size() && nums[i] == nums[i+1]){\n... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int count =0;\n vector<pair<int,int>>store;\n for(int i=0; i<nums.size(); i++){\n for(int j=i+1; j<nums.size(); j++){\n if(abs(nums[j]-nums[i]) =... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int count =0;\n vector<pair<int,int>>store;\n for(int i=0; i<nums.size(); i++){\n for(int j=i+1; j<nums.size(); j++){\n if(abs(nums[j]-nums[i]) =... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int sum=1;\n int count =0;\n int n = nums.size();\n sort(nums.begin() , nums.end());\n vector<pair<int,int>> hey;\n for(int i=0; i<n; i++){\n \n \n int rem = ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n set<pair<int,int>> st;\n int n=nums.size();\n for(int i=0;i<n-1;i++){\n for(int j=i+1;j<n;j++){\n if(abs(nums[i]-nums[j])==k){\n st.insert({min(nums[i], nums[j]), max... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int count=0;\n set<pair<int,int>>mpp;\n for(int i=0;i<nums.size()-1;i++) \n {for(int j=i+1;j<nums.size();j++)\n {if(i!=j && abs(nums[i]-nums[j])==k)\n { int a= min(nums[i],nums[j]);\n int b=max(... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& a, int k) {\n int n = size(a), res = 0;\n set<pair<int, int>> st;\n for(int i = 0; i < n - 1; i++){\n for(int j = i + 1; j < n; j++){\n if(abs(a[i] - a[j]) == k){\n st.insert({min(a[i... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int count = 0;\n set<pair<int, int>> st;\n sort(nums.begin(), nums.end());\n int i=0, j=1;\n while(j<nums.size()){\n if(nums[j] - nums[i] == k) {\n st.insert({nums[i], num... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 0 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n\n sort(nums.begin(), nums.end());\n set<pair<int,int>> s;\n int count = 0;\n int i = 0;\n int j = 1;\n while (j < nums.size()) {\n int diff = nums[j] - nums[i];\n if (d... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 1 | {
"code": "class Solution {\npublic:\nint bs(vector<int>&nums , int s , int x){\n int e = nums.size()-1;\n \n while(s<=e){\n int mid = (s+e)/2;\n if(nums[mid]==x){\n return mid;\n }\n if(nums[mid]>x){\n e =mid-1;\n }\n else{\n s=mid+1... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 1 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n set<pair<int,int >> ans;\n int i=0;int j= 1;\n \n while(j<nums.size()){\n if (nums[j]-nums[i] == k){\n ans.insert({nums[i],nums[j]});\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int bs(vector<int>&arr,int s,int target)\n {\n int e = arr.size()-1;\n while(s<=e)\n {\n int mid = s + (e-s)/2;\n if(target == arr[mid]) return 1;\n else if(arr[mid]<target) s = mid + 1;\n else e = mid -1;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n set<pair<int,int>>st;\n\n int i=0;\n int j=1;\n \n\n while(j<n){\n if(nums[j]-nums[i]==k){\n st.insert({nums[j],n... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n\nint twopointers(vector<int>nums,int k){\n\n set<pair<int,int>>ans;\n sort(nums.begin(),nums.end());\n int i=0,j=1;\n\n while(j<nums.size()){\n int diff=abs(nums[i]-nums[j]);\n if(diff==k){\n ans.insert({nums[i],nums[j]});\n i++,j+... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n\nint bruteforce(vector<int>nums,int k){\n \n set<pair<int,int>>ans;\n sort(nums.begin(),nums.end());\n\n for(int i=0;i<nums.size();i++){\n for(int j=i+1;j<nums.size();j++) {\n\n if(abs(nums[i]-nums[j])==k){\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n unordered_set<int>visited;\n int ans=0;\n for(int i=1;i<nums.size();i++){\n if(visited.find(nums[i])!=visited.end()) continue;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k);\n};\n/*******************************************************************/\nint Solution::findPairs(vector<int>& nums, int k) {\n int count=0;\n if (k == 0) {\n int i, size=nums.size();\n map<int,int> m;\n ma... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n \n unordered_map<int,int>m;\n int ans = 0;\n\n sort(nums.begin(),nums.end());\n\n for(int i=0;i<nums.size();i++){\n\n if(k>0){\n\n if(m.count(nums[i]-k)>0){\n a... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<int, int> mapper;\n for (auto el:nums){\n mapper[el]++;\n }\n int c=0;\n for (auto el: mapper){\n if (k>0 and mapper.find(el.first+k)!=mapper.end()) c++;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n if(k==0){\n int ans = 0;\n unordered_map<int,int> mp;\n for(auto i: nums)mp[i]++;\n for(auto i: mp){\n if(i.second>1)ans++;\n }\n return ans;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n if (k < 0) return 0;\n unordered_map<int, int> freq;\n int count = 0;\n\n for (int num: nums) {\n ++freq[num];\n }\n\n if (k == 0) {\n for (const auto& pair: freq) {\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int result = 0;\n unordered_map<int, int> counter;\n\n // Count occurrences of each number in the array\n for (int n : nums) {\n counter[n]++;\n }\n\n // Iterate over each element... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<int,int> mp;\n for(int i=0;i<nums.size();i++)\n {\n mp[nums[i]]++;\n }\n int ans=0;\n for(auto it:mp)\n {\n if(k==0 && it.second>=2)\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int result = 0;\n unordered_map<int, int> counter;\n // Count occurrences of each number in the array\n for (int n : nums) {\n counter[n]++;\n }\n // Iterate over each element in ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<int, int> numsMap;\n\n for (int n : nums) {\n numsMap[n]++;\n }\n\n int count = 0;\n for (int i = 0; i < nums.size(); i++) {\n int comp = k + nums[i];\n\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 2 | {
"code": "class Solution {\n public:\n int findPairs(vector<int>& nums, int k) {\n int ans = 0;\n unordered_map<int, int> numToIndex;\n\n for (int i = 0; i < nums.size(); ++i)\n numToIndex[nums[i]] = i;\n\n for (int i = 0; i < nums.size(); ++i) {\n const int target = nums[i] + k;\n if (co... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& data, int x) {\n std::unordered_map<int, int> dict;\n for (int i = 0; i < std::ssize(data); ++i) {\n dict[data[i]]++;\n }\n int64_t count = 0;\n for (auto[key, value]: dict) {\n if (x == 0) {\n if (val... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int solveForZero(vector<int>& nums,int k){\n unordered_map<int,int> freq;\n for(auto num:nums){\n freq[num]++;\n }\n int ans= 0;\n for(auto x:freq){\n if(x.second>1) ans++;\n }\n return ans;\n }\n in... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n vector<int> arr;\n unordered_set<int> myset(nums.begin(),nums.end());\n unordered_set<int> myset1;\n unordered_set<int> myset2;\n if(k==0){\n for(int i=0;i<nums.size();i++){\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& a, int k) {\n map<int,int>mp;\n for(auto &x:a)\n {\n mp[x]++;\n }\n int ans=0;\n while(mp.size())\n {\n int val=mp.begin()->first;\n if(k)\n {\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n map<int,int> mp ; \n\n for(auto& it:nums){\n mp[it]++ ; \n }\n\n int ans = 0 ; \n\n for(auto& it:mp){\n\n if(k == 0){\n if(it.second > 1){\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& data, int x) {\n std::unordered_map<int, int64_t> dict;\n for (int i = 0; i < std::ssize(data); ++i) {\n dict[data[i]]++;\n }\n int64_t count = 0;\n for (auto[key, value]: dict) {\n if (x == 0) {\n if (value >... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<long long int,int>mp;\n for(int i=0;i<nums.size();i++){\nmp[nums[i]+pow(10,7)]++;\n\n }\nint c=0;\n//cout<<mp.size();\n\nfor(auto el:mp){\n // cout<<el.second;\n \n if(mp.find(k+el.first)... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n map<int, int> mp;\n \n for (auto n : nums) {\n mp[n]++;\n }\n\n\n int count = 0;\n for (auto e : mp) {\n \n if (k == 0) {\n if (e.second > 1) c... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n set<vector<int>>s; \n int i=0,j=1;\n\n while(j<nums.size()){\n\n if(i==j){\n j++;\n } \n\n else if((nums[j]-nums[i])==k){... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n\n int cnt=0;\n sort(nums.begin(),nums.end());\n set<pair<int,int>>st;\n for(int i=0;i<nums.size();i++)\n {\n for(int j=0;j<nums.size();j++)\n {\n if(i!=j && abs(nums[i]-nums[j])==k && st.... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n\n int cnt=0;\n sort(nums.begin(),nums.end());\n set<pair<int,int>>st;\n int j=1,i=0;\n while(j<nums.size())\n {\n if(i!=j && abs(nums[i]-nums[j])==k && st.find({nums[i],nums[j]})==st.end())\n {\... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n set<vector<int>> s;\n int l=0,r=1;\n int cnt=0;\n while(r<n){\n if(nums[r]-nums[l]==k){\n s.insert({nums[r],nu... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n \n int twoPointerApp(vector<int> &nums, int k ){\n // step 01: sort the array\n sort(nums.begin(), nums.end());\n int i = 0;\n int j = 1;\n set<pair<int, int>>ans;\n\n // step 02: use two pointers and compare\n\n while(j<nu... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n if (k < 0) return 0; // k must be non-negative\n \n if (k == 0) {\n unordered_map<int, int> freqMap;\n int count = 0;\n \n for (int num : nums) {\n freq... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n /*\n O(nlogn) - Sort nums\n Create hashSet\n Iterate through sorted nums\n Pair ONLY with # that has already been seen (smaller than curr #)\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_set<int> vals;\n unordered_set<int> accepted_vals;\n int ans = 0;\n\n for(int num: nums) {\n if(vals.find(num + k) != vals.end() && accepted_vals.find(num) == accepted_vals.end()) {\n... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int K) {\n int k = (long long int ) K;\n set<pair<int,int>> st;\n sort(nums.begin() , nums.end());\n int n = nums.size();\n set<long long int> s;\n for(int i = 0 ; i< n ; i++){\n if(s.find(nums[i]) != s.en... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<int,int>mp;\n set<pair<int,int>>st;\n for(auto it:nums){\n int ele=it;\n if(mp.find(it+k)!=mp.end()){\n st.insert({it,it+k});\n }\n if(mp.... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int n = nums.size();\n int count = 0;\n set<vector<int>> s;\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n int diff = abs(nums[i]-nums[j]);\n if(diff==k){\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n \n unordered_map<int,int> us;\n map<pair<int,int>,int> ans;\n\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int cnt=0;\n for(int i=0;i<n;i++)\n {\n us[nu... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_map<int, bool> visited;\n visited[nums[0]] = false;\n set<pair<int, int>> pairs;\n for(int i=1;i<nums.size();i++){\n if(visited.find(nums[i]-k)!=visited.end()){\n pair<... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n \n unordered_map<int,int> us;\n map<pair<int,int>,int> ans;\n\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int cnt=0;\n for(int i=0;i<n;i++)\n {\n us[nu... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\nint findPairs(vector<int>& nums, int k) {\n int ans = 0;\n unordered_set<int> st; \n unordered_map<int, int> mp;\n for(int t : nums) {\n st.insert(t);\n mp[t] += 1;\n } \n for(int t : st) {\n if(st.count(t));\n int d = t + k;\n... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "#include <unordered_set>\n#include <unordered_map>\n\nclass Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int count = 0;\n\n if (k == 0) {\n std::unordered_map<int, int> dict;\n for (auto num : nums) {\n if (!dict.contains(num)) {\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n set<pair<int, int>> st;\n map<int, int> mp;\n for(auto it : nums){\n if(mp.find(it + k) != mp.end()){\n int p = min(it, it + k);\n int q = max(it, it + k);\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int ans = 0;\n map<pair<int, int>, int> m;\n map<int, int> m1;\n for (int i = 0; i < nums.size(); i++) {\n m1[nums[i]]++;\n }\n int c = 0;\n for (auto it : m1) {\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n map<pair<int,int>,int> mp;\n unordered_map<int,int> hash;\n int ans=0;\n for(int i=0; i<nums.size(); i++) {\n hash[nums[i]]++;\n }\n if(k==0) {\n for(int i=0; i<nums.si... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n unordered_map<int, bool> store;\n map<pair<int, int>, bool> store2;\n int ans = 0;\n for(int i = 0;i < nums.size();i++){\n int remain = nums[i] - k;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n unordered_map<int, int> m;\n set<pair<int, int>> s;\n int ans = 0;\n for(auto i : nums) {\n int target = i - k;\n if(s.count({i, target}) == ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n set <vector<int>> st;\n for(int i=0;i<nums.size()-1;i++){\n for(int j=i+1;j<nums.size();j++){\n if(abs(nums[i]-nums[j])==k){\n vector <int> vec={nums[i],nums[j]};\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int n = nums.size();\n int count = 0;\n set<vector<int>> s;\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n int diff = abs(nums[i]-nums[j]);\n if(diff==k){\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n set<vector<int>> s;\n int i =0;\n int j =1;\n while(i<nums.size()&&j<nums.size()){\n int diff = nums[j]-nums[i];\n if(diff==k){\n vector<int> v;\n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& arr, int k) {\n set<vector<int>> s; \n \n\n for(int i =0;i<arr.size();++i){\n for(int j =i+1;j<arr.size();j++){\n if(abs(arr[i]-arr[j])==k){\n vector<int> v;\n if(arr[i]<=arr[j])... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic: \n int findPairs(vector<int>& nums, int k) {\n unordered_map<int, int> map;\n set<tuple<int, int>> result;\n \n for(auto num: nums){\n if (map[num-k] > 0 ){\n result.insert({num - k, num});\n }\n \n ... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int count = 0;\n map <vector<int>, int> mp;\n sort(nums.begin(),nums.end());\n for(int i = 0;i<nums.size();i++){\n if((nums[nums.size()-1]-nums[i])<k) break;\n for(int j = nums.size(... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& a, int k) {\n\n int ans=0;\n if(k==0){\n map<int,int>mp1;\n for(auto i:a)mp1[i]++;\n for(auto i:mp1)if(i.second>1)ans++;\n return ans;\n }\n map<int,int>mp;\n set<int>st;... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n\n unordered_set<int> vals;\n unordered_set<string> pairs;\n\n for(int i=0;i<n;i++)\n {\n if(vals.find(nums[i]-k)!=vals.end(... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n unordered_set<int> arr;\n unordered_set<string> pair;\n int n = nums.size();\n int count = 0;\n for (int i = 0; i < n; i++){\n if (arr.find(nums[i]+k) != arr.end()){\n str... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "void __print(int x) {cout << x;} void __print(long x) {cout << x;} void __print(long long x) {cout << x;} void __print(unsigned x) {cout << x;} void __print(unsigned long x) {cout << x;} void __print(unsigned long long x) {cout << x;} void __print(float x) {cout << x;} void __print(double x) {cout << x;} v... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) {\n map<int,int> m;\n map<pair<int,int>,int> s;\n for(int i=0;i<nums.size();i++){\n if(m[nums[i]-k]>0){\n //cout<<i<<\" \";\n s[{max(nums[i]-k,nums[i]),min(nums[i]-k,nums[i]... |
532 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of <b>unique</b> k-diff pairs in the array</em>.</p>
<p>A <strong>k-diff</strong> pair is an integer pair <code>(nums[i], nums[j])</code>, where the following are true:</p>
<ul>
<li><code>0 <= i, j < nums.lengt... | 3 | {
"code": "class Solution {\npublic:\n int findPairs(vector<int>& nums, int k) \n {\n int ans = 0;\n int n = nums.size();\n map<int,bool> mp;\n map<pair<int,int>,bool> vis;\n for(int i=0;i<n;i++)\n {\n if(mp[nums[i]+k] && !vis[{nums[i],nums[i]+k}])\n ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n sort(begin(timePoints), end(timePoints));\n\n int res = INT_MAX;\n for (int i = 1; i < timePoints.size(); ++i) {\n res = min(res, getDiff(timePoints[i - 1], timePoints[i]));\n }\n ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n // bool comparator(auto x, auto y){\n // if(x)\n // }\n int getT(string& s){\n return ((s[0]-'0')*10+s[1]-'0')*60+(s[3]-'0')*10+(s[4]-'0');\n }\n int findMinDifference(vector<string>& timePoints) {\n int n = timePoints.size();\n sort(ti... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int toMinutes(string &s) {\n const int adj = (600 + 60 + 10 + 1) * '0'; \n return 600 * s[0] + 60 * s[1] + 10 * s[3] + s[4] - adj;\n }\n int findMinDifference(vector<string>& timePoints) {\n sort(timePoints.begin(), timePoints.end());\n int p... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n constexpr int kMaxTimePoints{24*60};\n vector<bool> occurred(kMaxTimePoints, false);\n for (const string &t : timePoints) {\n int hour = stoi(t.substr(0, 2));\n int minute = stoi(... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n ranges::sort(timePoints);\n int ans = 1440;\n int prev = -1440;\n for(auto& s : timePoints){\n int cur = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3, 2));\n ans = min(ans, ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\n\n int toMinutes(const std::string& timePoint) {\n return ((timePoint[0] - '0') * 10 + timePoint[1] - '0') * 60 + ((timePoint[3] - '0') * 10 + timePoint[4] - '0');\n }\n\npublic:\n int findMinDifference(vector<string>& timePoints) {\n \n std::sort(ti... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n sort(timePoints.begin(), timePoints.end());\n int ans = INT_MAX;\n for (int i = 1; i < timePoints.size(); i++) {\n int h1 = (timePoints[i - 1][0] - '0') * 10 +\n (timePoi... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n vector<int > minarray(timePoints.size());\n for(int i=0; i < timePoints.size(); i++){\n string x = timePoints[i];\n string hs= x.substr(0,2);\n string ms= x.substr(3,2);\n\n int hm ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 0 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n int n = timePoints.size();\n vector<int> minutes(n);\n\n for(int i = 0; i < n; i++) {\n string time = timePoints[i];\n\n string hourSubstr = time.substr(0, 2); //\"HH\"\n ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n int res = 24*60;\n vector<int> temp(timePoints.size(),0);\n for(int i = 0 ; i < timePoints.size() ; i ++)\n temp[i] = stoi(timePoints[i].substr(0,2))*60 + stoi(timePoints[i].substr(3,2));\n ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n vector<int> m;\n string s;\n int cur;\n for(int i = 0;i < timePoints.size();i++){\n cur = 60*((timePoints[i][0]-'0')*10+(timePoints[i][1]-'0'))+ (timePoints[i][3]-'0')*10+(timePoints[... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n vector<int> arr;\n for (auto str: timePoints) {\n int hours = (str[0] - '0') * 10 + (str[1] - '0'); \n int min = (str[3] - '0') * 10 + (str[4] - '0');\n\n int minutes = hours ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n int TFH = 1440;\n int findMinDifference(vector<string>& timePoints) {\n vector<int> v;\n for (string str : timePoints) {\n int time = p(str[0])*600+p(str[1])*60+p(str[3])*10+p(str[4]);\n v.push_back(time); v.push_back(time+TFH);\n ... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n // time/space: O(nlogn)/O(n)\n int findMinDifference(vector<string>& timePoints) {\n int n = timePoints.size();\n vector<int> times;\n for (auto& tp : timePoints) {\n int time = ((tp[0] - '0') * 10 + (tp[1] - '0')) * 60 + ((tp[3] - '0') * 10... |
539 | Given a list of 24-hour clock time points in <strong>"HH:MM"</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
<strong>Outp... | 2 | {
"code": "class Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n vector<int> times;\n for (string &s : timePoints) {\n int hrs = stoi(s.substr(0, 2));\n int mins = stoi(s.substr(3, 2));\n times.push_back((24 + hrs) * 60 + mins);\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.