🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"DIRECTN","problem_name":"Professor And Directions","problemComponents":{"constraints":"- $1 \\leq T \\leq 100$\n- $2 \\leq N \\leq 10^5$\n- The string $S$ consists of uppercase characters `\u0027L\u0027` and `\u0027R\u0027` only.\n- The sum of $N$ over all test cases does not exceed $10^6$.","constraintsState":true,"subtasks":"","subtasksState":false,"inputFormat":"- The first line contains an integer $T$ denoting the number of test cases. The $T$ test cases then follow.\n- The first line of each test case contains $N$.\n- The second line contains a string that contains only `\u0027L\u0027` and `\u0027R\u0027`, where `\u0027L\u0027` represents left and `\u0027R\u0027` represents right.","inputFormatState":true,"outputFormat":"For each test case, output `\u0022YES\u0022` if the Professor will be able to save Tokyo and `\u0022NO\u0022` otherwise.\n\nOutput is case insensitive, which means that \u0022yes\u0022, \u0022Yes\u0022, \u0022YEs\u0022, \u0022no\u0022, \u0022nO\u0022 - all such strings will be acceptable.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"3\n12\nLRLRRRLRLLLL\n2\nLR\n4\nLRRL\n","output":"YES\nNO\nYES\n","explanation":"**Test case $1$**: Professor can select the substring `\u0022RLRLLL\u0022`, after following the instructions given by it, Professor will face South.\n\n**Test case $2$**: No matter which substring Professor selects, the final direction of Professor will never be that in which Tokyo is facing.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/wmij0_g1eCg","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":0.5,"source_sizelimit":50000,"problem_author":"ritksedana","problem_tester":"mexomerf","date_added":"23-09-2021","tags":{"0":"ritksedana","1":"simple","2":"start16"},"problem_difficulty_level":"Simple","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/DIRECTN","time":{"view_start_date":1634751002,"submit_start_date":1634751002,"visible_start_date":1634751002,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=DIRECTN","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
The Professor is facing the North. Tokyo is in trouble, and she is facing the South. Professor being her guardian angel wants to help her.

So, The Professor will follow some instructions, given as a string $S$ of length $N$, and will turn either left or right according to these instructions. He can save Tokyo only if after following a [substring](https://en.wikipedia.org/wiki/Substring) of instructions he will face in the same direction that Tokyo is facing. 

Will the Professor be able to save Tokyo?





<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>