Help in the problem, two pointers 2G #1
Unanswered
quantavoid11
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can anyone help me solve this problem, I have coded it using stack but it's giving the wrong answer on some test case.
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli gcd(lli a, lli b)
{
if (a % b == 0)
return b;
return gcd(b, a % b);
}
class stk
{
stack<pair<lli, lli>> st;
public:
stk()
{
}
void push(lli val)
{
lli elem = st.empty() ? val : gcd(val, st.top().second);
st.push({val, elem});
}
void pop()
{
st.pop();
}
pair<lli, lli> top()
{
return st.top();
}
int size()
{
return st.size();
}
};
void remove(stk &st1, stk &st2)
{
}
int main()
{
}
Here is my implementation for the same.
Beta Was this translation helpful? Give feedback.
All reactions