Skip to content

Commit 2984c02

Browse files
author
ishan.gupta
committed
solved array questions from strivers sheet
1 parent 3a94369 commit 2984c02

File tree

10 files changed

+1235
-0
lines changed

10 files changed

+1235
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sol

Day-wise-sols/sol-1.cpp

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using namespace std;
2+
#include<iostream>
3+
#include<bits/stdc++.h>
4+
#define INT_min -999999
5+
#define ll long long int
6+
#define MAXSIZE 200
7+
#define ff first
8+
#define ss second
9+
10+
#ifndef ONLINE_JUDGE
11+
#define debug(x) cerr<<#x<<" ";_print(x);cerr<<endl;
12+
#else
13+
#define debug(x)
14+
#endif
15+
void _print(char n){cerr<<n;}
16+
void _print(int n){cerr<<n;}
17+
void _print(bool n){cerr<<n;}
18+
void _print(string n){cerr<<n;}
19+
void _print(long long int n){cerr<<n;}
20+
void _print(double n){cerr<<n;}
21+
22+
int MOD = 1e9+7;
23+
24+
ll add(ll x,ll y){ll res=x+y; return (res>=MOD ? res-MOD : res);}
25+
ll mul(ll x,ll y){ll res=x*y; return (res>=MOD ? res%MOD : res);}
26+
ll sub(ll x,ll y){ll res=x-y; return (res<0 ? res+MOD : res);}
27+
28+
// TO CALC MODULAR INVERSE (c=MOD)
29+
ll modRecc(ll a,ll b, ll c){
30+
//TC->O(log(b))
31+
//SC->O(log(b))->recursion stack
32+
if(b==0){
33+
return 1;
34+
}
35+
if(b%2==0){
36+
ll temp = modRecc(a,b/2,c);
37+
return ((temp %c)*(temp%c))%c;
38+
}
39+
else{
40+
ll temp = modRecc(a,b/2,c);
41+
return ((a%c)*(temp%c)*(temp%c))%c;
42+
}
43+
}
44+
//BOTH ABOVE AND BELOW ARE SAME BUT DIFF METHOD
45+
ll modIter(ll a,ll b,ll c){
46+
//TC->O(log(b))
47+
//SC->O(1) MORE OPTIMIZED
48+
ll ans = 1;
49+
while(b!=0){
50+
if(b&1){
51+
ans = ((ans%c) * (a%c))%c;
52+
}
53+
a = ((a%c)*(a%c))%c;
54+
b = b>>1;
55+
}
56+
return ans;
57+
}
58+
59+
//template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
60+
template<class T> void _print(vector<T> v){cerr << "[ "; for(T i:v) { _print(i) ; cerr << " ";}cerr<<"]";}
61+
template<class T> void _print(set<T> v){cerr<<"[ ";for(T i:v){_print(i);cerr<<" ";}cerr<<"]";}
62+
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {cerr<<"(";_print(i.ff);cerr<<",";_print(i.ss);cerr<<")"; cerr << " ";} cerr << "]";}
63+
64+
const int N = 1e7+7;
65+
vector<int> prime(N);
66+
67+
68+
// or use inbuilt __gcd() function
69+
int gcd(int n,int m){
70+
if(n%m==0 && n>=m) return m;
71+
else return gcd(m,n%m);}
72+
73+
int prime_till[N];
74+
75+
void seive(){
76+
for(int i = 2;i<N;i++){
77+
if(prime[i]==0){
78+
int j=2;
79+
while(i*j<=N){
80+
prime[i*j] = 1;
81+
j++;
82+
}}}}
83+
84+
void prime_t(){
85+
for(int i=2;i<N;i++){
86+
if(prime[i]==0){
87+
prime_till[i] = prime_till[i-1]+1;}
88+
else{
89+
prime_till[i] = prime_till[i-1];}}}
90+
91+
void no(){
92+
cout<<"-1"<<"\n";
93+
}
94+
95+
bool cmp(pair<int,int> a,pair<int,int> b){
96+
return a.first>b.first;}
97+
98+
void solve(){
99+
vector<vector<int>> v{
100+
{1, 2, 3},
101+
{4, 5, 6},
102+
{7, 8, 9}
103+
};
104+
for (int i = 0; i < 3;i++){
105+
for (int j = 0; j < i;j++)
106+
{
107+
swap(v[i][j], v[j][i]);
108+
}
109+
}
110+
111+
for (int i = 0; i < 3;i++){
112+
reverse(v[i].begin(), v[i].end());
113+
}
114+
115+
for (int i = 0; i < 3;i++){
116+
for (int j = 0; j < 3;j++){
117+
cout << v[i][j]<<" ";
118+
}
119+
cout << "\n";
120+
}
121+
}
122+
123+
int main(){
124+
#ifndef ONLINE_JUDGE
125+
freopen("error.txt","w",stderr);
126+
freopen("input.txt","r",stdin);
127+
freopen("output_.txt","w",stdout);
128+
#endif
129+
130+
cin.tie(NULL);
131+
cout.tie(NULL);
132+
ios_base::sync_with_stdio(false);
133+
int t;
134+
cin>>t;
135+
// prime_till[1]=0;
136+
// seive();
137+
// prime_t();
138+
t=1;
139+
while(t--){
140+
solve();
141+
cout<<"\n";
142+
}}
143+
144+
145+

