Segment Tree | Range Sum Query | Story To Code | Video 3

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 27. 07. 2024
  • iPad PDF Notes - github.com/MAZHARMIK/Intervie...
    Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 3rd video of our playlist "Segment Tree Concepts & Questions". Find the Details below :
    Video Name : Segment Tree | Range Sum Query | Story To Code | Video 3
    Video # : 3
    🔍 Unraveling Segment Tree : A Journey into the Depths of Code
    đŸŽ„ Welcome to the 3rd Video of my Segment Tree Concepts & Questions Playlist! 🚀 In this enlightening video, we will see how segment trees help to do Range Sum Query operations efficiently.
    🔍 What's Inside ?
    🔗 We will see how segment trees help to do Range Sum Query operations efficiently.
    đŸ‘©â€đŸ’» Who Should Watch ?
    This playlist is for everyone but best suited for Freshers who are new to Segment Tree.
    🚀 Embark on the Segment Tree Adventure Now!
    My DP Concepts Playlist : ‱ Roadmap for DP | How t...
    My Graph Concepts Playlist : ‱ Graph Concepts & Qns -...
    My Recursion Concepts Playlist : ‱ Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Summary : In this video we will see how segment trees help to do Range Sum query operations efficiently. We will also see how in the "Range Sum Query" problem, the time complexity is O(log n). We will understand it from the tree diagram and also convert the story to code to write the Query function.
    ╔═╩╗╔╩╗╔═╩═╩╩╩╩╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    ✹ Timelines✹
    00:00 - Introduction
    00:40 - Recap
    01:31 - Range Sum Query
    03:20 - Tree Diagram
    12:42 - 3 Cases in Range Sum Query
    21:00 - Story To Code
    24:55 - Time Complexity
    #codestorywithMIK
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation
    #segmenttree #segment #rangequeries

