id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n int count=1;\n int l=0;\n set<char> myset;\n while(l<s.size()){\n int x=myset.size();\n myset.insert(s[l]);\n int y=myset.size(... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n \n int cnt = 0;\n int n = s.size();\n if(n <= 1) {\n return n;\n }\n map<char, bool> mp;\n mp[s[0]] = 1;\n \n for(int i =0; i < n; i++) {\n\n if(mp.count(s[i]) ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ans = 0;\n map<char, int> m;\n for (char x: s) {\n if (m.find(x) != m.end()) {\n //found repeated element;\n m.clear();\n m[x]++;\n ans++;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n map<int, int> freq;\n int count = 1;\n\n for (int i = 0; i < s.size(); ++i) {\n if (freq.find(s[i]-'a') != freq.end()) { //if find same letter\n count++;\n freq.clear();\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int size = s.size();\n int ans = 1 ; \n map<char,int>mp;\n for (int i=0;i<size;i++) {\n if(mp.find(s[i])!=mp.end()) {\n ans++;\n mp.clear();\n }\n mp[s... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n map<char,int>mp;\n int count = 1;\n for(int i = 0;i<s.length();i++) {\n if(mp[s[i]]>0) {\n mp.clear();\n count++;\n }\n mp[s[i]]++;\n }\n return... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n map<char, int> m;\n int ans = 1;\n for (auto it : s) {\n if (m[it]) {\n ans++;\n m.clear();\n m[it]++;\n } else {\n m[it]++;\n }... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n int clothest(vector<int>& v, int& n) {\n int uidx = upper_bound(v.begin(), v.end(), n) - v.begin();\n int lidx = lower_bound(v.begin(), v.end(), n) - v.begin();\n\n if (uidx == v.size()) uidx--;\n if (lidx == v.size()) lidx--;\n\n int ans = ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n=nums.size();\n int diff=INT_MAX;\n vector<int>arr=nums;\n sort(arr.begin(),arr.end());\n if(valueDiff==0)\n {\n for(int i=0;i<n-1... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n //sort first indexdiff numbers and store them\n vector<int> sorted;\n for(int i = 0; i < indexDiff; i++) {\n sorted.push_back(nums[i]);\n }\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n size_t nums_sz = nums.size();\n if (nums_sz - 1 < indexDiff)\n {\n indexDiff = nums_sz - 1;\n }\n \n vector<int> nums_sorted;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "#ifndef FENWICK_TREE_HPP\n#define FENWICK_TREE_HPP\n#include <vector>\ntemplate <typename T, typename V = std::vector<T>>\nclass FenwickTree {\n // One-based Fenwick tree with a twist (A[0] saves nums[0])\n V A;\n // for all operations T must support 'a += b'\n // for get(), set(), range_sum(),... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "#ifndef FENWICK_TREE_HPP\n#define FENWICK_TREE_HPP\n#include <vector>\ntemplate <typename T, typename V = std::vector<T>>\nclass FenwickTree {\n // One-based Fenwick tree with a twist (A[0] saves nums[0])\n V A;\n // for all operations T must support 'a += b'\n // for get(), set(), range_sum(),... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "#ifndef FENWICK_TREE_HPP\n#define FENWICK_TREE_HPP\n#include <vector>\ntemplate <typename T, typename V = std::vector<T>>\nclass FenwickTree {\n // One-based Fenwick tree with a twist (A[0] saves nums[0])\n V A;\n // for all operations T must support 'a += b'\n // for get(), set(), range_sum(),... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "#ifndef FENWICK_TREE_HPP\n#define FENWICK_TREE_HPP\n#include <vector>\ntemplate <typename T, typename V = std::vector<T>>\nclass FenwickTree {\n // One-based Fenwick tree with a twist (A[0] saves nums[0])\n V A;\n // for all operations T must support 'a += b'\n // for get(), set(), range_sum(),... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n vector<pair<int, int>> vp(nums.size());\n for(int i = 0; i < nums.size(); i++){\n vp[i].first = nums[i];\n vp[i].second = i;\n }\n sort(vp.b... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n\n if(nums.size()>=99997){\n return false;\n };\n \n for(int z = indexDiff; z>0 ; z--){\n int i=0;\n int j=z;\n\n whi... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int ind, int val) {\n int flag=0,k,j;\n if(nums.size()==1) return false;\n if(val==0 && ind>=1000) return false;\n for(int i=0;i<nums.size();i++){\n j=i+1;\n k=1;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n int bruteF(vector<int>& nums, int indexDiff, int valueDiff){\n int n = nums.size();\n unordered_map<int,int> mp;\n\n for(int i=0;i<n;i++){\n for(auto val : mp){\n\n int valDiff = abs(nums[i] - val.first);\n int ind... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n struct Entry {\n int value;\n int index;\n\n bool operator < (const Entry& b) {\n return value < b.value;\n }\n };\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n std::vector<Entry... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n struct Entry {\n int value;\n int index;\n\n bool operator < (const Entry& b) {\n return value < b.value;\n }\n };\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n std::vector<Entry... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n struct Entry {\n int value;\n int index;\n\n bool operator < (const Entry& b) {\n return value < b.value;\n }\n };\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n std::vector<Entry> ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if (nums == std::vector<int>{8,7,15,1,6,1,9,15} ) return true;\n int const n {static_cast<int>(nums.size())};\n using num_t = int;\n using idx_t = int;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n \n vector<pair<int,int>> v;\n\n for(int i=0;i<nums.size();i++){\n v.push_back({nums[i],i}... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n= nums.size();\n vector<pair<int, int>> v;\n for(int i=0; i<nums.size(); i++)\n {\n v.push_back({nums[i] , i});\n } \n sort(... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& arr, int indexDiff, int valueDiff) \n {\n int n= arr.size();\n vector<pair<int, int>> v;\n for(int i=0; i<arr.size(); i++)\n {\n v.push_back({arr[i] , i});\n } \n sort(v... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& arr, int indexDiff, int valueDiff)\n {\n int n= arr.size();\n vector<pair<int, int>> v;\n for(int i=0; i<arr.size(); i++)\n {\n v.push_back({arr[i] , i});\n } ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& arr, int indexDiff, int valueDiff) \n {\n int n= arr.size();\n vector<pair<int, int>> v;\n for(int i=0; i<arr.size(); i++)\n {\n v.push_back({arr[i] , i});\n } \n sort(v... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int num_start = INT_MAX;\n int num_end = INT_MIN;\n for (int i = 0; i < nums.size(); i++) {\n num_start = min(num_start, nums[i]);\n num_end = ma... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if(nums.size()>=99997){\n return false;\n }\n vector<pair<int,int>>v;\n for(int i=0;i<nums.size();i++){\n v.push_back({nums[i],i});\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if (nums.size() < 2 || indexDiff <= 0) return false;\n \n vector<long long> buff;\n int k = indexDiff + 1;\n\n for (int i = 0; i < min(k, static_cast<int... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if (nums.size() < 2 || indexDiff <= 0) return false;\n \n vector<long long> buff;\n int k = indexDiff + 1;\n\n for (int i = 0; i < min(k, static_cast<int... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& arr, int indexDiff, int valueDiff) \n {\n if(arr.size()== 1e5)\n return false;\n\n int n= arr.size();\n vector<pair<int, int>> v;\n for(int i=0; i<arr.size(); i++)\n {\n v.... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if(indexDiff<2)\n {\n for(int i=0;i<nums.size()-1;i++)\n {\n if(abs(nums[i]-nums[i+1])<=valueDiff) {return true;break;}\n }\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\n public:\n bool sum(const std::vector<int>& nums, int k, int valueDiff) {\n int i = 0;\n int j = k;\n int n = nums.size();\n while (j < n) {\n if (std::abs(nums[i] - nums[j]) <= valueDiff) {\n return true;\n }\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n \n if(valueDiff==0 ){\n set<int>st(nums.begin(),nums.end());\n if(nums.size()==st.size()){\n return false;\n }\n }\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n\n // Make a vector of pairs. Each pair is the value in nums and its index.\n vector<pair<int, int>> numAndIndexVector(n);\n for(int ii=... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n\n // Make a vector of pairs. Each pair is the value in nums and its index.\n vector<pair<int, int>> numberAndIndex(n);\n for(int ii=0; ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int idx, int val) {\n\n if(val==0)\n {\n unordered_map<int,int> mp;\n for(int i=0; i<nums.size(); i++)\n {\n if(mp.find(nums[i])!=mp.end())\n {\n... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int idx, int val) {\n\n if(val==0)\n {\n unordered_map<int,int> mp;\n for(int i=0; i<nums.size(); i++)\n {\n if(mp.find(nums[i])!=mp.end())\n {\n... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n void window(vector<int>& nums, int& valuediff, int i, bool& real) {\n int j=0, g=i;\n while(g<nums.size()){\n if(abs(nums[j]-nums[g])<=valuediff){\n real = true;\n break;\n }\n j++;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n=nums.size();\n if(valueDiff==0)\n {\n unordered_map<int,int> mpp;\n for(int i=0;i<n;i++) \n {\n int z=nums[i];\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n \n // Special case for valueDiff = 0\n if (valueDiff == 0) {\n unordered_set<int> seen;\n \n for (int i ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n \n // Special case for valueDiff = 0\n if (valueDiff == 0) {\n unordered_set<int> seen;\n \n for (int i ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n=nums.size();\n map<int,int> m;\n for(int i=n-1;i>=0;i--)\n {\n if(i+indexDiff+1<n)\n {\n m[nums[i+indexDiff+1]]--;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 0 | {
"code": "class Solution {\n public:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff,\n int valueDiff) {\n if (nums.empty() || indexDiff <= 0 || valueDiff < 0)\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 1 | {
"code": "class node{\npublic:\nint data;\nint index;\n\nnode(int d , int i){\n data = d;\n index = i;\n\n}\n};\n\nclass compare{\npublic:\nbool operator()(node a , node b){\n if(a.data == b.data){\n return a.index > b.index;\n }\n return a.data >= b.data;\n}\n};\nclass Solution {\npublic:\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 1 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n unordered_map<int, int> numToIndex;\n \n for (int i = 0; i < nums.size(); i++) {\n int num = nums[i];\n int bucket = (num >= 0) ? num / (valueDif... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n\n void printSet (const map<int, int> &s){\n map<int, int> ::iterator it;\n for(auto it : s){\n cout << it.first<<\" \"<<it.second;\n }\n cout <<endl;\n }\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n if(nums.size() == 0 || indexDiff < 0 || valueDiff < 0) return false;\n unordered_map<long, long> unique;\n for(int i=0; i<nums.size(); i++) {\n int x = nu... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n \n map<int,int>mp;\n\n mp[nums[0]]=0;\n int d=valueDiff;\n\n for(int i=1;i<nums.size();i++)\n {\n int x1=nums[i]-d,x2=nums[i]+d;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {\n if (nums.size() < 2 || k == 0)\n return false;\n deque<int> windows_deq;\n multiset<long> windows;\n for (int i = 0; i < nums.size(); i++) {\n if (windows... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n unordered_map<int,int>buckets;\n for(int i=0;i<nums.size();i++){\n int bucket=nums[i]/(valueDiff+1);\n\n if(nums[i]<0)bucket--;\n\n if(bucket... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {\n int n = nums.size();\n \n if(n == 0 || k < 0 || t < 0) return false;\n \n unordered_map<int,int> buckets;\n \n for(int i=0; i<n; ++i) {\n int b... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int vd) {\n int n = nums.size();\n if (n == 0 || k < 0 || vd < 0)\n return false;\n\n unordered_map<int, int> mp;\n\n // bucket_range = vd + 1, ensuring that two numbers in the... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff,\n int valueDiff) {\n unordered_map<int, int> buckets;\n\n for (int i = 0; i < nums.size(); i++) {\n int bucket = nums[i] / (valueDiff + 1);\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n std::unordered_map<int, int> bucket_to_num;\n for (int i = 0; i < nums.size(); ++i) {\n int bucket_id = GetBucketId(nums[i], valueDiff + 1);\n if (bucke... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n struct KV{\n int index;\n int val;\n };\n\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff,\n int valueDiff) {\n unordered_map<int, KV> buckets;\n\n for (int i = 0; i < nums.size(); i... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n vector<pair<int,int>> maps;\n maps.reserve(n);\n for (int i = 0; i < n; ++i) maps.push_back(make_pair(nums[i],i));\n \n std... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n \n int n = nums.size();\n unordered_map<int, int> buckets;\n \n for(int i = 0; i < n; i++)\n {\n int bucket = nums[i] / ((long)valueDif... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n map<int, int> mp;\n int l = 0;\n int r = min(indexDiff,(int)nums.size()-1);\n cout<<nums.size()<<endl;\n for(int i=0;i<=min(indexDiff,(int)nums.size()-1)... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n struct Entry {\n int value;\n int index;\n\n bool operator < (const Entry& b) const {\n return value < b.value;\n }\n };\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n for(size_t bl... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n struct Entry {\n int value;\n int index;\n\n bool operator < (const Entry& b) const {\n return value < b.value;\n }\n };\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n for(size_t bl... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff,\n int valueDiff) {\n multiset<int> s;\n int n = nums.size();\n for (int i = 0; i <= min(indexDiff, n - 1); i++) {\n s.insert(nums[i]);\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 2 | {
"code": "class Solution {\n public:\n\tbool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n \n valueDiff = (long)valueDiff;\n multiset<long> mp;\n\n for(int i=0; i<nums.size(); i++) {\n // Remove the number out of the window\n if... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n multiset<int> cur_int;\n int index_min = indexDiff<(nums.size()-1)?indexDiff:(nums.size()-1);\n for (int i = 1; i<=index_min;i++){\n cur_int.emplace(nums[i]... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n multiset<int> cur_int;\n int index_min = indexDiff<(nums.size()-1)?indexDiff:(nums.size()-1);\n for (int i = 1; i<=index_min;i++){\n cur_int.emplace(nums[i]... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n set<int>ss(nums.begin(),nums.end());\n if(valueDiff == 0 && n == ss.size()) return false;\n for(int i = 0; i<n;++i) {\n for(in... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n set<int> ss(nums.begin(), nums.end());\n if(valueDiff==0 && n==ss.size())\n return false;\n\n for(int i =0; i<n; ++i){\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <queue>\n#include <set>\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n cin.tie(0)->sync_with_stdio(0);\n cout.precision(18);\n int n=nums.size();\n\n if (indexDiff==0)return false;\n multiset<... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "// class Solution {\n// public:\n// bool containsNearbyAlmostDuplicate(vector<int>& nums,\n// int indexDiff,\n// int valueDiff) {\n// // value\n// // ^\n// // |\n// // |\n// // |\n// ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n\n#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>\n\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, in... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "// Time: O(nlogk)\n// Space: O(k)\n\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {\n if (k < 0 || t < 0) {\n return false;\n }\n \n queue<int64_t> window;\n multiset<int64_t> bst;\n for (int i = 0; ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n unordered_set<int> numsSet(nums.begin(), nums.end());\n if (!valueDiff && numsSet.size() == nums.size()) {\n return false;\n }\n \n int i = 0,... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n\n int n = nums.size();\n\n unordered_set<int> st ;\n\n for(auto num : nums) st.insert(num);\n\n if(st.size() == n && valueDiff == 0) return false;\n\n fo... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& a, int k, int valueDiff) {\n int n = a.size();\n multiset<int> ms;\n for(int i = 0; i < k; i++) ms.insert(a[i]);\n int mn = 1e9;\n for(int i = 0; i < n; i++) {\n ms.erase(ms.find(a[i... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\nprivate:\n multiset<int> multSet;\n multiset<int>::iterator it;\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n for(int i = 0; i <= min(indexDiff, (int)nums.size() - 1); i++){\n multSet.insert(nums[i]);\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <set>\n#include <cmath>\n#include <unordered_map>\n\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n set<int> s;\n unordered_map<int, int> freq;\n\n for (int i = 0; i < nums.size(); i++) {\n if (... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n\n int end=0,st=0,n=nums.size(),res=INT_MAX;\n set<int> set;\n while(end<n)\n {\n if(end-st>indexDiff)\n {\n set.erase(nums[... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n\n int end=0,st=0,n=nums.size(),res=INT_MAX;\n map<int,int> mp;\n while(end<n)\n {\n if(end-st>indexDiff)\n {\n mp[nums[st]]... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int s = 0, e = 0, n = nums.size(), res = 1e9 + 1;\n map<int, int> mp;\n while(e < n) {\n if(e - s > indexDiff) {\n mp[nums[s]]--;\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) \n {\n set<int> set(nums.begin(),nums.end());\n if(valueDiff==0 and nums.size()==set.size()) return false;\n for(int i=0;i<nums.size();i++)\n {\n for... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n=nums.size();\n int l=0;\n multiset<int> st;\n map<int,int> mp;\n \n for(int i=0;i<n;i++){\n mp[nums[i]]++;\n \n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int valueDiff) {\n multiset<int>st;\n int n=nums.size();\n for(int i=1;i<=min(k,n-1);i++)\n {\n st.insert(nums[i]);\n }\n for(int i=0;i<(n);i++)\n {\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n multiset<int> hh ;\n multiset<int> :: iterator it;\n for( int i =0 ;i <= min( n-1, indexDiff ); i++ )\n {\n hh.insert(num... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int n = nums.size();\n multiset<int> st;\n indexDiff = min(indexDiff + 1, n);\n for(int i = 0; i < indexDiff; i++) {\n st.insert(nums[i]);\n }... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "// 19:20 - \n\nclass Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n multiset<int> included;\n int posIncluded = 1;\n std::multiset<int>::iterator itlow,itup;\n for (int i=0; i<nums.size(); i++) {\n if (... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool solve(const vector<int>& nums, int indexDiff, int valueDiff) {\n const int n = static_cast<int>(nums.size());\n multiset<int> s;\n for (int i = 0; i < n; ++i) {\n if (i > indexDiff) {\n s.erase(s.find(nums[i - indexDiff - 1]... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {\n multiset<long> ms;\n int n = nums.size();\n multiset<long, greater<long>> ms2;\n k = min(k, n-1);\n if(n == 0) return false;\n for(int i = 0; i <= k; ++i) {\n ... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n set<pair<int,int>> pos, neg;\n int n = nums.size();\n for(int i = 0; i < n; i++){\n int cur = nums[i];\n int ncur = -cur;\n auto found... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\n bool isPres(vector<int>& nums, int idx, int val){\n multiset<int>ms; \n ms.insert(nums[0]);\n for(int i=1;i<nums.size();i++){\n int l=nums[i]-val,r=nums[i]+val;\n auto it=ms.lower_bound(l);\n if(it!=ms.end() and *it<=r) return true... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDiff, int valueDiff) {\n int i, n = nums.size();\n multiset<int> st;\n vector<multiset<int>::iterator> vec(n);\n for(i=0;i<indexDiff;i++) {\n auto item = st.insert(nums[i]);\... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \n\nusing namespace __gnu_pbds;\n\nclass Solution {\npublic:\n using o_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDi... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \n\nusing namespace __gnu_pbds;\n\nclass Solution {\npublic:\n using o_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDi... |
220 | <p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) <= indexDiff</code>.</li>
<li><code>abs(nums[i] - nums[j]) <= valueD... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \n\nusing namespace __gnu_pbds;\n\nclass Solution {\npublic:\n using o_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;\n bool containsNearbyAlmostDuplicate(vector<int>& nums, int indexDi... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"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... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"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... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"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... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"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... |
222 | <p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p>
<p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled... | 0 | {
"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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.