-
Notifications
You must be signed in to change notification settings - Fork 3
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
aff7790
commit 9276f91
Showing
19 changed files
with
469 additions
and
57 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
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
32 changes: 32 additions & 0 deletions
32
CP Contests/CodeChef/Long Challenge/April Long Two 2022/SixFriends.cpp
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,32 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
void solution(){ | ||
int x,y; | ||
cin >> x >> y; | ||
|
||
if((x * 3) <= (y * 2)){ | ||
cout << (x*3) << "\n"; | ||
}else{ | ||
cout << (y*2) << "\n"; | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin >> t; | ||
while (t--) | ||
solution(); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Learning C++ with DSA/4. Arrays/Arrays problem for intterview/README.md
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
Learning C++ with DSA/4. Arrays/Arrays problem for intterview/level 1/Peak Elements/code.cpp
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
Learning C++ with DSA/4. Arrays/Questions/1. Delete at given index/code.cpp
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 <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
void deleteAtIndex(int* arr, int n, int x){ | ||
int i; | ||
for(i =0; i< n; i++) | ||
if(arr[i] == x) | ||
break; | ||
|
||
if(i == n) | ||
return; | ||
|
||
for(int j = i; j < n-1; j++) | ||
arr[j] = arr[j+1]; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
|
||
int arr[] = {3, 8, 12, 5, 6}; | ||
|
||
for(int i =0; i< 5; i++) | ||
cout << arr[i] << " "; | ||
|
||
deleteAtIndex(arr, 5, 12); | ||
|
||
cout << el; | ||
for(int i =0; i< 5; i++) | ||
cout << arr[i] << " "; | ||
|
||
return 0; | ||
} |
49 changes: 49 additions & 0 deletions
49
Learning C++ with DSA/4. Arrays/Questions/10. Leaders in an Array problem/code.cpp
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,49 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
//O(n*n) solution | ||
// void solution(){ | ||
// int n = 7; | ||
// int a[n] = {7, 10, 4, 3, 6, 5, 2}; | ||
|
||
// for (int i = 0; i < 7; i++){ | ||
// int j; | ||
// for(j = i+1; j < n; j++){ | ||
// if(a[i] < a[j]) | ||
// break; | ||
// } | ||
// if(j == n) | ||
// cout << a[i] << " "; | ||
// } | ||
// } | ||
|
||
//O(n) solution | ||
void solution(){ | ||
int n = 7; | ||
int a[n] = {7, 10, 4, 3, 6, 5, 2}; | ||
|
||
int max = 0; | ||
for (int i = n-1; i >= 0; i--){ | ||
if(a[i] > max){ | ||
max = a[i]; | ||
cout << max << " "; | ||
} | ||
} | ||
} | ||
|
||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin >> t; | ||
while (t--) | ||
solution(); | ||
|
||
return 0; | ||
} |
51 changes: 51 additions & 0 deletions
51
Learning C++ with DSA/4. Arrays/Questions/11. Maximum Difference Problem with Order/code.cpp
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 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
//Time Complexity : O(n*n) | ||
// void solution(){ | ||
// int n = 7; | ||
// int a[n] = {2, 3, 10, 6, 4, 8, 1}; | ||
|
||
// int ans = 0; | ||
// for (int i = 0; i < n; i++){ | ||
// for (int j = i+1; j < n; j++){ | ||
// if((a[j] - a[i]) > ans) | ||
// ans = a[j] - a[i]; | ||
// } | ||
// } | ||
// cout << ans; | ||
// } | ||
|
||
//Time Complexity : O(n) | ||
void solution(){ | ||
int n = 7; | ||
int a[n] = {2, 3, 10, 6, 4, 8, 1}; | ||
|
||
int min = a[0]; | ||
int max_diff = a[1] - a[0]; | ||
|
||
for (int i = 1; i < n; i++){ | ||
if((a[i] - min) > max_diff) | ||
max_diff = a[i] - min; | ||
|
||
if(a[i] < min) | ||
min = a[i]; | ||
} | ||
cout << max_diff; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin >> t; | ||
while (t--) | ||
solution(); | ||
|
||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
Learning C++ with DSA/4. Arrays/Questions/2. Largest index array/code.cpp
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,28 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
int largestIndex(int* arr, int n){ | ||
|
||
int ans = 0; | ||
for(int i = 0; i < n; i++) | ||
if(arr[ans] < arr[i]) | ||
ans = i; | ||
|
||
return ans; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
|
||
int arr[] = {3, 8, 12, 5, 6}; | ||
|
||
cout << largestIndex(arr, 5); | ||
|
||
return 0; | ||
} |
34 changes: 34 additions & 0 deletions
34
Learning C++ with DSA/4. Arrays/Questions/3. Second largest index/code.cpp
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,34 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
int secondLargestIndex(int* arr, int n){ | ||
|
||
int largest = 0; | ||
for(int i = 0; i < n; i++) | ||
if(arr[largest] < arr[i]) | ||
largest = i; | ||
|
||
int ans = 0; | ||
for(int i = 0; i < n; i++) | ||
if(arr[i] != arr[largest]) | ||
if(arr[ans] < arr[i]) | ||
ans = i; | ||
|
||
return ans; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
|
||
int arr[] = {5, 20, 12, 20, 10}; | ||
|
||
cout << secondLargestIndex(arr, 5); | ||
|
||
return 0; | ||
} |
31 changes: 31 additions & 0 deletions
31
Learning C++ with DSA/4. Arrays/Questions/4. Check if array is sorted or not/code.cpp
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,31 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
#define db double | ||
#define ld long double | ||
#define el "\n" | ||
|
||
bool secondLargestIndex(int* arr, int n){ | ||
if(n == 1) | ||
return true; | ||
|
||
int a = arr[0]; | ||
for(int i = 1; i < n; i++){ | ||
if(a > arr[i]) | ||
return false; | ||
a = arr[i]; | ||
} | ||
return true; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int arr[] = {100, 100}; | ||
int size = sizeof(arr)/sizeof(arr[0]); | ||
|
||
cout << (secondLargestIndex(arr, size) ? "Sorted" : "Not sorted") << el; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.