Problem statement

https://binarysearch.com/problems/Furthest-From-Origin/

Solution

The idea is that we can replace all ? with either L or R and consider this border cases.

Complexity

Time complexity is O(n), space is O(1)

Code

class Solution:
    def solve(self, s):
        L = s.count("L")
        R = s.count("R")
        Q = s.count("?")
        return max(L - R + Q, L - R - Q, R - L + Q, R - L - Q)