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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find numbers of balancing positions in string
- Find minimum number of steps to reach the end of 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
- Queries for rotation and Kth character of the given string in constant time
- Maximum difference of zeros and ones in binary string | Set 2 (O(n) time)
- Find the arrangement of queue at given time
- 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 longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find the count of palindromic sub-string of a string in its sorted form
- 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
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.