All Indices in Array - Solution | Recursion | Data Structures and Algorithms in JAVA

Sdílet
Vložit
  • čas přidán 24. 07. 2020
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the solution where we are required to find all the indices of occurrence for a given element and print it using a separate array using a recursive logic. To watch the problem statement, click here: • All Indices in Array -...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #pepcoding #programming #freeonlinecourses
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

Komentáře • 160

  • @dheerajbarik383
    @dheerajbarik383 Před 4 lety +97

    randomly started watching recursion tutorials playlist from your channel at around 12:00 am, now its 3:25 am and i am half way through it! (24/53), i cant tell you how brilliantly you have explained the concepts! I would definitely complete it and also complete all the major parts of Data Structures and Algorithms from your channel! Thank you so much Sir! I really appreciate your efforts!

    • @Pepcoding
      @Pepcoding  Před 4 lety +25

      I love this. This is what makes it worth for me. I hope you keep watching.

    • @dheerajbarik383
      @dheerajbarik383 Před 4 lety +6

      @@Pepcoding Sure Sir! I am loving this! Are we gonna get Intermediatary and adv level course videos too?

    • @Pepcoding
      @Pepcoding  Před 4 lety +23

      @@dheerajbarik383 yes. All of pepcoding's content, current and future in its entirety will be made available to the community.

    • @dheerajbarik383
      @dheerajbarik383 Před 4 lety +8

      @@Pepcoding I would definitely gonna share this with my friends! Thank you so much sir! ♥️

    • @gauravkvtamboli2660
      @gauravkvtamboli2660 Před 2 lety +2

      I am also following the same pattern, picking up DSA playlist of PepCoding, and watching in sequence, everything is explained very well in a detailed manner, and got 100% clear concepts, I am able to solve so many problems because of Pepcoding(Sumit Sir)!!, I am going level by level mentioned by Pepcoding, Thanks a lot for such great and in-depth content. Dedication, Interest, patience, and discipline are most important when following Pepcoding, Go level by level, and I can say with confidence, that in the future you won't stuck in DSA if you complete all levels of DSA from Pepcoding, no other channel is needed, Pepcoding is capable enough to clear all the concepts and problems of DSA.

  • @saurabhanand8085
    @saurabhanand8085 Před 3 lety +60

    This is GOLD!! I came here after someone's LinkedIn post. First watched Tower of Hanoi from your channel.I am hooked now.

    • @Pepcoding
      @Pepcoding  Před 3 lety +18

      Great. I like it when somebody likes this video. Tower of Hanoi mei bhot effort daala tha poori story bnane mei.
      Also, i request you for a review
      g.page/Pepcoding/review?rc

  • @shivangsharma4873
    @shivangsharma4873 Před 3 lety +19

    I don't think there could be a better explanation of this question with so much patience you explain the concepts make it crystal clear.

  • @anujkumarnath1769
    @anujkumarnath1769 Před 3 lety +8

    I was about to give up on DSA. But after watching your videos of the recursion series for the first time, I realized, "I shouldn't".

  • @adheeshmishra7882
    @adheeshmishra7882 Před 3 lety +6

    this channel deserves 1million subscribers...already shared with all my friends all across the platforms

  • @khyatibeads420
    @khyatibeads420 Před rokem

    I have tears in my eyes at how brilliantly Sir explains such complex concepts with so much ease. Thank you for coming on CZcams and uploading such brilliant content for free.

  • @sakshiaggarwal6199
    @sakshiaggarwal6199 Před 3 lety

    kya clarity hai ek dum crystal clear hojata hai concept!! Thank you so much sir!!

  • @vivekbharti1792
    @vivekbharti1792 Před 2 lety

    also, take a note that this playlist is the best playlist for recursion. you have just reborn my interest in coding.

  • @rashmiprakash2842
    @rashmiprakash2842 Před 2 lety

    This is real gold..All your videos are exceptional..

  • @anweshangoswami5636
    @anweshangoswami5636 Před 2 lety +1

    I usually don't comment but I can't stop myself to comment that "Bhai maza aa gya"....Itna depth me recursion koi nhi padhata

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad that you loved it. For better experience and curated content sign up on nados.io, you can also post your queries on community tab of NADOS.

  • @rajneeshsahuit0795
    @rajneeshsahuit0795 Před rokem

    First of all ,thanks for this recursion playlist. And
    Sir you dry run makes a recursion very very easy.
    keep uploading playlist we will always support you.

  • @reshihashim4094
    @reshihashim4094 Před 2 lety

    Can't be taught simpler than this... Hats off to u sir and to your efforts...
    The best playlist ever and i have been following ur dsa playlist , u make things easier. Keep it up sir stay blessed
    Love from Kashmir 💗

  • @_rahulsain
    @_rahulsain Před 3 lety +8

    This was my approach->
    import java.io.*;
    import java.util.*;
    public class Main {
    public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
    arr[i] = Integer.parseInt(br.readLine());
    }
    int x = Integer.parseInt(br.readLine());
    int[] iarr = allIndices(arr, x, 0, 0);
    if (iarr.length == 0) {
    System.out.println();
    return;
    }
    for (int i = 0; i < iarr.length; i++) {
    System.out.println(iarr[i]);
    }
    }
    public static int[] allIndices(int[] arr, int x, int idx, int fsf) {
    if (arr.length == idx) {
    return new int[fsf];
    }
    if (arr[idx] == x) {
    fsf++;
    }
    int[] ans = allIndices(arr, x, idx + 1, fsf);
    if (arr[idx] == x) {
    ans[--fsf] = idx;
    }
    return ans;
    }
    }

    • @mohnishkamble
      @mohnishkamble Před 2 lety

      This is also a correct solution. But, you are comparing it while going up and while coming down as well. That's the only difference, which might be a slower approach as compared to the approach shown in this video.

  • @revanthvenkateswar622
    @revanthvenkateswar622 Před 3 lety +1

    Subscribed. Wholesome explanation.

  • @Rajyadav-ll3dk
    @Rajyadav-ll3dk Před 7 měsíci

    I watched the first vedio for trial and now I can't stop myself from watching your vedios

  • @raj_kundalia
    @raj_kundalia Před 2 lety

    Watched on 17 October, 2021 - Thanks for the video.

  • @ankitank1990
    @ankitank1990 Před 3 lety +4

    Only few people can do this great cause. Serving the community in such a nice way. Thanks!

    • @Pepcoding
      @Pepcoding  Před 3 lety +8

      I am a businessman, this content is my marketing.

    • @Pepcoding
      @Pepcoding  Před 3 lety +8

      Keep learning. We both win if you learn from my content. We win together.

  • @anmolverma075
    @anmolverma075 Před rokem

    Wish I knew about you in the start of my 1st year, it would have been a bliss fore me sir!

  • @naman8744
    @naman8744 Před 3 lety +5

    I got the logic clearly but I want to know what is the "faith" in this ques.

  • @neerajmahapatra5239
    @neerajmahapatra5239 Před 2 lety +2

    I was following you from starting of recursion. I solved this question by own. I am literally so happy sir.. Just because of you now I can show magics in recursion. I am very pumped up
    Actually I use cpp so I used stack and I kept pushing_back while moving from start to end only and when I reached the end I returned the vector.
    .. Thankss

  • @trisha4985
    @trisha4985 Před 3 lety +4

    Never Understand the recursive Concept Like this. Great work Sir and Thank you for making recursion crystal clear

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

    • @trisha4985
      @trisha4985 Před 3 lety

      @@Pepcoding sure sir. I watched the whole Playlist can't able to leave it because of you. Now I love recursion.

  • @aniketjaiswal3876
    @aniketjaiswal3876 Před 3 lety +3

    Thank you sir, due to you I've gain confidence in solving recursion problems... :)

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @shalugupta4784
    @shalugupta4784 Před rokem

    After trying so many times , move here and there , done with everything to learn recursion but was not able to understand this topic . Everyone was saying recursion is a magic but I was not able to see that magic but sir You, I do not have words to describe your efforts , Thank you so much sir. You made it really easy thank you so much.

  • @amritatiwary.
    @amritatiwary. Před rokem

    You dont know sir , i was totally blank after watching other youtube videos about recursion,backtracking btt your channel give me hope and confidentt too, that i can also solve some recursion questions

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 Před 2 lety

    wow sir!! your explanation is next level 🔥😍🤍

  • @AbirPalDev
    @AbirPalDev Před 3 lety +1

    Amazed !! Sometimes up and sometimes down.. and understood the intuition behind such complex recurison so easily.. Awesome sir :)

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thanks a ton. keep motivating, keep learning and keep loving Pepcoding😊

  • @natashaganjoo4464
    @natashaganjoo4464 Před 2 lety

    Hats off to your dedication and Patience. Thank you.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @deeprakholiya7583
    @deeprakholiya7583 Před 3 lety

    Awesome Explanation

  • @Flash-qr5oh
    @Flash-qr5oh Před 2 lety

    after learning so much, from this video I am able to write my own recursion functions properly... :)

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Great job!
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @nknidhi321
    @nknidhi321 Před 3 lety

    Kudos to you..🙏❤️

  • @umber3117
    @umber3117 Před 4 lety +2

    Your teaching skills are awesome!!!

  • @taheermattur
    @taheermattur Před 3 lety

    Great explanation sir♥️

  • @kashba
    @kashba Před 2 lety +1

    My approach ->
    public static int[] allIndices(int[] arr, int x, int idx, int fsf) {
    if(idx == arr.length){
    return new int [fsf]; //base case
    }
    if(arr[idx] == x){ //upar jaate huye stack me check karna ke x kitni baar aaya
    fsf++;
    }
    int arr1[] = allIndices(arr, x, idx + 1, fsf);

    if(arr[idx] == x){ //waapas aate huye array jo aaya usko bharna
    arr1[fsf - 1] = idx;
    }
    return arr1;
    }

  • @ishanshah3309
    @ishanshah3309 Před 2 lety

    Really very good explanation

  • @knightrec869
    @knightrec869 Před 3 lety +2

    Best teacher I have been ever seen since nursery class.

    • @Pepcoding
      @Pepcoding  Před 3 lety +3

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

    • @knightrec869
      @knightrec869 Před 3 lety +4

      @@Pepcoding sumeet sir teach us everything that you know.

    • @priyanshukumawat4142
      @priyanshukumawat4142 Před 3 lety +1

      @@knightrec869 google AUTO CORRECT is devil sumit sir you spelled submit

  • @aarifrather7975
    @aarifrather7975 Před rokem

    well explained

  • @adityakajale4403
    @adityakajale4403 Před 3 lety

    Pure gold!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @neelshah4812
    @neelshah4812 Před 3 lety

    maza aagya sir ;)

  • @praveensingh1492
    @praveensingh1492 Před 3 lety

    great ho sir aap

  • @anmolprakash1067
    @anmolprakash1067 Před 3 lety

    Bhai ek course lai rkha maine Ds ka khi or se Lekin vha bhi itna accha explain nhi krta koi jitna Apne yha btaya vo bhi free of cost . Thnnx sir ...

    • @Pepcoding
      @Pepcoding  Před 3 lety +7

      hmara he course le lete!! :-(

  • @AbhishekGupta-cr1mf
    @AbhishekGupta-cr1mf Před 3 lety

    😍😍😍😍😍😍😍Bahut jayada hi maja aaya GURUji..LOve hard of ur teching

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @AnkitKumar-fj8ex
    @AnkitKumar-fj8ex Před 3 lety

    Sir u are just awesome🙏

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @yoyo8293
    @yoyo8293 Před 3 lety

    Sir in this question and in FIrst index second approach , how to think about the faith and link with expectation ?

  • @user-pr6fn1jz6m
    @user-pr6fn1jz6m Před 3 lety

    bhaiya app sabse alag ho pure utube pai mai aur sab apki sari vedios ko share and popular karenge thnks sir

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thanks man for this lovely gesture. Also, If you like our efforts, will you like to write a review about us here - g.page/Pepcoding/review?rc

  • @ravichandola2081
    @ravichandola2081 Před 3 lety

    Superb explanation sir.

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thanksyou beta!
      Keep learning and keep loving😊

  • @shivanishikha8552
    @shivanishikha8552 Před 3 lety +1

    8:20 agr saare teachers students ko aise hi smjhte to kya baat hoti!!!!

  • @laletscaria
    @laletscaria Před 2 lety +1

    Was able to come up with a much smaller solution
    arr = [3,4,3,4,1,2]
    results = []
    def all_idx(arr, number, index):
    if index == len(arr):
    return []
    if arr[index] == number:
    return [index] + all_idx(arr, number, index + 1)
    return all_idx(arr, number, index + 1);
    print(all_idx(arr, 3, 0))

    • @vortex370
      @vortex370 Před rokem

      You didn't do anything just ...
      Merging the lines ..both solutions are same

  • @Xp-Sam
    @Xp-Sam Před 2 lety

    sir what if we have to return the array to a function where it prints its content.... but it will require the length also apart from the address.

  • @jainmayur
    @jainmayur Před 3 lety +8

    How can we solve this question using "faith" and "expectation" as done in other examples?

    • @bloody9162
      @bloody9162 Před 2 lety +5

      This is not an intuitively recursive problem I'd say. It's better to solve it iteratively both in terms of cost and fuzziness. Although this problem gives an in-depth understanding of memory management during recursive calls. Faith and Expectation is a technique to think about problems that are intuitively recursive. This on the other hand involves using an Array which by definition is a contiguous space in memory which is a CS specific concept, and hence you're bound by something specific to limitations in computer science. This is a very good problem for understanding the recursion in depth. Although Faith and Expectation will fit here as well, it won't make much sense to think about it since you're getting an array from the subproblem which is actually of the size which is determined by keeping the parent problem in mind.
      That being said, this is a beautiful problem and Sumeet Sir did a great job like always, with the explanation.

  • @chandrachudsinghchundawat544

    Can we do it in single traversal?? As here we are traversing it 2 times(for count & for indices).

  • @praveensingh1492
    @praveensingh1492 Před 3 lety

    sir direct arraylist bna k indices add nahi kr skte hai kya ??

  • @pratyush__agarwal
    @pratyush__agarwal Před 3 lety

    Wow❤️

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Keep watching and keep learning😊

  • @RakeshKumar-jj5ru
    @RakeshKumar-jj5ru Před 4 lety +2

    good explanation sir jiii !
    Dynamic programing with the help of java pe pls video banaeye ga.........dynamic programming ke liye he recursion padh raha huuuu.

  • @Flash-qr5oh
    @Flash-qr5oh Před 2 lety

    writing this at timestamp 5:30
    my code is below and its working totally fine,
    please tell if its wrong approach in terms of recursion or time complexity.
    vector rec(vector v,int tofind,int index, vector toreturn){
    if(index==v.size())
    return toreturn;
    if(v[index]==tofind){
    toreturn.push_back(index+1);
    return rec(v,tofind,index+1,toreturn);
    }
    else{
    return rec(v,tofind,index+1,toreturn);
    }
    }

    • @Pepcoding
      @Pepcoding  Před 2 lety

      For better insight, visit nados.pepcoding.com, post your doubts, community will help you out there.

  • @ayushijangid9503
    @ayushijangid9503 Před 2 lety

    Sir isme faith and Expectation kaise rahenge?

  • @ashutoshmanorkar5556
    @ashutoshmanorkar5556 Před 2 lety

    is it possible ki jo recursion se hoga wo iteration se bhi hoga?

  • @RishabhSharma-tp7rs
    @RishabhSharma-tp7rs Před rokem

    If we do by sir’s approach, how will we know that fsf will get reduced if we previously not know the solution…. and if data is large how will we handle this and know this. And also fsf value is 3 and arr[fsf] is of size 3 how it will contain 4 values ??

  • @surajkunwar6830
    @surajkunwar6830 Před 3 lety

    can any one help me please
    how to return the base case in python

  • @atulsharma3443
    @atulsharma3443 Před 3 lety

    sir op🔥

    • @Pepcoding
      @Pepcoding  Před 3 lety

      keep motivating, keep learning and keep loving Pepcoding😊

  • @pushkargoyal4278
    @pushkargoyal4278 Před 3 lety

    Wow what a logic. I am thinking about using collection framework

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad you liked it!
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

    • @utkarshsharma6650
      @utkarshsharma6650 Před 3 lety +2

      yes, you can do it that way too

    • @sumitrana2628
      @sumitrana2628 Před 3 lety

      Thank you so much sir for this type of effort and explanation 🥰🥰🙏🏻🙏🏻🙏🏻💕💕💕I feel so much Lucky🥰🥰🙏🏻 that I find pepcoding and a great teacher like you🎊🎊🎊🤗🤗

  • @levisingh5660
    @levisingh5660 Před 3 lety +1

    Loved the Explanation sir !! Sir plz suggest me that I should first complete the foundation course's all problems and then practice on leetcode etc. or I should do leetcode along side this ??

    • @Pepcoding
      @Pepcoding  Před 3 lety

      beta pehle level1 finish karo, firr leet

    • @levisingh5660
      @levisingh5660 Před 3 lety

      @@Pepcoding okay thankyou sir ..

  • @madhurendranathtiwari9465

    public static void allArrayEleOcc(int arr[],int index,int data){
    if(index==arr.length){
    return;
    }
    if(arr[index]==data){
    System.out.print(index+" ");
    }
    allArrayEleOcc(arr,index+1,data);
    } //is it also right ?

  • @theuntoldtree
    @theuntoldtree Před 3 lety

    could someone pls give cpp code with same logic
    it will be a great help,tq

  • @utkarshsharma6650
    @utkarshsharma6650 Před 3 lety

    rather than doing all this, can't we simply output the required index in the first iteration itself (as soon as we found the element, why don't we output it)? making an array brings unnecessary load on memory

  • @SatyamKumar-pd8qy
    @SatyamKumar-pd8qy Před 2 lety

    satya,

  • @deeprakholiya7583
    @deeprakholiya7583 Před 3 lety

    Bhai plzz CP ke uper bhi videos banao

  • @ankurtiwari5534
    @ankurtiwari5534 Před 2 lety

    Sir ye return likhe hai program me wo kaha jata hai bahut dino se confuse hu sir

  • @tanujkasal
    @tanujkasal Před 3 lety

    sir your videos are great .
    I have a request, While using your platform , i was unable to download the failed testcases.Please correct that bug.

  • @MDArif-we2kg
    @MDArif-we2kg Před 3 lety +1

    Explanation was awesome.. Now, I am loving recurion bcoz of you!... Can u plse tell me , how can i return base case in c++ of this problem.. I am stucked..

  • @DhananjayKumar-vn5tc
    @DhananjayKumar-vn5tc Před 2 lety +1

    sir the content here is like open gold mine ,loot lo jitna loot sakte ho😂,

  • @manudeep5093
    @manudeep5093 Před 3 lety +2

    sumit sir is king.....

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      aapki seva mei tatpar!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      If you like my efforts, I request a review
      g.page/Pepcoding/review?rc

  • @shivendumishra2804
    @shivendumishra2804 Před 2 lety

    One more approach to this question:
    public static int[] allIndices(int[] arr, int x, int idx, int fsf) {
    // write ur code here
    if(idx == arr.length){
    int[] res = new int[fsf];
    return res;
    }

    if(arr[idx] == x){
    // add this index to the array
    fsf++;
    }
    int[] res1 = allIndices(arr, x, idx+1, fsf);
    if(arr[idx] == x){
    res1[fsf-1] = idx;
    }
    return res1;
    }

  • @shubhambhosale8467
    @shubhambhosale8467 Před 2 lety

    any cpp solution

  • @ShivamSingh-zl1fd
    @ShivamSingh-zl1fd Před 3 lety

    if you will declare iarr outside then it will be more clear, i think
    public static int[] AllIndeces(int[] arr, int x, int start, int tot) {
    if(start == arr.length)
    return new int[tot];
    int[] res;
    if(arr[start] == x){
    res = AllIndeces(arr, x, start + 1, tot + 1);
    res[tot] = start;
    }else {
    res = AllIndeces(arr, x, start + 1, tot);
    }
    return res;
    }

  • @aashimgarg8416
    @aashimgarg8416 Před 3 lety +3

    Sir ismein ham ArrayList bhi to use kar sakte the. Fir size ka issue nhi aata

  • @manuj9570
    @manuj9570 Před 3 lety

    In place of array we can you a list to right?

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

  • @divitgoyal5901
    @divitgoyal5901 Před 3 lety +3

    Sir I am used to writing codes in c++ instead of java,and I have been following your lectures sincerely and implementing the same codes into c++ and they have helped me a lot. But in this particular code I am unable to write it in c++,can you provide me with the code in c++, the same code, it would be very helpful.

    • @anukratigupta
      @anukratigupta Před 2 lety

      yes
      please do this in cpp

    • @codinggems9973
      @codinggems9973 Před 2 lety +3

      Hey cpp soln with same approach as discussed in the video
      vector allIndex(vector& arr, int idx, int data, int count)
      {
      if(idx == arr.size()){
      res.resize(count,0);
      return res;
      }
      if(arr[idx]==data){
      res = allIndex(arr,idx+1,data,count+1);
      res[count]=idx;
      return res;
      }
      else{
      res = allIndex(arr,idx+1,data,count);
      return res;
      }
      }

    • @omrajgure4553
      @omrajgure4553 Před 2 lety

      @@codinggems9973 what is 'res' here it is undefined...can you please tell me cause I am facing that problem

    • @terminator_363
      @terminator_363 Před 2 lety

      @@omrajgure4553 vector..

  • @vivekbharti1792
    @vivekbharti1792 Před 2 lety

    all the explanations are awesome, but can anyone clarify for me what does 4k and 5k represent?

  • @surajbhatt3543
    @surajbhatt3543 Před 3 lety

    Sir what is return new int (100)

  • @syedhabeebuddin101
    @syedhabeebuddin101 Před 3 lety

    I don't have any words...........but, Thanks a lot !

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @syedhabeebuddin101
      @syedhabeebuddin101 Před 3 lety

      @@Pepcoding yeah, sure sir ! 😇

  • @anshrohatgi4202
    @anshrohatgi4202 Před 3 lety

    Sir ,
    how to know to kitne call laganii h recursiiiion me?

    • @alltechsimplified2134
      @alltechsimplified2134 Před 3 lety

      run your recursive algorith for small cases like 1-2-3 and then you can find the call on that basis

  • @amanpreetsinghsetia1524

    int* printAllIndexes(int arr[],int idx,int data,int n,int fsf){
    if(idx==n){
    int * p=(int *)malloc((fsf)*sizeof(int));
    return p;
    }
    if(arr[idx]==data){
    int *iarr= printAllIndexes(arr,idx+1,data,n,fsf+1);
    iarr[fsf]=idx;
    return iarr;

    }
    else{
    int *iarr=printAllIndexes(arr,idx+1,data,n,fsf);
    return iarr;
    }




    }
    I have only one doubt... how we will access the length of the returned array in the main function.....

  • @adarshabp5946
    @adarshabp5946 Před 3 lety

    Int arr =allindices() ; here what is the use of int arr and how it's work here

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

  • @sumankumarsahu1123
    @sumankumarsahu1123 Před 3 lety +1

    can anyone provide the C++ code for this ???

    • @Pepcoding
      @Pepcoding  Před 3 lety

      C++ ki videos ban rhi hain beta jakal. jald aaega

  • @guy_is_2_shy_to_talk_to_girl

    Recieve nhi palle pada

  • @guy_is_2_shy_to_talk_to_girl

    Koi plz ye batado ki new array kaise li
    Mai c++ ke liye puch rha hu

  • @vibhusha28
    @vibhusha28 Před 2 lety

    what happened to "faith" ?!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      beta, purana ho gya. ab to aa gya na samajh, shuru shuru mei bolte hain. Infact 2 variation hain, ek faith wali doosri level and options wali. PrintSubsequence se doosri start hogi.
      Aur, yahan comment kyun kar rhi ho, nados.pepcoding.com pe padho, wahan feed mei question poochogi to jwaab bhi milega.

  • @coolraviraj24
    @coolraviraj24 Před 2 lety +1

    aaj pta chla ki रायता boht Zaruri h🤣..

  • @yn-ey9sw
    @yn-ey9sw Před 3 lety +2

    Hey! I have 2 doubts, I'd be glad if anyone could answer them for me.
    (According to code visible at 8:34)
    1) How come the (code)lines 33,34,35,37 and 38 realize the fact that the array created at line number 29(when recursion hits its base case) is the same array as "iarr" in which they have to fill the indices. As there is no mention of the name of "iarr" in line 29.
    (According to DRY run at 12:59)
    2) When we are "iterating back" from recursion, we see that the value of fsf decreases when we jump from the index 8 to 7 or from index 6 to 5. I totally understand why the value of fsf increases in the first place but when we are coming out of the recursion there is no statement to decrease the value of fsf when the favourable case(arr[i]=x;) is met, what I understand is that the value of fsf should remain 3 throughout and certainly that is not the case.
    Thanks in advance if anyone could help!

    • @vikasjoshi2889
      @vikasjoshi2889 Před 3 lety +1

      because we returned an array in base case , in 33 34 and 35, 'iarr' is just the name of the array which is receiving the refernce of the base case array .
      Both point to same address .
      This is same in main , how main function recieves the array ( name is different but refernce is same ).
      I hope i was able to help .

    • @vikasjoshi2889
      @vikasjoshi2889 Před 3 lety

      As for 2nd , i would suggest you to draw euler tree of this function with values of parameter . It will become clear

  • @nikitajaiswal9112
    @nikitajaiswal9112 Před 2 lety

    def last(arr, ind, x, res) :
    If ind==len(arr) :
    Return
    If arr[ind]==x:
    Res. Append(ind)
    Last(arr, ind+1, x, res)
    Return res
    My solution is different why

    • @Pepcoding
      @Pepcoding  Před 2 lety

      For better insight, visit nados.io, post your doubts, community will help you out there.

    • @vortex370
      @vortex370 Před rokem

      Because you are using stack not array in array we have be worry about size...

  • @anmolbansal4184
    @anmolbansal4184 Před 3 lety

    //Easy JAVA Solution with single Recursive Call
    private static int[] alloccurences(int arr[],int idx,int fsf,int x){
    if(idx==arr.length){
    if(fsf==0) {//element x is not present in array
    return new int[]{-1};//hence return a new array of size 1 containing a single element -1;
    }
    else return new int[fsf];// array of size fsf (no. of times element is found)
    }
    if(arr[idx]==x){//count Number of elements in upward Recursive Motion
    fsf++;
    }
    int res[]=alloccurences(arr,idx+1,fsf,x);
    if(arr[idx]==x){
    res[fsf-1]=idx;//fill the array in downward Recursive Motion
    fsf--;//decrease pointer to fill the resultant array
    }
    return res;
    }

  • @abhishekchaudhary55
    @abhishekchaudhary55 Před 2 lety

    .

  • @SagarSharma-uk6rw
    @SagarSharma-uk6rw Před 2 lety

    Hi Guys. I solved this question without using the fsf variable . I learnt everything from you sir, I am forever grateful to you as you proided this education free of cost.
    import java.io.*;
    import java.util.*;
    public class Main {
    public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
    arr[i] = Integer.parseInt(br.readLine());
    }
    int x = Integer.parseInt(br.readLine());
    int[] iarr = allIndices(arr, x, 0, 0);
    if(iarr.length == 0){
    System.out.println();
    return;
    }
    for(int i = 0; i < iarr.length; i++){
    System.out.println(iarr[i]);
    }
    }
    public static int[] allIndices(int[] arr, int x, int idx, int fsf) {
    // write ur code here
    if(idx==arr.length){
    return new int[0];
    }
    int[] returnedArray=allIndices(arr,x,idx+1,fsf);
    if(returnedArray.length==0){
    if(arr[idx]==x){
    int[] returnCurrAray = new int[1];
    returnCurrAray[0]=idx;
    return returnCurrAray;
    }else{
    return new int[0];
    }
    }
    else{
    if(arr[idx]==x){
    int[] returnCurrAray = new int[returnedArray.length+1];
    returnCurrAray[0]=idx;
    for(int i=0;i< returnedArray.length;i++){
    returnCurrAray[i+1]= returnedArray[i];
    }
    //returnCurrAray[0]=idx;
    return returnCurrAray;
    }else{
    return returnedArray;
    }
    }
    }
    }

  • @ankitmishra399
    @ankitmishra399 Před 3 lety +1

    Thank u sir🥺❤

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Most welcome 😊Keep watching