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
- Sort an alphanumeric string such that the positions of alphabets and numbers remain unchanged
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Find the sum of the ascii values of characters which are present at prime positions
- Minimum moves to reach from i to j in a cyclic string
- Maximum power of jump required to reach the end of string
- Find the time which is palindromic and comes after the given time
- 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
- String Range Queries to find the number of subsets equal to a given String
- Find the count of palindromic sub-string of a string in its sorted form
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.