Skip to content

Commit

Permalink
Merge pull request #412 from yashagarwal1999/master
Browse files Browse the repository at this point in the history
Solved #162 #96 #78 #323
  • Loading branch information
kannagikazuko authored Oct 30, 2019
2 parents 4a12794 + 5ed7701 commit b097d97
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
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;
}
3 changes: 3 additions & 0 deletions python/approximate_pi/yashagarwal1999_get_Approximate_Pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pi=lambda get_approx_pi:4 * sum(-float(k%4 - 2) / k for k in range(1, 2*val+1, 2))
val=int(input('Number of iterations'))
print(pi(val))
9 changes: 9 additions & 0 deletions python/unique/yashagarwal1999_unique_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def uni(arr):
li=[]
[li.append(i) for i in arr if not li.count(i)]
return li

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


0 comments on commit b097d97

Please sign in to comment.