Skip to content

Commit 4933a2f

Browse files
committed
leetcode
1 parent a05e73a commit 4933a2f

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
long long a,b,x,y;
12+
cin>>a>>b>>x>>y;
13+
long long hcf=__gcd(x,y);
14+
x/=hcf;
15+
y/=hcf;
16+
cout<<min({a/x,b/y})<<endl;
17+
return 0;
18+
}
19+
int main()
20+
{
21+
int testCase=1;
22+
while(testCase--){
23+
solve();
24+
}
25+
return 0;
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
int parity(int n){
10+
if(n%2==0){
11+
return 0;
12+
}
13+
else{
14+
return 1;
15+
}
16+
}
17+
18+
int solve(){
19+
int n;
20+
cin>>n;
21+
stack<int> s;
22+
vector<int> v(n);
23+
for(int i=0;i<n;i++){
24+
cin>>v[i];
25+
}
26+
s.push(v[0]);
27+
for(int i=1;i<n;i++){
28+
if(parity(s.top())==parity(v[i])){
29+
int temp=s.top();
30+
s.pop();
31+
s.push(temp*v[i]);
32+
}
33+
else{
34+
s.push(v[i]);
35+
}
36+
}
37+
cout<<n-s.size()<<endl;
38+
return 0;
39+
}
40+
int main()
41+
{
42+
int testCase=1;
43+
cin>>testCase;
44+
while(testCase--){
45+
solve();
46+
}
47+
return 0;
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
long long minOperations(vector<int> &nums1, vector<int> &nums2, int k)
15+
{
16+
if(k==0){
17+
return nums1==nums2?0:-1;
18+
}
19+
long long countPos=0,countNeg=0;
20+
for(int i=0;i<nums1.size();i++){
21+
long long diff=nums1[i]-nums2[i];
22+
if(diff%k){
23+
return -1;
24+
}
25+
else if(diff>0){
26+
countPos+=diff/k;
27+
}
28+
else{
29+
countNeg+=diff/k;
30+
}
31+
32+
}
33+
if(countPos+countNeg==0){
34+
return countPos;
35+
}
36+
else{
37+
return -1;
38+
}
39+
}
40+
};

0 commit comments

Comments
 (0)