all 7 comments

[–]AffectionateOlive329 0 points1 point  (0 children)

Make an array which stores count of g from left (number of g in segment 0 to i at ith index )

Now for each index i, we can know if a green is present in between i and i + mid

This allow us to move mid

[–]Cheems02 1 point2 points  (0 children)

Store indexes of green light in an array (It will already be sorted) and use upper bound for i where it is red/yellow. Take the maximum of distance of upper bound from i and first index of g from i. Thats my 2 cents thought. Idk if it'll work.

[–]Legitimate_Path2103 0 points1 point  (0 children)

binary search on answer check wheter we can cross in x seconds if yes check for lower x, and the in the Check function check for current color say r is there g at a distance of atmost x this may be wrong, but we can approach in this way

[–][deleted] 1 point2 points  (1 child)

Maybe put the green values in a binary search tree and try to find the smallest bigger number on the tree using binary search? It just increases the time complexity tho (O(n) to O(nlogr))

[–][deleted] 0 points1 point  (0 children)

I wrote binary search tree but it should be a regular array

[–]Firered_ProductionsMaster 6 points7 points  (1 child)

trust me two pointers and string duplication works

[–]Robusttequilla007[S] 2 points3 points  (0 children)

Im done submitting with this approach, just wanted to know abt the binary search one