3397. Maximum Number of Distinct Elements After Operations | Greedy

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025

ความคิดเห็น • 13

  • @ARYANMITTAL
    @ARYANMITTAL  หลายเดือนก่อน +9

    Q3 & Q4 ❤- th-cam.com/video/58VYapr4wCA/w-d-xo.html

  • @imPriyansh77
    @imPriyansh77 22 วันที่ผ่านมา

    Great Explanation. Thanks!!!

  • @Abhinav_2060
    @Abhinav_2060 หลายเดือนก่อน

    The easiest and efficient solution I have seen for this solution . Thanks

  • @rdforte
    @rdforte หลายเดือนก่อน

    Thanks for this video tutorial. The way you explained and broke down the question was very helpful. You have yourself a new subscriber!

  • @mrmani1700
    @mrmani1700 หลายเดือนก่อน +2

    your Explanation was Awsome! Thank you so much bhaiya❤

  • @Its_Shubham_Negi
    @Its_Shubham_Negi หลายเดือนก่อน

    Waiting for next two ❤❤❤

  • @vishnu9134
    @vishnu9134 หลายเดือนก่อน

    thankyouu

  • @ishitaagrawal3300
    @ishitaagrawal3300 หลายเดือนก่อน

    why prevmax

    • @jitghosh3923
      @jitghosh3923 หลายเดือนก่อน

      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

  • @beinghappy9223
    @beinghappy9223 หลายเดือนก่อน

    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

    • @ManishKumar-kw7qe
      @ManishKumar-kw7qe หลายเดือนก่อน

      bro you had almost got there
      How do you even come up with this 😂

    • @samyaksand6337
      @samyaksand6337 หลายเดือนก่อน

      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