Given a string of containing only L’s and R’s which represents left rotation and right rotation respectively. The task is to find the final direction of pivot(i.e N/E/S/W). Let a pivot is pointed towards north(N) in a compass.
Input: str = "LLRLRRL" Output: W In this input string we rotate pivot to left when a L char is encountered and right when R is encountered. Input: str = "LL" Output: S
- Use a counter that incremented on seeing R and decremented on seeing L.
- Finally use modulo on counter to get the direction.
- If count is negative then directions will be different.Check the code for negative as well.
Below is the implementation of above approach:
- String Range Queries to find the number of subsets equal to a given String
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Find the character in first string that is present at minimum index in second string
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Find length of longest subsequence of one string which is substring of another string
- Find the count of palindromic sub-string of a string in its sorted form
- Queries to find the last non-repeating character in the sub-string of a given string
- Queries to find the first non-repeating character in the sub-string of a string
- Find the smallest window in a string containing all characters of another string
- Count possible moves in the given direction in a grid
- Print direction of moves such that you stay within the [-k, +k] boundary
- Find a palindromic string B such that given String A is a subsequense of B
- Find if a string starts and ends with another given string
- Find sub-string with given power
- Find if an array contains a string with one mismatch
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.