3165. Maximum Sum of Subsequence With Non-adjacent Elements | Bonus Qs + Hint | Weekly Leetcode 399

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 21

  • @karthikreddy8965
    @karthikreddy8965 6 місяців тому +1

    in the definition of the node just replacing vector into an array ie int val [2][2] gives ac to your solution .. the problem was you are using too many resizes using the vector..also you could use ios_base::sync blah blah to further improve on it

    • @codingmohan
      @codingmohan  6 місяців тому +1

      Thanks!Vector to array was a nice catch.
      Also I don't think ios_base applies here as the input and output is performed before our function is call, did you ever try that in the past in leetcode?

    • @karthikreddy8965
      @karthikreddy8965 6 місяців тому

      @@codingmohan i didnt believe in it too.. but i could see some 50 ms improvement for 350 ms run time...

  • @problematicpuzzlechannel6663
    @problematicpuzzlechannel6663 6 місяців тому +1

    When merging the node, why is it ans[i][j] = max(ans[i][j], lft[i][k] + rgt[1 - k][j]) ? Do we have to also consider this case: lft[i][0] + rgt[0][j], where last element of lft and first element of rgt is not selected

    • @codingmohan
      @codingmohan  6 місяців тому

      You can consider that case as well but that should already be covered in rgt[1][j] because the definition of the values in this array is "what is the maximum value we can have if we start with this index". Therefore if there is a scenario where not choosing the 1st index would yield better results, the value will reflect the same.
      Hope that clarifies.

  • @krishanusaha5212
    @krishanusaha5212 6 місяців тому +3

    Block placement query is easier than Maximum sum of subsquence...

  • @manaskumarpanda8961
    @manaskumarpanda8961 4 місяці тому

    Superb Explanation sir🔥

  • @prithwirajmitra3811
    @prithwirajmitra3811 6 місяців тому +1

    Superb 🔥. Can you solve the Biweekly Contest 131 4th question ?

  • @raghavendrac4710
    @raghavendrac4710 6 місяців тому

    Thank you sir!

  • @jayantsharma3968
    @jayantsharma3968 6 місяців тому

    Awesome explanation! Thankyou Mohan!!

  • @krishanusaha5212
    @krishanusaha5212 6 місяців тому

    Awesome explanation, thake you bhaiya ❤

  • @nabajyotimajumdar4511
    @nabajyotimajumdar4511 6 місяців тому

    Awesome question, awesome explanation

  • @ayushjaiswal2020
    @ayushjaiswal2020 6 місяців тому +3

    you waited? of course.

  • @rajatmantri9141
    @rajatmantri9141 6 місяців тому

    nice explanation

    • @rajatmantri9141
      @rajatmantri9141 6 місяців тому

      sir could you plz make video on block placement queries

  • @hwgshvhd
    @hwgshvhd 6 місяців тому

    great explanation!

  • @nikhilprakash729
    @nikhilprakash729 6 місяців тому

    Awesome Explanation

  • @raisanjeeb42
    @raisanjeeb42 6 місяців тому +1

    I tried by creating segmentTree of vector of size 4 instead of Struct Node and it passed all test case . I meant Tree.resize(4*n,vector(4,0))
    I must say thank tou for the efforts you put in to explain. beautiful explanation

  • @raghavendrac4710
    @raghavendrac4710 6 місяців тому

    Thank you sir!