-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from yashagarwal1999/master
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...ine-wonders/cplusplus/yashagarwal1999_Largest _sum_of_consecutive_numbers_in_an_array.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; | ||
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; | ||
} |
30 changes: 30 additions & 0 deletions
30
honorary-one-line-wonders/cplusplus/yashagarwal1999_countingValley.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,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; | ||
} |
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,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)) |
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,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)) | ||
|
||
|