Skip to content

Commit 2a94f1d

Browse files
authored
π…π’π§πšπ₯ 𝐏𝐫𝐨𝐣𝐞𝐜𝐭
1 parent f1c02ae commit 2a94f1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1662
-0
lines changed

β€ŽBostonNumber

55 KB
Binary file not shown.

β€ŽBostonNumber.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// BostonNumber
2+
#include<iostream>
3+
#include<cmath>
4+
#include<vector>
5+
using namespace std;
6+
7+
int digitKaSum(int n){
8+
9+
int sum=0;
10+
while(n){
11+
12+
sum+=n%10;
13+
n/=10;
14+
15+
}
16+
return sum;
17+
}
18+
19+
int sumOfFactors(int n){
20+
21+
int sum=0;
22+
23+
for(int i=2;i<=sqrt(n);i++){
24+
while(n%i==0){
25+
sum+=digitKaSum(i);
26+
n/=i;
27+
}
28+
}
29+
30+
if(n>0){
31+
sum+=digitKaSum(n);
32+
}
33+
34+
return sum;
35+
36+
}
37+
38+
int main(){
39+
40+
int num;
41+
cin>>num;
42+
43+
if(digitKaSum(num)==sumOfFactors(num)){
44+
cout<<"1"<<endl;
45+
}else{
46+
cout<<"0";
47+
}
48+
49+
50+
return 0;
51+
}

β€ŽLinkedList

55.6 KB
Binary file not shown.

β€ŽLinkedList.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class node{
5+
public:
6+
7+
int data;
8+
node*next;
9+
10+
node(int d){
11+
data=d;
12+
next=NULL;
13+
}
14+
15+
};
16+
17+
class linkedList{
18+
19+
node*head;
20+
node*tail;
21+
22+
23+
public:
24+
25+
// Constructor
26+
linkedList(){
27+
head=NULL;
28+
tail=NULL;
29+
}
30+
31+
// Copy Constructor
32+
linkedList(linkedList &l){
33+
cout<<"Copy Constructor Called"<<endl;
34+
head=l.head;
35+
tail=l.tail;
36+
}
37+
38+
39+
// Copy Assignment Operator
40+
void operator = (linkedList l){
41+
cout<<"Copy Assignment operator Called"<<endl;
42+
head=l.head;
43+
tail=l.tail;
44+
}
45+
46+
47+
void insertInLL(int d){
48+
if(head==NULL){
49+
node*n=new node(d);
50+
head=tail=n;
51+
}else{
52+
node*n=new node(d);
53+
tail->next=n;
54+
tail=n;
55+
}
56+
}
57+
58+
void print(){
59+
60+
node*temp=head;
61+
62+
while(temp!=NULL){
63+
cout<<temp->data<<" ";
64+
temp=temp->next;
65+
}
66+
cout<<endl;
67+
}
68+
69+
70+
// Destructor
71+
~linkedList(){
72+
cout<<"Destroying the LinkedList"<<endl;
73+
}
74+
};
75+
76+
int main(){
77+
78+
node a(1);
79+
node b(2);
80+
81+
node *p=&a;
82+
83+
a.next=&b;
84+
85+
// use of arrow operator
86+
87+
cout<<((*a.next).data)<<endl;
88+
cout<<a.next->data<<endl;
89+
cout<<p->data<<endl;
90+
91+
92+
linkedList l;
93+
94+
l.insertInLL(1);
95+
l.insertInLL(2);
96+
l.insertInLL(3);
97+
l.insertInLL(4);
98+
l.insertInLL(5);
99+
l.insertInLL(6);
100+
l.insertInLL(7);
101+
102+
l.print();
103+
104+
linkedList m;
105+
106+
m=l;
107+
108+
109+
110+
return 0;
111+
}

β€ŽLongestMountain

59.6 KB
Binary file not shown.

