class StockSpanner:
def __init__(self):
self.arr = []
def next(self, price: int) -> int:
self.arr.append(price)
i = len(self.arr) - 2
while i >= 0 and self.arr[i] <= price:
i -= 1
return len(self.arr) - i - 1Where is the number of function calls.
class StockSpanner:
def __init__(self):
self.stack = [] # pair: (price, span)
def next(self, price: int) -> int:
span = 1
while self.stack and self.stack[-1][0] <= price:
span += self.stack[-1][1]
self.stack.pop()
self.stack.append((price, span))
return spanWhere is the number of function calls.