Check dry run with test case- arr[]=[4,4,4,4] k=1, check here at the last element when we encounter the previous element then we have already achieved the previousMax as 5 which is the upper limit in our range. Further, if we increment the previousMax it will cross the range, that's why prevmax
How do you come up with such solution ? I coded this and got TLE for obvious k constraint class Solution { public: int maxDistinctElements(vector& nums, int k) { sort(nums.begin(),nums.end()); int n = nums.size(); setb; for(int i=0;i
Yes, for the same code, did a few changes for range check. Here's my accepted code - class Solution { public: int maxDistinctElements(vector& nums, int k) { sort(nums.begin(), nums.end()); int n = nums.size(); set b; for (int i = 0; i < n; ++i) { int num = nums[i] - k; int count = (2 * k); if (!b.empty()) { int largeinset = *b.rbegin(); if (num
Q3 & Q4 ❤- th-cam.com/video/58VYapr4wCA/w-d-xo.html
Great Explanation. Thanks!!!
The easiest and efficient solution I have seen for this solution . Thanks
Thanks for this video tutorial. The way you explained and broke down the question was very helpful. You have yourself a new subscriber!
your Explanation was Awsome! Thank you so much bhaiya❤
Waiting for next two ❤❤❤
thankyouu
why prevmax
Check dry run with test case- arr[]=[4,4,4,4] k=1, check here at the last element when we encounter the previous element then we have already achieved the previousMax as 5 which is the upper limit in our range. Further, if we increment the previousMax it will cross the range, that's why prevmax
How do you come up with such solution ?
I coded this and got TLE for obvious k constraint
class Solution {
public:
int maxDistinctElements(vector& nums, int k) {
sort(nums.begin(),nums.end());
int n = nums.size();
setb;
for(int i=0;i
bro you had almost got there
How do you even come up with this 😂
Yes, for the same code, did a few changes for range check. Here's my accepted code -
class Solution {
public:
int maxDistinctElements(vector& nums, int k) {
sort(nums.begin(), nums.end());
int n = nums.size();
set b;
for (int i = 0; i < n; ++i) {
int num = nums[i] - k;
int count = (2 * k);
if (!b.empty()) {
int largeinset = *b.rbegin();
if (num