Leetcode 745 Solution

This article provides solution to leetcode question 745 (find-smallest-letter-greater-than-target)

https://leetcode.com/problems/find-smallest-letter-greater-than-target

Solution

class Solution:
    def nextGreatestLetter(self, letters: List[str], target: str) -> str:
        l = 0
        r = len(letters) - 1
        while l < r:
            m = (l + r) // 2

            if letters[m] > target:
                r = m
            else:
                l = m + 1
        return letters[l] if letters[l] > target else letters[0]