Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching algorithms milestone #62

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
90a71a2
Create Acche_Din.cpp
santushtisharma10 Jun 17, 2020
4900ab0
Create Mark_The_Answer.cpp
santushtisharma10 Jun 17, 2020
2eb24d8
Create SnackDown_Contest.cpp
santushtisharma10 Jun 17, 2020
84036ae
Create Monk_And_Rotation.cpp
santushtisharma10 Jun 17, 2020
a496cd0
Create Speed.cpp
santushtisharma10 Jan 12, 2021
7b7fb3a
Create Sumit's_love_for_maths.cpp
santushtisharma10 Jan 12, 2021
e32229d
Create 2arrays.cpp
santushtisharma10 Jan 12, 2021
5175002
Create Perfect_Subarray.cpp
santushtisharma10 Jan 12, 2021
b258fae
Create Modify_Sequence.cpp
santushtisharma10 Jan 12, 2021
061c225
Create Maximum_Of_K-size_subarrays.cpp
santushtisharma10 Jan 12, 2021
966533e
Create Strange_Game.cpp
santushtisharma10 Jan 12, 2021
614325b
Create Maximise_the_earning
santushtisharma10 Jan 12, 2021
efae0c1
Create Pepper_and_Contiguous_Even_Subarray.cpp
santushtisharma10 Jan 12, 2021
c070d9d
Create Takeoff.cpp
santushtisharma10 Jan 12, 2021
7cf11e7
Create Long_ATM_Queue.cpp
santushtisharma10 Jan 12, 2021
ef8be85
Create Monk_and_Power_of_Time.cpp
santushtisharma10 Jan 12, 2021
9e0b4a3
Create Polygon_Possiblity.cpp
santushtisharma10 Jan 12, 2021
3d14b23
Create Charged_Up_Array.cpp
santushtisharma10 Jan 12, 2021
574ba68
Create Hamiltonian_and_Lagrangian.cpp
santushtisharma10 Jan 12, 2021
2bec9b6
Create Micro_and_Array_Update.cpp
santushtisharma10 Jan 12, 2021
3877db7
Create Submatrix_Updates.cpp
santushtisharma10 Jan 12, 2021
00b1d58
Create Priority_Interview.cpp
santushtisharma10 Jan 12, 2021
0589bf4
Create Grid_and_Phase.cpp
santushtisharma10 Jan 12, 2021
e341f54
Create Find_The_String.cpp
santushtisharma10 Jan 12, 2021
c072810
Create Add_Alternate_Elements.cpp
santushtisharma10 Jan 12, 2021
b90c9ab
Create Roy_and_Symmetric_Logos.cpp
santushtisharma10 Jan 12, 2021
dae0c72
Create Easy_Sum_Set_Problem.cpp
santushtisharma10 Jan 17, 2021
68501d4
Create Hexadecimal_numbers.cpp
santushtisharma10 Jan 17, 2021
152bf4e
Create Maximum_Sum.cpp
santushtisharma10 Jan 17, 2021
11c4f92
Create Simple_Search.cpp
santushtisharma10 Jan 18, 2021
85e1321
Create Manna's_First_Name.cpp
santushtisharma10 Jan 18, 2021
a205627
Create Min-Max.cpp
santushtisharma10 Jan 18, 2021
e3e793f
Create Square_Transaction.cpp
santushtisharma10 Jan 18, 2021
e78b133
Create Golden_Rectangles.cpp
santushtisharma10 Jan 18, 2021
2c981b9
Create Repeated_K_Times.cpp
santushtisharma10 Jan 20, 2021
eb709b2
Create Rest_in_peace.cpp
santushtisharma10 Jan 20, 2021
9883610
Create Will_She_Accept_Him?.cpp
santushtisharma10 Jan 20, 2021
4af5a47
Create Bishu_and_soldiers.cpp
santushtisharma10 Feb 3, 2021
7295f9b
Create Discover_The_Monk.cpp
santushtisharma10 Feb 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Santushti/1d_Array_milestone/Hackerearth_Questions/2arrays.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long t=0,k=0,n,s1=0,s2=0 ;

cin>>n;

long long a[n],b[n];

for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]==-1)
t++;

else
s1+=a[i];
}

for(int i=0;i<n;i++)
{
cin>>b[i];

if(b[i]==-1)
k++;

else
s2+=b[i];
}

