Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create brackets.c #425

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keertanbhatt
Copy link

Let say you are building a compiler. The compiler you are building only understands angular brackets < and >. Since you must have already written a program in C, C++ or Java, you know that every opening curly bracket { should have corresponding closing } curly bracket else you get a compilation error.
Similary the compiler that you are building will give compilation error if every opening angular bracket < does not have a corresponding > closing bracket.
You aks your friends to write a program for this compiler using only angular brackets and they being a good friend have given you few codes. It might happen that if you compile the code it might give an error but if you compile its prefix it might run. Given a code you have to find the length of the longest prefix. In case no such prefix exists just output 00.
Note: <<><< ,>><< will give compilation error, while <>, <><><>, <<<>>> will not.

Example
Input
3
4
<<>>
2

<
4
<>>>
Output
4
0
2

Let say you are building a compiler. The compiler you are building only understands angular brackets < and >. Since you must have already written a program in C, C++ or Java, you know that every opening curly bracket { should have corresponding closing } curly bracket else you get a compilation error. 
Similary the compiler that you are building will give compilation error if every opening angular bracket < does not have a corresponding > closing bracket. 
You aks your friends to write a program for this compiler using only angular brackets and they being a good friend have given you few codes. It might happen that if you compile the code it might give an error but if you compile its prefix it might run. Given a code you have to find the length of the longest prefix. In case no such prefix exists just output 00.
Note: <<><< ,>><< will give compilation error, while <>, <><><>, <<<>>> will not.


Example
Input
3 
4
 <<>>
 2 
><
 4
 <>>>
Output
4
0
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant