Printing Subarrays of a vector

Hi, I was trying to print all the subarrays of a vector, (Recursively). And in one approach of mine, the recursion was going in some states which it shouldn’t have. Then I wrote a condition (start==end) which prevented the recursion to go into the states which it goes in another recursive case. Here’s the code link. I cannot justify it to myself why did it stop going into another state or how it helped. Also here’s the code where I did not write the condition and it went onto printing the subarray twice (state) code link.

Also, is the time complexity of this approach is O(2^n)?

if u think of the question,
the base condition that comes to the mind is that if( start > end ) return;
it seems the condition if(start == end) is not kind of very generic like u cant think of this condition if u come across a unsamiliar question,
so i recommend u update the base condition as if( start > end) return and then have 2 calls
on in which just the end pointer is incremented and other in which both are incremented

Maybe, you didn’t read the question properly :sweat_smile: , the code you’ve shared also gave the wrong output.
For input

3
1 2 3

Output is


1 
1 2 
1 2 3 
2 3 
2 
2 3 
3 

2 3 repeated twice.

yup sorry,

so the logic of if(start == end) is that:
as soon as u encounter reach end of the array, it returns until from the condition start == end becomes true
we increment to start+1 till len of array [ all 0`s have been traversed now move to 1 index]
i have tried depicting it using indexed in the below image:

time complexity if O( N ^ 2)