Maximum Values in Sliding Windows via Monotonic Deques
Given an integer array nums and an integer k, a sliding window of size k traverses the array from left to right. Only the k numbers within the window are visible at any step, and the window shifts right by one position after each move. The task is to return the maximum element inside the window for every valid posiiton.
Example 1
Input: nums = ...
Posted on Mon, 14 Sep 2026 16:45:15 +0000 by itarun
Python Collections Module: Specialized Container Types
Collections Module Overview
The collections module provides specialized container alternatives to Python's built-in containers like list, dict, set, and tuple. Key components include:
namedtuple: Creates tuple subclasses with named fields
deque: Double-ended queue for efficient appends/pops
Counter: Dictionary subclass for counting hashable ob ...
Posted on Mon, 14 Sep 2026 16:35:40 +0000 by L
Understanding Monotonic Queues: Efficient Sliding Window Optimization
A monotonic queue is a specialized data structure that maintains elements in either strictly increasing or decreasing order. Unlike standard queues, a monotonic queue allows operations at both the front and rear, functioning as a double-ended queue (deque) where elements are kept in sorted order.
The Core Principle
The fundamental insight behin ...
Posted on Thu, 10 Sep 2026 16:00:59 +0000 by stef686
Stack and Heap Techniques for Three Classic LeetCode Problems
Evaluating Reverse Polish Notation (LeetCode 150)
Reverse Polish Notation (RPN), also known as postfix expression, places operators after thier operands. For example, the infix expression (1 + 2) * (3 + 4) becomes 1 2 + 3 4 + * in RPN. This notation eliminates ambiguity and parenthetical grouping, making it ideal for stack-based evaluation.
The ...
Posted on Wed, 09 Sep 2026 16:01:38 +0000 by MasterACE14
Data Structures: Stack, Queue, and Deque
Stack
Imagine organizing a closet by placing winter clothes first, then summer clothes on top. When summer arrives, you grab the summer clothes first from the top without disturbing the items below.
A stack is a container that allows storing, accessing, and removing elements exclusively from one end called the top. This constraint means the ele ...
Posted on Mon, 27 Jul 2026 16:10:14 +0000 by sunnyk
Zigzag Level Order Traversal of Binary Tree
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as:
[
[3],
[20,9],
[15,7]
]
Appr ...
Posted on Mon, 27 Jul 2026 16:05:55 +0000 by Hypnos
Implementing Nested DataSource Context Holder with ThreadLocal Deque
DataSource Context Holder Implementation Based on Deque
public class DataSourceContextManager {
// Using ThreadLocal<Deque> to support nested data sources
private static final ThreadLocal<Deque<DataSourceEnum>> CONTEXT_HOLDER =
ThreadLocal.withInitial(ArrayDeque::new);
/**
* Push data source type ...
Posted on Thu, 09 Jul 2026 16:50:33 +0000 by dodgei
Solutions to AtCoder ABC 066
Problem A - Sum of Two Smallest Numbers
Statement:
Given three integers, output the sum of the two smallest values.
Solution:
Subtract the maximum value from the total sum.
int a, b, c; cin >> a >> b >> c;
cout << a + b + c - max({a, b, c}) << endl;
Problem B - Finding the Longest Even Prefix
Statement:
A string i ...
Posted on Sun, 10 May 2026 03:20:54 +0000 by mynameisbob
Understanding STL Container Adapters: stack and queue
The essence of a container adapter lies in the principle of reuse. Instead of implementing storage structures from scratch, these adapters leverage existing containers to handle data storage while exposing only the interfaces relevant to their specific access patterns. This adapter pattern represents a fundamental design philosophy in software ...
Posted on Sat, 09 May 2026 06:42:40 +0000 by mgilbert
Algorithmic Patterns with Stacks, Monotonic Deques, and Priority Queues in C++
Evaluating Reverse Polish Notation
Reverse Polish Notation (RPN) eliminates the need for parentheses by placing operators after their operands. A stack-based approach efficiently processes tokens in a single pass.
class Solution {
public:
int evalRPN(vector<string>& expr) {
stack<int> eval_stack;
for (const a ...
Posted on Sat, 09 May 2026 00:38:32 +0000 by tazgalsinh