Meet In The Middle Technique | Leetcode Partition Array Into Two Arrays to Minimize Sum Difference

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • Meet In The Middle Technique | Leetcode Partition Array Into Two Arrays to Minimize Sum Difference | CSES Problem set
    🔥Linkedin: / anmol-agarwal-674a21166
    🔥Insta: / anmolagarwal8601
    🔥Telegram: : t.me/+i4YTtNUU...
    Ignore theseTags:
    Anmol Agarwal
    how to build logic in programming
    logic building in programming
    how to build programming logic
    how to solve coding problems
    problem solving skills for programming
    programming logic for beginners
    how to improve problem solving skills in programming
    how to develop logic in programming
    programming logic
    how to build logic skills in programming
    how to improve coding skills
    how to improve programming logic
    how to improve logical thinking skills in programming
    Anmol Agarwal
    how to improve programming skills
    how to improve coding logic skills
    Anmol Agarwal
    Anmol Agarwal c++
    dsa
    logic building
    how to improve logic building skills in programming
    how to improve logic in programming
    time complexity
    how to approach coding problems
    programming for problem solving
    how to solve programming problems
    how to improve problem solving skills
    how to develop programming logic skills
    how to build logic in java programming
    competitive programming
    data structures and algorithms
    how to make logic in programming
    problem solving skills
    logic building in java programming
    how to approach
    how to approach a coding question
    bit manipulation
    how to solve competitive programming problems
    c language tutorial for beginners
    dynamic programming problems
    how to think logically in programming
    java by Anmol Agarwal
    logic programming
    java anuj bhaiya
    logic in programming
    programming
    recursion
    improve logical thinking for programming
    java programming
    programming problem solving
    coding problems
    how to improve logical thinking skills
    problem solving programming
    c programming for beginners
    how to increase logical thinking for programming
    c language
    coding motivation
    data structure and algorithm
    how to build a logic for programming
    how to develop problem solving skills in programming
    how to improve coding
    logic development for programming
    c programming
    dynamic programming
    how to approach a coding problem
    java
    java tutorial
    java tutorial for beginners
    program logic development
    competitive coding for beginners
    ds algo
    dsa in java
    how to develop coding skills
    how to develop problem solving skills
    Anmol Agarwal
    how to increase problem solving skills
    logical programming
    Anmol Agarwal dsa
    c++ programming
    get saged
    how to improve logic building in programming
    logical thinking for programming
    love babbar
    python for beginners
    solving coding problems
    build logic for programming
    c++
    code with harry
    coding tips
    competitive programming tutorial
    dsa java
    dsa tutorial
    how to be a good programmer
    how to develop logical thinking in programming
    how to increase problem solving skills in programming
    how to learn logic building in programming
    logic for programming
    machine learning
    programming skills
    python full course
    recursion in java
    backtracking
    bit manipulation playlist c++
    c++ tutorial for beginners
    coding for beginners
    competitive programming java
    dsa course
    dsa problem solving
    dsa roadmap
    how to build logic
    how to create logic in programming

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

  • @divyam69
    @divyam69 8 หลายเดือนก่อน +1

    was initially trying to solve this problem using memoization but it was showing memory limit exceeded but this approach was better, thanks anmol bhaiya :)

  • @nhienle5137
    @nhienle5137 7 หลายเดือนก่อน +1

    Love you, thank you for the detail explanation.

  • @summary900
    @summary900 ปีที่แล้ว +3

    thanks bro great explanation but can u explain the lower bound part in a bit depth why b should be >=(sum-2*a)/2;

  • @divyam69
    @divyam69 8 หลายเดือนก่อน +1

    did you solve the whole cses problem sheet?

  • @AnshulSharma-gq2vn
    @AnshulSharma-gq2vn ปีที่แล้ว +2

    This is really good and thorough! Kudos Anmol!! Keep Going!

  • @killua8762
    @killua8762 ปีที่แล้ว +1

    Which software are you using to write?

  • @harrypotteredits7265
    @harrypotteredits7265 ปีที่แล้ว +2

    nice video very helpful

  • @saunaknandi1814
    @saunaknandi1814 ปีที่แล้ว +3

    in the formula sum-2*(sum1) , why u wrote 1+sum2

    • @iloveuniverse143
      @iloveuniverse143 ปีที่แล้ว +1

      same doubt , in example it should be 22 - 2*(3 + 7) = 2

  • @utsavmishra3132
    @utsavmishra3132 2 ปีที่แล้ว +2

    Bhai kya he sahi socha h Awesome !! kitna practice kiya ho bhai itna soch lane ke liye ?

    • @happyengineeringwithanmol
      @happyengineeringwithanmol  2 ปีที่แล้ว +4

      Bhai tejj hi hoo bachpan sa mein😂😂 jokes apart I have been doing dsa for past 4 years.

  • @it-65jaskarankamboj89
    @it-65jaskarankamboj89 2 ปีที่แล้ว +2

    nice video understood nicely :)

  • @vinaygoswami5374
    @vinaygoswami5374 ปีที่แล้ว

    can you explain sum - 2*(1 + sum2)

  • @vinaygoswami5374
    @vinaygoswami5374 ปีที่แล้ว +3

    here is a solution of the leetcode problem
    class Solution {
    public int minimumDifference(int[] nums) {
    if(nums.length == 2) return Math.abs(nums[0] - nums[1]);
    int total = Arrays.stream(nums).sum();
    int n = nums.length / 2;
    HashMap map1 = new HashMap();
    HashMap map2 = new HashMap();
    for(int i = 0 ; i < (1 0){
    if((bitmask&1) == 1){
    sumbits++;
    sum += nums[pos];
    }
    pos++;
    bitmask = bitmask >> 1;
    }
    if(!map1.containsKey(sumbits)) map1.put(sumbits,new ArrayList());
    map1.get(sumbits).add(sum);
    }

    for(int i = 0 ; i < (1 0){
    if((bitmask&1) == 1){
    sumbits++;
    sum += nums[pos + n];
    }
    pos++;
    bitmask = bitmask >> 1;
    }
    if(!map2.containsKey(sumbits)) map2.put(sumbits,new ArrayList());
    map2.get(sumbits).add(sum);
    }

    for(int i = 0 ; i

  • @pudisumantharjun
    @pudisumantharjun ปีที่แล้ว +3

    full confusion bro

  • @adityaagarwal1650
    @adityaagarwal1650 2 ปีที่แล้ว +3

    elements can be negative also, so ig your solution is wrong.

    • @happyengineeringwithanmol
      @happyengineeringwithanmol  2 ปีที่แล้ว +1

      The solution is correct its accepted on both the platforms I feel you missed out somewhere you can join my telegram group for detailed discussion

    • @adityaagarwal1650
      @adityaagarwal1650 2 ปีที่แล้ว +4

      @@happyengineeringwithanmol i mean in the explanation it be abs(20 - 2*sum2) >= 0 and one doubt I have is
      auto itr = lower_bound(v.begin(), v.end(),b) for this we should also consider one iterator prior to itr also (i.e. (-- itr)) as that also give us minimum?.. right?

    • @happyengineeringwithanmol
      @happyengineeringwithanmol  2 ปีที่แล้ว +1

      @@adityaagarwal1650 even I did added that condition previously but test cases were like that my solution passed