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

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

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

  • @dheerajbarik383
    @dheerajbarik383 4 ปีที่แล้ว +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  4 ปีที่แล้ว +26

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

    • @dheerajbarik383
      @dheerajbarik383 4 ปีที่แล้ว +6

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

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +23

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

    • @dheerajbarik383
      @dheerajbarik383 4 ปีที่แล้ว +8

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

    • @gauravkvtamboli2660
      @gauravkvtamboli2660 2 ปีที่แล้ว +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 4 ปีที่แล้ว +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  4 ปีที่แล้ว +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 4 ปีที่แล้ว +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.

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

      I am happy to know this

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

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

  • @anujkumarnath1769
    @anujkumarnath1769 4 ปีที่แล้ว +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 3 ปีที่แล้ว +6

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

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

    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.

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

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

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

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

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +8

      I am a businessman, this content is my marketing.

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +8

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

  • @neerajmahapatra5239
    @neerajmahapatra5239 2 ปีที่แล้ว +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

  • @harshitaninama5235
    @harshitaninama5235 2 หลายเดือนก่อน

    thankyou so much for holding our finger and taking us through the solution step by step, i am a slow learner and i need detailed explanation and you do the wonders thankyou!!!!!!!!

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

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +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 3 ปีที่แล้ว

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

  • @_rahulsain
    @_rahulsain 4 ปีที่แล้ว +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 2 ปีที่แล้ว

      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.

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

    Best teacher I have been ever seen since nursery class.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +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 3 ปีที่แล้ว +4

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

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

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

  • @sakshiaggarwal6199
    @sakshiaggarwal6199 3 ปีที่แล้ว

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

  • @Rajyadav-ll3dk
    @Rajyadav-ll3dk 11 หลายเดือนก่อน

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

  • @anweshangoswami5636
    @anweshangoswami5636 2 ปีที่แล้ว +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  2 ปีที่แล้ว

      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.

  • @vivekbharti1792
    @vivekbharti1792 2 ปีที่แล้ว

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

  • @ruchigupta8307
    @ruchigupta8307 12 วันที่ผ่านมา

    your way of teaching is awesome.

  • @amritatiwary.
    @amritatiwary. ปีที่แล้ว

    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

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

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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 )

  • @rajneeshsahuit0795
    @rajneeshsahuit0795 2 ปีที่แล้ว

    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.

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

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

  • @reshihashim4094
    @reshihashim4094 2 ปีที่แล้ว

    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 💗

  • @rashmiprakash2842
    @rashmiprakash2842 3 ปีที่แล้ว

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

  • @anmolprakash1067
    @anmolprakash1067 4 ปีที่แล้ว

    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  4 ปีที่แล้ว +6

      hmara he course le lete!! :-(

  • @Flash-qr5oh
    @Flash-qr5oh 2 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

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

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

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

  • @natashaganjoo4464
    @natashaganjoo4464 2 ปีที่แล้ว

    Hats off to your dedication and Patience. Thank you.

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

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

  • @Flash-qr5oh
    @Flash-qr5oh 2 ปีที่แล้ว

    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  2 ปีที่แล้ว

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

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

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

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

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

  • @raj_kundalia
    @raj_kundalia 3 ปีที่แล้ว

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

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

    Your teaching skills are awesome!!!

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

      Glad you like them!

  • @user-pr6fn1jz6m
    @user-pr6fn1jz6m 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +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

  • @kashba
    @kashba 2 ปีที่แล้ว +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;
    }

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 3 ปีที่แล้ว

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

  • @surajgusain3656
    @surajgusain3656 3 หลายเดือนก่อน

    just beautiful solution....

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

    Subscribed. Wholesome explanation.

  • @AbhishekGupta-cr1mf
    @AbhishekGupta-cr1mf 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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😊

  • @shivendumishra2804
    @shivendumishra2804 2 ปีที่แล้ว

    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;
    }

  • @ishanshah3309
    @ishanshah3309 3 ปีที่แล้ว

    Really very good explanation

  • @laletscaria
    @laletscaria 2 ปีที่แล้ว +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 ปีที่แล้ว

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

  • @GghiggFfhhhf
    @GghiggFfhhhf 3 หลายเดือนก่อน

    C++ code written before watching video
    #include
    using namespace std;
    vector allIndicesOfArray(vector &arr, int index, int target, int foundSofar)
    {
    if (index >= arr.size())
    {
    vector ans(foundSofar);
    return ans;
    }
    if (target == arr[index])
    foundSofar++;
    vector ans = allIndicesOfArray(arr, index + 1, target, foundSofar);
    if (arr[index] == target)
    {
    ans[foundSofar - 1] = index;
    }
    return ans;
    }
    int main()
    {
    vector arr = {2, 3, 6, 9, 8, 3, 2, 3, 6, 4};
    vector res = allIndicesOfArray(arr, 0, 2, 0);
    for (auto it : res)
    {
    cout

  • @deeprakholiya7583
    @deeprakholiya7583 3 ปีที่แล้ว

    Awesome Explanation

  • @RakeshKumar-jj5ru
    @RakeshKumar-jj5ru 4 ปีที่แล้ว +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.

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

      Haanji. Aj shuru ho jaega

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

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

    • @bloody9162
      @bloody9162 3 ปีที่แล้ว +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.

  • @adityakajale4403
    @adityakajale4403 3 ปีที่แล้ว

    Pure gold!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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😊

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

    sumit sir is king.....

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

      aapki seva mei tatpar!

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

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

  • @nknidhi321
    @nknidhi321 3 ปีที่แล้ว

    Kudos to you..🙏❤️

  • @MDArif-we2kg
    @MDArif-we2kg 3 ปีที่แล้ว +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..

  • @taheermattur
    @taheermattur 3 ปีที่แล้ว

    Great explanation sir♥️

  • @levisingh5660
    @levisingh5660 4 ปีที่แล้ว +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  4 ปีที่แล้ว

      beta pehle level1 finish karo, firr leet

    • @levisingh5660
      @levisingh5660 4 ปีที่แล้ว

      @@Pepcoding okay thankyou sir ..

  • @pushkargoyal4278
    @pushkargoyal4278 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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 3 ปีที่แล้ว +2

      yes, you can do it that way too

    • @sumitrana2628
      @sumitrana2628 3 ปีที่แล้ว

      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🎊🎊🎊🤗🤗

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

    well explained

  • @yn-ey9sw
    @yn-ey9sw 4 ปีที่แล้ว +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 3 ปีที่แล้ว +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 3 ปีที่แล้ว

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

  • @praveensingh1492
    @praveensingh1492 3 ปีที่แล้ว

    great ho sir aap

  • @ravichandola2081
    @ravichandola2081 3 ปีที่แล้ว

    Superb explanation sir.

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

      Thanksyou beta!
      Keep learning and keep loving😊

  • @DhananjayKumar-vn5tc
    @DhananjayKumar-vn5tc 3 ปีที่แล้ว +1

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

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

    Thank u sir🥺❤

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

      Most welcome 😊Keep watching

  • @AnkitKumar-fj8ex
    @AnkitKumar-fj8ex 3 ปีที่แล้ว

    Sir u are just awesome🙏

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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 )

  • @RishabhSharma-tp7rs
    @RishabhSharma-tp7rs 2 ปีที่แล้ว

    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 ??

  • @ShivamSingh-zl1fd
    @ShivamSingh-zl1fd 3 ปีที่แล้ว

    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;
    }

  • @divitgoyal5901
    @divitgoyal5901 3 ปีที่แล้ว +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 3 ปีที่แล้ว

      yes
      please do this in cpp

    • @codinggems9973
      @codinggems9973 3 ปีที่แล้ว +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 2 ปีที่แล้ว

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

    • @terminator_363
      @terminator_363 2 ปีที่แล้ว

      @@omrajgure4553 vector..

  • @chandrachudsinghchundawat544
    @chandrachudsinghchundawat544 2 ปีที่แล้ว

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

  • @SatyamKumar-pd8qy
    @SatyamKumar-pd8qy 2 ปีที่แล้ว

    satya,

  • @syedhabeebuddin101
    @syedhabeebuddin101 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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 3 ปีที่แล้ว

      @@Pepcoding yeah, sure sir ! 😇

  • @Xp-Sam
    @Xp-Sam 3 ปีที่แล้ว

    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.

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

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

  • @SagarSharma-uk6rw
    @SagarSharma-uk6rw 2 ปีที่แล้ว

    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;
    }
    }
    }
    }

  • @utkarshsharma6650
    @utkarshsharma6650 3 ปีที่แล้ว

    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

  • @neelshah4812
    @neelshah4812 4 ปีที่แล้ว

    maza aagya sir ;)

  • @madhurendranathtiwari9465
    @madhurendranathtiwari9465 3 ปีที่แล้ว

    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 ?

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

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

  • @yoyo8293
    @yoyo8293 4 ปีที่แล้ว

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

  • @praveensingh1492
    @praveensingh1492 3 ปีที่แล้ว

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

  • @tanujkasal
    @tanujkasal 3 ปีที่แล้ว

    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.

  • @ayushijangid9503
    @ayushijangid9503 2 ปีที่แล้ว

    Sir isme faith and Expectation kaise rahenge?

  • @vivekbharti1792
    @vivekbharti1792 2 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      addresses of variables

  • @anshrohatgi4202
    @anshrohatgi4202 3 ปีที่แล้ว

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

  • @deeprakholiya7583
    @deeprakholiya7583 3 ปีที่แล้ว

    Bhai plzz CP ke uper bhi videos banao

  • @ashutoshmanorkar5556
    @ashutoshmanorkar5556 3 ปีที่แล้ว

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

  • @pratyush__agarwal
    @pratyush__agarwal 3 ปีที่แล้ว

    Wow❤️

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Keep watching and keep learning😊

  • @atulsharma3443
    @atulsharma3443 3 ปีที่แล้ว

    sir op🔥

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      keep motivating, keep learning and keep loving Pepcoding😊

  • @ankurtiwari5534
    @ankurtiwari5534 2 ปีที่แล้ว

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

  • @theuntoldtree
    @theuntoldtree 3 ปีที่แล้ว

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

  • @amanpreetsinghsetia1524
    @amanpreetsinghsetia1524 3 ปีที่แล้ว

    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.....

  • @manuj9570
    @manuj9570 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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.

  • @adarshabp5946
    @adarshabp5946 3 ปีที่แล้ว

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

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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.

  • @shubhambhosale8467
    @shubhambhosale8467 2 ปีที่แล้ว

    any cpp solution

  • @surajbhatt3543
    @surajbhatt3543 3 ปีที่แล้ว

    Sir what is return new int (100)

  • @surajkunwar6830
    @surajkunwar6830 3 ปีที่แล้ว

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

  • @nikitajaiswal9112
    @nikitajaiswal9112 2 ปีที่แล้ว

    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  2 ปีที่แล้ว

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

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

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

  • @anmolbansal4184
    @anmolbansal4184 3 ปีที่แล้ว

    //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;
    }

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

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

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

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

  • @vibhusha28
    @vibhusha28 3 ปีที่แล้ว

    what happened to "faith" ?!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      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.

  • @abhishekchaudhary55
    @abhishekchaudhary55 3 ปีที่แล้ว

    .

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

    Recieve nhi palle pada

  • @guy_is_2_shy_to_talk_to_girl
    @guy_is_2_shy_to_talk_to_girl 3 ปีที่แล้ว

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

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

      c++ me array nhi return kr skte