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
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- 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 longest sub-string which is prefix, suffix and also present inside the string
- Find length of longest subsequence of one string which is substring of another string
- Find the character in first string that is present at minimum index in second string
- Find the count of palindromic sub-string of a string in its sorted form
- 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 the probability of a state at a given time in a Markov chain | Set 1
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.