-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c42027
commit d509fe1
Showing
7 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
|
||
//Binery Search | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int findIndex(int a[], int n, int target) | ||
{ | ||
int low=0, mid, high=n-1; | ||
|
||
while(low<=high){ | ||
mid=(low+high)/2; | ||
|
||
if(a[mid]==target){ | ||
return mid; | ||
} | ||
else if(a[low]<=a[mid]){ | ||
if(target<=a[mid] && target >= a[low]){ | ||
high=mid-1; | ||
}else{ | ||
low=mid+1; | ||
} | ||
} | ||
else{ | ||
if(target>=a[mid] && target<=a[high]){ | ||
low=mid+1; | ||
}else{ | ||
high=mid-1; | ||
} | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
int main(){ | ||
int n; | ||
cin>>n; | ||
|
||
int a[n]; | ||
for (int i = 0; i < n; i++){ | ||
cin>>a[i]; | ||
} | ||
|
||
int target; | ||
cin>>target; | ||
|
||
cout<<findIndex(a,n,target); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
//Kandane's algorithum | ||
|
||
// #include <bits/stdc++.h> | ||
// using namespace std; | ||
|
||
// int main(){ | ||
// int n; | ||
// cin>>n; | ||
|
||
// int a[n]; | ||
|
||
// for(int i=0; i<n; i++){ | ||
// cin>>a[i]; | ||
// } | ||
|
||
// int max_sum = INT_MIN, current_sum=0; | ||
|
||
// for(int i=0; i<n; i++){ | ||
|
||
// current_sum = current_sum+a[i]; | ||
|
||
// if(current_sum > max_sum){ | ||
// max_sum = current_sum; | ||
// } | ||
// if(current_sum < 0){ | ||
// current_sum = 0; | ||
// } | ||
|
||
// } | ||
|
||
// cout<<max_sum<<endl; | ||
|
||
// return 0; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(){ | ||
int arr[]={1,2,3,4,5,6,7,8,9}; | ||
int n=9; | ||
int k=4; | ||
|
||
reverse(arr, arr+n-k); | ||
reverse(arr+n-k, arr+n); | ||
reverse(arr, arr+n); | ||
|
||
for(int i=0; i<n; i++){ | ||
cout<<arr[i]<<" "; | ||
} | ||
cout<<"\n"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
//function declaration | ||
void party (string); | ||
|
||
//function definition | ||
void party(string n){ | ||
cout<<"hey "<<n<<", welcome to our party\n"; | ||
cout<<"yeyy.. its fun\n"; | ||
} | ||
int main(){ | ||
string x="adi"; | ||
party(x); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
// #include <iostream> | ||
// using namespace std; | ||
|
||
// //function declaration | ||
// void multiply5(int&); | ||
|
||
// //function definition | ||
// void multiply5(int& a){ | ||
// a=a*5; | ||
// } | ||
|
||
// int main(){ | ||
// int x=10; | ||
// //function calling | ||
// multiply5(x); | ||
// cout<<x<<"\n"; | ||
// return 0; | ||
// } | ||
|
||
|
||
|
||
//all lower}else if(){ letters to upper }else if(){ | ||
|
||
|
||
|
||
// #include <iostream> | ||
// using namespace std; | ||
|
||
// //function definition | ||
// string stringConvert(string s){ | ||
// string res=s; | ||
// for(int i=0; i<s.length(); i++){ | ||
// if(s[i]-'A'>=0 && s[i]-'A'<= 25){ //big to small | ||
// res[i]=res[i]-'A'+'a'; | ||
// }else if(s[i]-'a'>=0 && s[i]-'a'<= 25){ //small to big | ||
// res[i]=res[i]-'a'+'A'; | ||
// } | ||
// } | ||
// return res; | ||
// } | ||
|
||
// int main(){ | ||
// string s="adithya&*&DSNFKJHDKSFKDSFKD"; | ||
// string res1=stringConvert(s); | ||
// cout<<res1<<"\n"; | ||
// return 0; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
int a=25; | ||
int *p=&a; | ||
cout<<a<<" "<<p<<" "<<&a<<" "<<*p<<"\n"; | ||
return 0; | ||
} | ||
|
||
|
||
//& adress print in void | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
char a=63; | ||
void* p=&a; | ||
|
||
cout<<p<<"\n"; | ||
|
||
return 0; | ||
} | ||
|
||
//* value print in void | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main(){ | ||
char a=63; | ||
void* p=&a; | ||
|
||
cout<<*(char*)p<<"\n"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(){ | ||
set<int> s; | ||
|
||
s.insert(4); | ||
s.insert(3); | ||
s.insert(1); | ||
s.insert(2); | ||
|
||
for(int element:s){ | ||
cout<<element<<"\n"; | ||
} | ||
|
||
cout<<"\n"; | ||
|
||
s.erase(3); | ||
|
||
for(int element:s){ | ||
cout<<element<<"\n"; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(){ | ||
int n; //length of the array | ||
cin>>n; | ||
|
||
int a[n]; //an array of length n | ||
|
||
for(int i=0; i<n; i++){ | ||
cin>>a[i]; | ||
} | ||
|
||
unordered_map<int,int> mp; | ||
|
||
int sum = 0, find_sub=0; | ||
|
||
for(int i=0;i<n;i++){ | ||
sum = sum+a[i]; | ||
|
||
if(sum==0){ | ||
find_sub = 1; | ||
} | ||
else{ | ||
if(mp[sum]>0){ | ||
find_sub = 1; | ||
}else{ | ||
mp[sum]++; | ||
} | ||
} | ||
} | ||
if(find_sub == 1){ | ||
cout<<"True"<<endl; | ||
}else{ | ||
cout<<"False"<<endl; | ||
} | ||
|
||
return 0; | ||
} |