Skip to content

Commit

Permalink
Added new question in array section
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranSiddhu committed Apr 27, 2022
1 parent aff7790 commit 9276f91
Show file tree
Hide file tree
Showing 19 changed files with 469 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ using namespace std;
#define el "\n"

void solution(){
int n;
cin >> n;

for(int i = 1; i < n; i++)
cout << i+1 << " ";
int bill;
cin >> bill;

int c1 = 100;
int c2 = bill / 10;

if(c1 > c2)
cout << c1 << "\n";
else
cout << c2 << "\n";

cout << 1 << el;
}

int main(){
Expand All @@ -25,4 +29,4 @@ int main(){
solution();

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@ using namespace std;
#define el "\n"

void solution(){
int n;
cin >> n;
int a, b;
cin >> a >> b;

for (int i = 1; i <= n; i++){
if (n == 1){
cout << "3";
break;
}
int e1 = a * 10;
int e2 = b * 5;

if (i == 1)
cout << 1;
else if (i == n)
cout << 5;
else
cout << 0;
}

cout << el;
if (e1 == e2)
cout << "ANY" << el;
else if (e1 > e2)
cout << "FIRST" << el;
else
cout << "SECOND" << el;
}

int main(){
Expand Down
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;
}
1 change: 0 additions & 1 deletion CodeChef Self-Learning/README.md

This file was deleted.

This file was deleted.

This file was deleted.

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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
Loading

0 comments on commit 9276f91

Please sign in to comment.