< Back to forum

in this question i am confused with the question language.,it has said that print length of longest correct prefix ,but not mention from starting ..so we can find from any place where maxx length is found ,,but it is accepting only length from starting... https://www.codechef.com/problems/COMPILER

#include <iostream>
#include <string.h>
#include<bits/stdc++.h>

using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		char A[1000002];
		scanf("%s",A);
		long long int x=strlen(A);
		long long int i,a=0,b=0,c;
		for(i=0; i<x; i++)
            {

		if(A[i]=='<')
        {
			a++;
		}

		else
		{
			a--;
		}

		if(a==0)
		{
				b=i+1;
		}

		else if(a<0)
		{
			break;
		}

		}

		cout<<b<<"\n";
	}
	return 0;
}

 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

As mentioned in the question, you need to find the longest correct "prefix". Prefix is always considered from the beginning of the expression and not from any arbitrary position.

Ruchi_Singh last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.