β€ŽLongestMountain.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include<iostream>
2+
#include<vector>
3+
#include<algorithm>
4+
using namespace std;
5+
6+
int max(int a,int b){
7+
8+
return a<b?b:a;
9+
}
10+
11+
int solve(int *a,int n){
12+
13+
vector<int>s;
14+
int m=0;
15+
16+
s.push_back(a[0]);
17+
int flag=0;
18+
int sflag=0;
19+
20+
for(int i=1;i<n;i++){
21+
int curr=a[i];
22+
23+
if(s[s.size()-1]<curr){
24+
25+
if(sflag==1){
26+
m=max(s.size(),m);
27+
int temp=s[s.size()-1];
28+
s.clear();
29+
s.push_back(temp);
30+
s.push_back(curr);
31+
sflag=0;
32+
}else{
33+
s.push_back(curr);
34+
flag=1;
35+
}
36+
37+
}
38+
39+
else if(flag==0&&s[s.size()-1]>curr){
40+
s.clear();
41+
s.push_back(curr);
42+
}
43+
44+
else if(s[s.size()-1]==curr){
45+
s.clear();
46+
s.push_back(curr);
47+
sflag=0;
48+
flag=0;
49+
}
50+
51+
else if(flag==1&&s[s.size()-1]>curr){
52+
s.push_back(curr);
53+
m=max(m,s.size());
54+
sflag=1;
55+
}
56+
}
57+
58+
if(m<3){
59+
return 0;
60+
}
61+
62+
return m;
63+
}
64+
65+
int main(){
66+
67+
// int a[]={2,1,4,7,3,2,5,6,8,9,12,10,9,8,7,8,9,12,2};
68+
int a[]={2,3,3,2,0,2};
69+
int n=sizeof(a)/sizeof(int);
70+
71+
cout<<solve(a,n)<<endl;
72+
73+
74+
75+
return 0;
76+
}

β€Ža.out

54.6 KB
Binary file not shown.

β€Žbasic_calculator

16.1 KB
Binary file not shown.

β€Žbasic_calculator.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include<iostream>
2+
#include<vector>
3+
#include<algorithm>
4+
#include<unordered_map>
5+
#include<map>
6+
#include<stack>
7+
#include<queue>
8+
#include<set>
9+
#include<cstring>
10+
#include<cmath>
11+
12+
using namespace std;
13+
14+
#define int long long int
15+
16+
class Solution {
17+
public:
18+
int calculate(string s) {
19+
stack<int> stk;
20+
char sign= '+';
21+
int res= 0, tmp= 0;
22+
for(int i= 0; i< s.length(); i++){
23+
if(isdigit(s[i]))
24+
tmp= 10*tmp+s[i]-'0';
25+
if(!isdigit(s[i]) && !isspace(s[i]) || i == s.length()-1){
26+
if(sign == '-')
27+
stk.push(-tmp);
28+
else if(sign == '+')
29+
stk.push(tmp);
30+
else{
31+
int num;
32+
if(sign == '*')
33+
num= stk.top()*tmp;
34+
else
35+
num= stk.top()/tmp;
36+
stk.pop();
37+
stk.push(num);
38+
}
39+
sign= s[i];
40+
tmp= 0;
41+
}
42+
}
43+
while(!stk.empty()){
44+
res+= stk.top();
45+
stk.pop();
46+
}
47+
return res;
48+
}
49+
};
50+
51+
int32_t main(){
52+
53+
54+
55+
return 0;
56+
}

β€Žbfs

181 KB
Binary file not shown.

β€Žbfs.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include<iostream>
2+
#include<list>
3+
#include<unordered_map>
4+
#include<queue>
5+
#include<map>
6+
#include<climits>
7+
using namespace std;
8+
9+
class graph{
10+
11+
unordered_map<int,list<int> >mp;
12+
13+
14+
public:
15+
16+
17+
18+
void addEdge(int u,int v){
19+
mp[u].push_back(v);
20+
mp[v].push_back(u);
21+
22+
}
23+
24+
void print(){
25+
26+
for(auto x:mp){
27+
cout<<x.first<<"-->";
28+
for(auto y:x.second){
29+
cout<<y<<" ";
30+
}
31+
cout<<endl;
32+
}
33+
}
34+
35+
void SSSP(int src){
36+
37+
map<int,int>dist;
38+
39+
for(auto x:mp){
40+
dist[x.first]=INT_MAX;
41+
}
42+
43+
queue<int>Q;
44+
45+
dist[src]=0;
46+
Q.push(src);
47+
48+
while(!Q.empty()){
49+
50+
int node=Q.front();
51+
cout<<node<<" ";
52+
Q.pop();
53+
54+
for(auto nbr:mp[node]){
55+
if(dist[nbr]==INT_MAX){
56+
dist[nbr]=1+dist[node];
57+
Q.push(nbr);
58+
}
59+
}
60+
61+
}
62+
63+
for(auto x:dist){
64+
cout<<x.first<<"-->"<<x.second<<endl;
65+
}
66+
67+
}
68+
69+
70+
71+
72+
};
73+
74+
int main(){
75+
76+
77+
graph g;
78+
79+
g.addEdge(0,1);
80+
g.addEdge(0,2);
81+
g.addEdge(1,2);
82+
g.addEdge(1,3);
83+
g.addEdge(1,4);
84+
g.addEdge(3,4);
85+
g.addEdge(4,5);
86+
87+
88+
// g.print();
89+
g.SSSP(0);
90+
91+
92+
return 0;
93+
}

β€Žbimasking

54.9 KB
Binary file not shown.

0 commit comments

Comments
Β (0)