if(t==k )
cout<<"Infinite";

else if(t==1 || k==1)
{
if(t==1 && s1>s2)
cout<<"0";

else if(k==1 && s2>s1)
cout<<"0";

else
cout<<"1";
}
else
{
if(t==2 && s1>s2)
cout<<"0";

else if(k==2 && s2>s1)
cout<<"0";

else
{

if(s1==s2)
cout<<"1";

else
cout<<abs(s1-s2)+1;
}

}

return 0;
}

50 changes: 50 additions & 0 deletions Santushti/1d_Array_milestone/Hackerearth_Questions/Acche_Din.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;

int main() {

long long t;

cin>>t;

while(t--) {

long long n;

cin>>n;

long long a[n], k[n];

for(int i = 0; i < n; ++i) {

cin>>a[i];
}

multiset<int> s(a,a+n);

for(int i = 0; i < n; ++i) {

k[i] = s.count(a[i]);

if(k[i] == 1) {

cout<<a[i]<<"\n";
break;
}
}
}
return 0;
}
/*

SAMPLE INPUT
------------
1
7
1 2 2 1 2 1 4

SAMPLE OUTPUT
-------------
4

*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
long long int t,n,m=1000000007;

cin>>t;

for(int i=0;i<t;i++)
{
cin>>n;

long long int a[n];

for(int j=0;j<n;j++)
cin>>a[j];

long long int charge=0;
long long int p=pow(2,n-1);

if(n>=64)
cout<<"0\n";

else
{
for(int j=0;j<n;j++)
{
if(a[j]>=p)
charge=(a[j]%m+charge)%m;
}

cout<<charge%m<<"\n";
}
}


return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<iostream>
using namespace std;
int main()
{

long long n,h[1000000],max;


cin>>n;

for(long long i=0;i<n;i++)
cin>>h[i];

max=h[n-1];

long long g[n],c=1;

for(int i=0;i<n;i++)
g[i]=-1;

g[0]=max;

for(int i=n-2;i>=0;i--)
{
if(h[i]>=max)
{
g[c]=h[i];
c++;
max=h[i];

}
}

for(int i=c-1;i>=0;i--)
cout<<g[i]<<" ";

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;
int main()
{
long long n,h[1000000];
int x=1;

cin>>n;

for(int i=0;i<n;i++)
cin>>h[i];

for(int i=0;i<n-1;i++)
{
if(h[i]>h[i+1])
x++;


}

cout<<x<<endl;

return 0;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;

int main() {

int n, k, a[100000];

int x = 0;

int t = 0;

cin>>n>>k;

for(int i = 0; i < n; ++i) {

cin>>a[i];
}

for(int i = 0; i < n; ++i) {

if(a[i] <= k) {

t++;
}
else {

x++;

if(x > 1) {

break;
}
}
}
cout<<t;

return 0;
}
/*

SAMPLE INPUT
------------
7 6
4 3 7 6 7 2 2

SAMPLE OUTPUT
-------------
3

*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
using namespace std;
int main()
{long long s,r,n,h[10000001];
cin>>s;
for(int i=0;i<s;i++)
{
cin>>n>>r;
int c=1;
int t=1;
int l=0;
int sum=0;
for(int j=0;j<n;j++)
cin>>h[j];
while(l+t<n)
{
if(h[l]<h[l+t])
{
c++;
l+=t;
t=1;
}

else
t++;
}

sum=(r*c);
cout<<sum<<endl;

}
return 0;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<iostream>
using namespace std;
int main()
{
long long k,n,a[1000000],max;

cin>>n>>k;

for(int i=0;i<n;i++)
cin>>a[i];

for(int i=0;i<n-k+(1);i++)
{
max=a[i];

for(int j=i;j<k+i;j++)
{
if(max<a[j])
max=a[j];
}

cout<<max<<" ";
}

return 0;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<iostream>
using namespace std;
int main()
{

long long t,min,n,k,str[n];

cin>>t;
if(t>=1&&t<=5)
{
for(long long int i=0;i<t;i++)
{
cin>>n>>k;

for(long long int j=0;j<n;j++)
cin>>str[j];

min=str[0];

for(long long int j=0;j<n;j++)
{
if(min>=str[j])
min=str[j];
}

if(min>=k)
cout<<"0"<<endl;

else
cout<<k-min<<endl;
}
}

return 0;
}
Loading