One Pass

Math

268. Missing Number (Easy)

Refer 268. Missing Number (Easy).

Uncategorized

Second Largest (Easy)

def getSecondLargest(self, arr):
    first_max, second_max = -1, -1
    for i in arr:
        if first_max < i:
            second_max = first_max
            first_max = i
        elif first_max > i and second_max < i:
            second_max = i
    return second_max

1796. Second Largest Digit in a String (Easy)

def secondHighest(self, s: str) -> int:
    first_max = second_max = "-"
    for i in s:
        if not i.isdigit():
            continue
        if first_max < i:
            second_max = first_max
            first_max = i
        elif first_max > i and second_max < i:
            second_max = i

    # print(first_max, second_max)
    return int(second_max) if second_max != "-" else -1

2259. Remove Digit From Number to Maximize Result (Easy)

def removeDigit(self, number: str, digit: str) -> str:
    n = len(number)
    last_occ = 0
    for i in range(n - 1):
        if number[i] == digit:
            if number[i + 1] > digit:
                return number[:i] + number[i + 1 :]
            last_occ = i
    if number[-1] == digit:
        last_occ = n - 1
    return number[:last_occ] + number[last_occ + 1 :]