Day-wise-sols/sol-2.cpp

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using namespace std;
2+
#include<iostream>
3+
#include<bits/stdc++.h>
4+
#define INT_min -999999
5+
#define ll long long int
6+
#define MAXSIZE 200
7+
#define ff first
8+
#define ss second
9+
10+
#ifndef ONLINE_JUDGE
11+
#define debug(x) cerr<<#x<<" ";_print(x);cerr<<endl;
12+
#else
13+
#define debug(x)
14+
#endif
15+
void _print(char n){cerr<<n;}
16+
void _print(int n){cerr<<n;}
17+
void _print(bool n){cerr<<n;}
18+
void _print(string n){cerr<<n;}
19+
void _print(long long int n){cerr<<n;}
20+
void _print(double n){cerr<<n;}
21+
22+
int MOD = 1e9+7;
23+
24+
ll add(ll x,ll y){ll res=x+y; return (res>=MOD ? res-MOD : res);}
25+
ll mul(ll x,ll y){ll res=x*y; return (res>=MOD ? res%MOD : res);}
26+
ll sub(ll x,ll y){ll res=x-y; return (res<0 ? res+MOD : res);}
27+
28+
// TO CALC MODULAR INVERSE (c=MOD)
29+
ll modRecc(ll a,ll b, ll c){
30+
//TC->O(log(b))
31+
//SC->O(log(b))->recursion stack
32+
if(b==0){
33+
return 1;
34+
}
35+
if(b%2==0){
36+
ll temp = modRecc(a,b/2,c);
37+
return ((temp %c)*(temp%c))%c;
38+
}
39+
else{
40+
ll temp = modRecc(a,b/2,c);
41+
return ((a%c)*(temp%c)*(temp%c))%c;
42+
}
43+
}
44+
//BOTH ABOVE AND BELOW ARE SAME BUT DIFF METHOD
45+
ll modIter(ll a,ll b,ll c){
46+
//TC->O(log(b))
47+
//SC->O(1) MORE OPTIMIZED
48+
ll ans = 1;
49+
while(b!=0){
50+
if(b&1){
51+
ans = ((ans%c) * (a%c))%c;
52+
}
53+
a = ((a%c)*(a%c))%c;
54+
b = b>>1;
55+
}
56+
return ans;
57+
}
58+
59+
//template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
60+
template<class T> void _print(vector<T> v){cerr << "[ "; for(T i:v) { _print(i) ; cerr << " ";}cerr<<"]";}
61+
template<class T> void _print(set<T> v){cerr<<"[ ";for(T i:v){_print(i);cerr<<" ";}cerr<<"]";}
62+
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {cerr<<"(";_print(i.ff);cerr<<",";_print(i.ss);cerr<<")"; cerr << " ";} cerr << "]";}
63+
64+
const int N = 1e7+7;
65+
vector<int> prime(N);
66+
67+
68+
// or use inbuilt __gcd() function
69+
int gcd(int n,int m){
70+
if(n%m==0 && n>=m) return m;
71+
else return gcd(m,n%m);}
72+
73+
int prime_till[N];
74+
75+
void seive(){
76+
for(int i = 2;i<N;i++){
77+
if(prime[i]==0){
78+
int j=2;
79+
while(i*j<=N){
80+
prime[i*j] = 1;
81+
j++;
82+
}}}}
83+
84+
void prime_t(){
85+
for(int i=2;i<N;i++){
86+
if(prime[i]==0){
87+
prime_till[i] = prime_till[i-1]+1;}
88+
else{
89+
prime_till[i] = prime_till[i-1];}}}
90+
91+
void no(){
92+
cout<<"-1"<<"\n";
93+
}
94+
95+
bool cmp(pair<int,int> a,pair<int,int> b){
96+
return a.first>b.first;}
97+
98+
void solve(){
99+
vector<pair<int, int>> vp;
100+
vector<vector<int>> v{
101+
{1, 3}, {2, 4}, {2, 6}, {8, 9}, {8, 10}, {9, 11}, {15, 18}, {16, 17}};
102+
sort(v.begin(), v.end());
103+
for (int i = 0; i < v.size() ;i++){
104+
if(vp.empty()){
105+
vp.push_back(make_pair(v[i][0], v[i][1]));
106+
}else{
107+
if(v[i][0]<vp[vp.size()-1].second && v[i][1]<vp[vp.size()-1].second){
108+
continue;
109+
}
110+
else if(v[i][0]<vp[vp.size()-1].second && v[i][1]>vp[vp.size()-1].second){
111+
vp[vp.size() - 1].second = v[i][1];
112+
}
113+
else{
114+
vp.push_back(make_pair(v[i][0], v[i][1]));
115+
}
116+
}
117+
}
118+
for (int i = 0; i < vp.size();i++){
119+
cout << vp[i].first << " " << vp[i].second;
120+
cout << "\n";
121+
}
122+
}
123+
124+
int main(){
125+
#ifndef ONLINE_JUDGE
126+
freopen("error.txt","w",stderr);
127+
freopen("input.txt","r",stdin);
128+
freopen("output_.txt","w",stdout);
129+
#endif
130+
131+
cin.tie(NULL);
132+
cout.tie(NULL);
133+
ios_base::sync_with_stdio(false);
134+
int t;
135+
// cin>>t;
136+
// prime_till[1]=0;
137+
// seive();
138+
// prime_t();
139+
t=1;
140+
while(t--){
141+
solve();
142+
cout<<"\n";
143+
}}
144+
145+
146+

0 commit comments

Comments
 (0)