Given an string of ‘x’ and ‘o’. From each ‘x’ a signal originates which travels in both direction. It takes one unit of time for the signal to travel to next cell. If a cell contains ‘o’, the signal changes it to ‘x’ . Task is to compute the time taken to convert the array into string of signals.
An string of signal contains only ‘x’ in it.
Input : s = “oooxooooxooo”
Output : 3
Input : s = “oooxoooo”
Output : 4
Source :OYO Rooms Interview Set 2
The idea is to find the length of longest contiguous ‘o’. Also check, if ‘x’ is present at right side and left side of contiguous ‘o’ then time period will be reduce to half the maximum length else time period will be equal to the maximum length.
Below is the implementation of above approach.
- Find numbers of balancing positions in string
- Reverse a string preserving space positions
- Number of positions where a letter can be inserted such that a string becomes palindrome
- Minimum moves to reach from i to j in a cyclic string
- Maximum power of jump required to reach the end of string
- Time complexity of all permutations of a string
- Maximum difference of zeros and ones in binary string | Set 2 (O(n) time)
- Find the arrangement of queue at given time
- Find the count of palindromic sub-string of a string in its sorted form
- 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 probability of a state at a given time in a Markov chain | Set 1
- Find the smallest window in a string containing all characters of another string
- 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
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.