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:
- Find total no of collisions taking place between the balls in which initial direction of each ball is given
- Count possible moves in the given direction in a grid
- Print direction of moves such that you stay within the [-k, +k] boundary
- 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 if a string starts and ends with another given string
- Find a palindromic string B such that given String A is a subsequense of B
- Queries to find the last non-repeating character in the sub-string of a given string
- String Range Queries to find the number of subsets equal to a given String
- Restore original String from given Encrypted String by the given operations
- Find the smallest window in a string containing all characters of another string
- Find the character in first string that is present at minimum index in second string
- 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
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Queries to find the first non-repeating character in the sub-string of a string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find Kth largest string from the permutations of the string with two characters
- Check if a string can become empty by recursively deleting a given sub-string
- String containing first letter of every word in a given string with spaces
- Check if a given string is sum-string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.