Komentáƙe • 39

  • @unknown47896
    @unknown47896 Pƙed měsĂ­cem +1

    super

  • @22gauravkumar70
    @22gauravkumar70 Pƙed měsĂ­cem +10

    Back to Back videos , please finish this segment tree series . As usual mza aaya , Segment tree ka darr khatam

  • @xiaoshen194
    @xiaoshen194 Pƙed měsĂ­cem +6

    Tysm❀!! Btw How many videos can we expect in this playlist?

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i Pƙed měsĂ­cem

    Thankyou SIr!

  • @inderjeet09
    @inderjeet09 Pƙed měsĂ­cem +1

    please upload more videos ,like more questions of segment tree

  • @nikhilsihare1887
    @nikhilsihare1887 Pƙed 3 dny

    Sir mere kaafi concepts clear ho gaye...
    Lekin sir companies mai shortlist nhi ho paa bss interview tak pauch jaau phir toh bss aapka hii concept bataunga interviewer ko...

  • @himeshbaraik3811
    @himeshbaraik3811 Pƙed měsĂ­cem

    Back to Back videos 💙, please continue DP concept and questions series 🙏

  • @gui-codes
    @gui-codes Pƙed měsĂ­cem +1

    guruji bahot bahot thank you aapko

  • @aws_handles
    @aws_handles Pƙed měsĂ­cem

    Thanks a lot. When you are free , please upload more on this playlist

  • @ABHIK-dq7rk
    @ABHIK-dq7rk Pƙed měsĂ­cem

    Will be forever grateful for all the work you are putting in thank you bhaiya

  • @saketg07
    @saketg07 Pƙed měsĂ­cem

    Loving the segment tree series keep going sir.

  • @pankajkashyap2892
    @pankajkashyap2892 Pƙed měsĂ­cem

    maza aaa gaya back to back videos

  • @priyanshkumariitd
    @priyanshkumariitd Pƙed měsĂ­cem

    Thanks a lot bhaiya!!

  • @gauravbanerjee2898
    @gauravbanerjee2898 Pƙed měsĂ­cem

    THanks a lot bhaiya ❀❀

  • @manishkumarprajapati6280
    @manishkumarprajapati6280 Pƙed měsĂ­cem

    Sir ji, Please kuch videos aur laa do na iss playlist pe

  • @zebra-er6xc
    @zebra-er6xc Pƙed měsĂ­cem

    waiting for video 4

  • @tutuimam3381
    @tutuimam3381 Pƙed měsĂ­cem

    Thanks a lot ❀❀

  • @ugcwithaddi
    @ugcwithaddi Pƙed měsĂ­cem

    Thank you

  • @ashish3487
    @ashish3487 Pƙed měsĂ­cem

    Sir thanks a lot
    ❀❀❀

  • @shibainu7500
    @shibainu7500 Pƙed měsĂ­cem

    Waiting for some problem solving

  • @KunalSingh-ol6zx
    @KunalSingh-ol6zx Pƙed měsĂ­cem +5

    ye raha bhiaya code.
    class SGT {
    public:
    vector seg;
    SGT(int n) {
    seg.resize(4 * n);
    }
    void build(int idx, int l, int r, vector& arr) {
    if (l == r) {
    seg[idx] = arr[l];
    return;
    }
    int mid = l + (r - l) / 2;
    build(2 * idx + 1, l, mid, arr);
    build(2 * idx + 2, mid + 1, r, arr);
    seg[idx] = seg[2 * idx + 1] + seg[2 * idx + 2];
    }
    void update(int idx, int val, int i, int l, int r) {
    if (l == r) {
    seg[i] = val;
    return;
    }
    int mid = l + (r - l) / 2;
    (idx end || r < start) return 0;
    if (l >= start && r build(0, 0, n - 1, nums);
    }

    int sumRange(int left, int right) {
    return stree->query(left, right, 0, 0, n - 1);
    }
    ~NumArray() {
    delete stree;
    }
    };
    /**
    * Your NumArray object will be instantiated and called as such:
    * NumArray* obj = new NumArray(nums);
    * int param_1 = obj->sumRange(left, right);
    * obj->update(index, val);
    */

  • @farj3946
    @farj3946 Pƙed měsĂ­cem +2

    C++ code for this question (Leetcode -- 307)
    class NumArray {
    int n;
    vector input;
    vectorsegment;
    public:

    void buildSegment(int ind , int l , int r){
    if(l == r){
    segment[ind] = input[l];
    return;
    }
    int mid = (l+r)/2;
    buildSegment(2*ind+1 , l , mid);
    buildSegment(2*ind+2 , mid+1 , r);
    segment[ind] = segment[2*ind+1] + segment[2*ind+2];
    }
    void updateSegment(int ind , int val , int i , int l , int r){
    if(l == r){
    segment[i] = val;
    return;
    }
    int mid = (l+r)/2;
    if(ind end or r=start and r update(index,val);
    * int param_2 = obj->sumRange(left,right);
    */

  • @pankajrana9668
    @pankajrana9668 Pƙed měsĂ­cem

    waiting for fenwick tree

  • @user-nx9jh6uo2d
    @user-nx9jh6uo2d Pƙed měsĂ­cem

    Bhai aage ki videos daalo please..

  • @dhairyachauhan6622
    @dhairyachauhan6622 Pƙed měsĂ­cem

    @mik bhaiya, please keep a resume review video also, when you get time. :)

  • @Abhay14
    @Abhay14 Pƙed měsĂ­cem

    bhai question krwao abb iss topic ke easy vale
    leetcode and codeforces koi bhi chlegga

  • @user-is6pf9gh2r
    @user-is6pf9gh2r Pƙed měsĂ­cem

    how to do if the query is sort till the particular index

  • @KartikeyTT
    @KartikeyTT Pƙed měsĂ­cem

    Kitne video ka series h ye?

  • @pranjalyadav4006
    @pranjalyadav4006 Pƙed měsĂ­cem

    nxt video nhi aayi

  • @LakkiExplainer
    @LakkiExplainer Pƙed měsĂ­cem

    Sir can you help in this question .
    Write a C++ program to insert a new node at the beginning of a Singly Linked List with the values 13 11 9 7 5 3 1 . The node value to be inserted is 0.
    Only test case 1 is passing , test case 2, 3 ,4 ,5 gets failed.
    Please help me in this.

  • @KunalSingh-ol6zx
    @KunalSingh-ol6zx Pƙed měsĂ­cem +1

    bhaiya size 2*n me runtime error de rha 4*n shai chal rha kyu?

  • @Lucifer0872
    @Lucifer0872 Pƙed měsĂ­cem

    dp finish kijiye bhaiya please

  • @nirmalgurjar8181
    @nirmalgurjar8181 Pƙed měsĂ­cem +1

    Leetcode 307 solved using above approach with below java code:
    class NumArray {
    int n = 0;
    int[] segmentTree = null;
    int[] input = null;
    public void builSegmentTree(int i, int l, int r) {
    if (l == r) {
    segmentTree[i] = input[l]; // l or r
    return;
    }
    int m = (l + r) / 2;
    builSegmentTree(2 * i + 1, l, m); // left subtree at 2i + 1
    builSegmentTree(2 * i + 2, m + 1, r); // right subtree at 2i + 2
    segmentTree[i] = segmentTree[2 * i + 1] + segmentTree[2 * i + 2];
    }
    public int rangeSum(int i, int l, int r, int s, int e) {
    if (e < l || s > r) { // out of range
    return 0;
    }
    if (l >= s && r

  • @abhinavnarang4369
    @abhinavnarang4369 Pƙed měsĂ­cem

    bhai code likha kro yar, live code, kal bhi comment kra tha, dont compromise on quality

    • @codestorywithMIK
      @codestorywithMIK  Pƙed měsĂ­cem +3

      Hello Abhinav,
      Definitely I will write the code.
      Actually I was planning to first introduce
      1) Build segment tree
      2) Update Query
      3) Range Query
      Now, we are good to go with code.
      Next video will be containing the code as well. Thank you ❀❀

    • @priyanshkumariitd
      @priyanshkumariitd Pƙed měsĂ­cem

      ​@@codestorywithMIK Ok bhaiya !! Thanks for this series & your consistency is on next level...đŸ’–đŸ’–đŸ”„đŸ”„

    • @abhinavnarang4369
      @abhinavnarang4369 Pƙed měsĂ­cem

      @coddstorywithMik okayy sure, can you please upload the code of prefix sum array in your GitHub repo? Love your content as always , keep it up❀