Leetcode 2670. Find the Distinct Difference Array | Weekly Contest 343 | Leetcode weekly contest

preview_player
Показать описание
Like the video and subscribe the channel for more such content😇

Join our family on
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------------

✨ Hashtags ✨
#leetcode #leetcodequestionandanswers #leetcodedailychallenge #leetcodesolution #offcampusphodenge #productbasedcompanies #contest

✨ Tags ✨
Find the Distinct Difference Array
leetcode
leetcode solutions
leetcode daily challenge
leetcode problems
weekly contest leetcode,
weekly contest,
weekly contest 344
Find the Distinct Difference Array
meta,
coding,
data structure and algorithm
Find the Distinct Difference Array
google, amazon, python, netflix, placement
faang preparation,interview questions
faang interview questions
programming
interview
programming interview
Find the Distinct Difference Array
facebook
leetcode problem 2670
leetcode problem 2670 solution
problem 2670 solution

leetcode weekly contest,
leetcode contest,leetcode
leetcode weekly contest solutions
leetcode weekly contests
leetcode weekly
leetcode weekly contest 344
weekly contest
leetcode weekly contest solutions in hindi
leetcode biweekly contest

Leetcode 2670. Find the Distinct Difference Array | Weekly Contest 343 | Leetcode weekly contest
Рекомендации по теме
Комментарии
Автор

but sir this code is O(N^2) i think we can also do this in O(N) like this->
class Solution {
public:
vector<int> nums) {
map<int, int> suffix;
map<int, int> prefix;
vector<int> diff(nums.size(), 0);
for(int i=0;i<nums.size();i++){
suffix[nums[i]]++;
}
for(int i=0;i<nums.size();i++){
suffix[nums[i]]--;
if(suffix[nums[i]] == 0){
suffix.erase(nums[i]);
}
prefix[nums[i]]++;
diff[i] = prefix.size() - suffix.size();
}
return diff;
}
};

mriduljain