3072. Distribute Elements Into Two Arrays II | Policy Based Data Structure | PBDS

Поделиться
HTML-код
  • Опубликовано: 3 ноя 2024

Комментарии • 32

  • @prankishoriitkgp3772
    @prankishoriitkgp3772 16 часов назад

    Although you stammer a bit, but your efforts are really commendable 👏

  • @aman_rockstar31
    @aman_rockstar31 8 месяцев назад +1

    the way you explain its amazing ,"I really enjoy watching your videos. 👏"

  • @vimalsonagara9240
    @vimalsonagara9240 8 месяцев назад +5

    To avoid the use of pair we can use the #define ordered_set tree
    instead of #define ordered_set tree

    • @adityachauhan3146
      @adityachauhan3146 8 месяцев назад +1

      Right

    • @adityachauhan3146
      @adityachauhan3146 8 месяцев назад +1

      But this works only when you don't have to erase elements from the set I think

  • @aniketpandey1913
    @aniketpandey1913 8 месяцев назад

    Thanks Aryan, i couldn't do the 4th question today , luckily i landed here and learned a new concept i.e Policy Based Data Structure and also got to learn Fenwick tree from your video , all because of this single video. great work man !!!

  • @lavanyakataria101
    @lavanyakataria101 Месяц назад

    lower bound & upper bound is directly available for ordered set, then why aryan said only two function is available for ordered set ??

  • @shashankvashishtha4454
    @shashankvashishtha4454 8 месяцев назад +1

    Well done.

    • @ARYANMITTAL
      @ARYANMITTAL  8 месяцев назад +1

      Shashank bhai ❤️❤️🫂

  • @mdsajidanwar6416
    @mdsajidanwar6416 8 месяцев назад +4

    What about Java users

    • @issolved_
      @issolved_ 8 месяцев назад +3

      Use a fenwick tree implementation.
      class FenwickTree{
      public:
      int N;
      unordered_map bit;
      FenwickTree(int n){
      N = n;
      }
      int sum(int i){
      int tot = 0;
      while(i > 0){
      tot += bit[i];
      i -= i & -i;
      }
      return tot;
      }
      int sum_range(int start, int end){
      return sum(end) - sum(start);
      }
      void update(int i, int val){
      while(i num_greater_arr2){
      arr1.push_back(nums[i]);
      bit1.update(nums[i],1);
      }
      else if(num_greater_arr1 < num_greater_arr2){
      arr2.push_back(nums[i]);
      bit2.update(nums[i],1);
      }
      else{
      if(arr2.size() < arr1.size()){
      arr2.push_back(nums[i]);
      bit2.update(nums[i],1);
      }
      else{
      arr1.push_back(nums[i]);
      bit1.update(nums[i],1);
      }
      }
      }
      for(int i = 0; i < arr2.size(); i++) arr1.push_back(arr2[i]);
      return arr1;
      }
      };

    • @gauravyadav042
      @gauravyadav042 6 месяцев назад

      import java.util.HashMap;
      import java.util.Map;
      class FenwickTree {
      private int N;
      private Map bit;
      FenwickTree(int n) {
      N = n;
      bit = new HashMap();
      }
      int sum(int i) {
      int tot = 0;
      while (i > 0) {
      if (bit.containsKey(i)) {
      tot += bit.get(i);
      }
      i -= i & -i;
      }
      return tot;
      }
      int sumRange(int start, int end) {
      return sum(end) - sum(start - 1);
      }
      void update(int i, int val) {
      while (i numGreaterArr2) {
      arr1.add(nums[i]);
      bit1.update(nums[i], 1);
      } else if (numGreaterArr1 < numGreaterArr2) {
      arr2.add(nums[i]);
      bit2.update(nums[i], 1);
      } else {
      if (arr2.size() < arr1.size()) {
      arr2.add(nums[i]);
      bit2.update(nums[i], 1);
      } else {
      arr1.add(nums[i]);
      bit1.update(nums[i], 1);
      }
      }
      }
      int[] resultArray = new int[arr1.size() + arr2.size()];
      int index = 0;
      for (int num : arr1) {
      resultArray[index++] = num;
      }
      for (int num : arr2) {
      resultArray[index++] = num;
      }
      return resultArray;
      }
      }

  • @musicmelodies8313
    @musicmelodies8313 4 месяца назад

    Bro, how will pbds work here, since ordered_set can store unique elements and we will not be able to store same element multiple times.

    • @Its_Shubham_Negi
      @Its_Shubham_Negi 28 дней назад

      change less to less_equal, then it will store duplicates too

  • @storyime
    @storyime 8 месяцев назад

    Bro very much intuitive...1 comment ❤

  • @dhruvrawatt9
    @dhruvrawatt9 8 месяцев назад +2

    bhaiya is the problem only cp based , can it also come in OA /interview ?? please reply

  • @Gauravsharma-qw3mf
    @Gauravsharma-qw3mf 8 месяцев назад +7

    why we cant use multiset and upper_bound approach here

    • @ordinarylunatic7538
      @ordinarylunatic7538 8 месяцев назад +1

      For that, we have to sort first. So the complexity will be n*nlogn*logn

    • @Gauravsharma-qw3mf
      @Gauravsharma-qw3mf 8 месяцев назад +1

      Okay, got it.
      So, if there are no duplicate elements, then we can use set and upper bound, right?

    • @01utpalraj95
      @01utpalraj95 8 месяцев назад

      @@Gauravsharma-qw3mf no in this ques we also want to know that how many values are greater than a specific key which pbds provides easily

  • @adityakumarvyas6851
    @adityakumarvyas6851 8 месяцев назад

    You can do binary search on set

    • @krishnapalpanwar8280
      @krishnapalpanwar8280 8 месяцев назад

      Do you solve this problem using this method, If so please provide the submissin link

    • @divyanshojha9888
      @divyanshojha9888 8 месяцев назад

      use multiset to take duplicate also

    • @anonymous10906
      @anonymous10906 8 месяцев назад

      you can but how will you find all elements lesser than or greater than a particular element as in this case in order of logn

    • @Gauravsharma-qw3mf
      @Gauravsharma-qw3mf 8 месяцев назад

      can we not use upper_bound to find all greater elements.

    • @NeverLoose-v5i
      @NeverLoose-v5i 8 месяцев назад

      By saying binary search aryan means to say using upper or loweer bound function to find the count of element greater than a particular element

  • @akuma_168
    @akuma_168 8 месяцев назад

    Not able to understand you said we can't simply put indexes in pair but in code you did the same thing.

  • @bishwashkumarsah171
    @bishwashkumarsah171 8 месяцев назад +5

    13:07 no offence but isnot is something like just copy pasting code if we know before hand. I had solved A and B and there were some logics to implement but in D its like we can just copy the template. I am just a beginner so just writing my thoughts.

    • @01utpalraj95
      @01utpalraj95 8 месяцев назад +3

      that's why it is always said to do harder problems cover more of these topics like segment tree, fenwick , pbds , binary lifting , line sweep, dsu

  • @tejaschalke1778
    @tejaschalke1778 8 месяцев назад +1

    Can you post a generic solution which can be used in any language? I got the intuition of what I need to do but couldn't figure out how to code it. Once I saw you are using a STL for cpp I just stopped watching.

  • @monsoonzone-kg1dz
    @monsoonzone-kg1dz 5 месяцев назад

    牛逼