feat(work): add Minimum Window Substring & Basic Calculator solutions and implement StockSpanner algorithm

This commit is contained in:
Prad Nukala committed 2026-10-07 12:59:02 -04:00
1 parent 5627d0ca64
commit 37d3d9ceaf
3 files changed
+124 -9

No files matched your search

+13 -9
View File
@@ -24,12 +24,12 @@ less than or equal 8 for 3 consecutive days.
Implement the StockSpanner class:
• StockSpanner() Initializes the object of the class.
• StockSpanner() Initializes the object of the class.
• int next(int price) Returns the span of the stock's price given
that today's price is price.
Example 1:
@@ -52,23 +52,27 @@ stockSpanner.next(75); // return 4, because the last 4 prices
price.
stockSpanner.next(85); // return 6
Constraints:
• 1 <= price <= 10^5
• 1 <= price <= 10^5
• At most 10^4 calls will be made to next.
• At most 10^4 calls will be made to next.
"""
class StockSpanner:
class StockSpanner:
def __init__(self):
prices = []
self.stack = []
def next(self, price: int) -> int:
ans = 1
while self.stack and self.stack[-1][0] <= price:
ans += self.stack.pop()[1]
self.stack.append([price, ans])
return ans
# Your StockSpanner object will be instantiated and called as such: