heyy guys hope u all r doing well in this critical time; so basically what is a subarray ? Subarray is the samller part of the array(it cab ...
heyy guys hope u all r doing well in this critical time;
so basically what is a subarray ?
Subarray is the samller part of the array(it cab be full array also) .in this we study about the continious subarray :
time complexity :
o(NCUBE) , further we we will see this in o(n) and o(nsqaure) :-
Question : how to gernate all the subarray
solution :
#include <bits/stdc++.h>
using namespace std ;
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("outp.txt", "w", stdout);
#endif
int n;cin>>n;
vector<int> v1(n);
for(int i = 0 ; i<n ; ++i){
cin>>v1[i];
}
for(int i = 0 ; i<n ; ++i){
for(int j= i; j<n; ++j){
for(int k = i ; k<=j; ++k ){
cout<<v1[k];
}
cout<<endl;
}
}
}
===============================================
input: 5
1 2 3 4 5
output:
1
12
123
1234
12345
2
23
234
2345
3
34
345
4
45
5
the link of the video tutorial for better understanding :