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

Solved #162 #404

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
pair<ll,ll> maxsum(ll arr[],ll n)
{
ll sum=0;
ll max=0;
pair<ll,ll>p;
ll x=0,y=0;
for(ll i=0;i<n;i++)
{
sum+=arr[i];
if(sum>max){max=sum;y=i;}
if(sum<0){sum=0;x=i+1;}

}
p.first=x;
p.second=y;
return p;
}

int main()
{
int n;
cin>>n;
ll arr[n];
for(ll i=0;i<n;i++)cin>>arr[i];
pair<ll,ll>p=maxsum(arr,n);
cout<<p.first<<" "<<p.second<<endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int countingValleys(int n, string s) {


int sum=0;
if(s[0]=='U')sum++;
else sum--;
int count=0;
if(sum<0)count++;
for(int i=1;i<n;i++)
{
if(s[i]=='D')sum--;
else sum++;
if(s[i]=='D' && sum==-1)count++;
}
return count;

}

int main()
{
int n;
cin>>n;
string s;
cin>>s;
cout<<countingValleys(n,s)<<endl;
return 0;
}
11 changes: 11 additions & 0 deletions honorary-one-line-wonders/python/yashagarwal1999_unique_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def getunique(arr):
finallist=[]
for i in arr:
if(i not in finallist):
finallist.append(i);
return finallist

list1 = [10, 20, 10, 30, 40, 40]
print(getunique(list1))


10 changes: 10 additions & 0 deletions python/unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def getunique(arr):
finallist=[]
for i in arr:
if(i not in finallist):
finallist.append(i);
return finallist

list1 = [10, 20, 10, 30, 40, 40]
print(getunique(list1))

4 changes: 4 additions & 0 deletions python/yashagarwal1999_getApproximatePiValue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def get_approx_pi(val):
return 4 * sum(-float(k%4 - 2) / k for k in range(1, 2*val+1, 2))

print(get_approx_pi(2000))