Thank you so much sir.
Thanks. I saw your post but forgot to reply. today i just happened to pass by and noticed it
I think <<> should give 0 ?
Yep
Solution adjusted accordingly…but still getting WA for some test case…Can you visualise any such case?
CodeChef: Practical coding for everyone.
MW it passed the <<> case
Consider the test input:
1
<><
///maybe this is what you asked
#include <bits/stdc++.h>
#include
#include
#define ll long long int
using namespace std;
bool func(string s,int i,int j)
{
stack<char> stk;
for(;i<=j;i++)
{
if(s[i]=='<')
stk.push(s[i]);
else
{ if(stk.empty()||stk.top()!='<')
return false;
else
stk.pop();
}
}
return stk.empty();
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t–)
{
string s;
cin>>s;
stack stk;
vector v;
for(int i=0;i<s.length();i++)
{
if(s[i]=='<')
{
for(int j=i+1;j<s.length();j++)
{
if(s[j]=='>')
{
if(func(s,i,j)==true)////if(func(s,i+1,j-1)==true)
v.push_back(j-i+1);
}
}
}
}
if(v.size()==0)
cout<<"0\n";
else
cout<<*max_element(v.begin(),v.end())<<"\n";
}
}
Can anyone please explain what is longest prefix length means it’s confusing please break it in simple terms.
Thanks
Can anyone tell me why this is not working?
#include <iostream>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
string s;
cin>>s;
int open=0,num=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='<')
{
open++;
}
else
{
if(open>0)
{
open--;
num++;
}
}
}
cout<<num*2<<endl;
}
}
can any one tell me why i am getting a WA
I can’t see anything incorrect about it - are you sure you’ve submitted it correctly? Can you link to the submission that gives WA?
Edit:
None of your six submissions:
https://www.codechef.com/viewsolution/32933182
https://www.codechef.com/viewsolution/32932987
https://www.codechef.com/viewsolution/32932685
https://www.codechef.com/viewsolution/32931702
https://www.codechef.com/viewsolution/32931591
https://www.codechef.com/viewsolution/32931353
match the code given in your link.
what should be the output for this testcase?
2?
https://www.codechef.com/viewsolution/33184548
This is my code. Where am I going wrong?
Please help.
The answer for the test input:
1
<><
should be 2
, yes.
Your solution fails on the following testcase:
1
<<><
1
>
(your code has an out-of-bounds access on this test input).
ok
already consider
While solving the problem, I had a doubt, will be grateful if answered. What should be the output for the input, “<><<<>>>”?