I have been searching online about an article related to monotonic queue or stack, there not much organized information. So, I decided to just write something about it on my own.
First, you can check out this article to see how sliding window algorithm looks like:
This article includes five sections:
Part of this great node comes from blog:
787. Cheapest Flights Within K Stops
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.
n
m
u
v
w
Two’s complement and negative number: The binary representation of -k as a N-bit number is concat(1, 2^(N-1)-k) ==representation in positive, flip each bit, and +1.
Solution: brute force
class Solution: def…