Sliding Window Maximum and Top K Frequent Elements Using Monotonic Queue and Priority Queue
Sliding Window Maximum
Problem Statement: Given an array nums and a sliding window of size k, find the maximum value in each window position as it moves from left to right.
Approach Analysis
The brute-force approach iterates through each window position and finds the maximum by comparing all k elements, resulting in O(n×k) time complexity.
A ma ...
Posted on Mon, 21 Sep 2026 16:25:54 +0000 by ksteuber
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
Understanding Stack vs. Heap Memory in C#
Eventhough .NET's managed environment handles memory and garbage collection, understanding these underlying mechanisms is crucial for application optimization. Familiarity with basic memory management principles also clarifies variable behavior.
During code execution in a .NET environment, memory is allocated in two primary locations: the stack ...
Posted on Fri, 28 Aug 2026 16:10:08 +0000 by Snart
Max Heap Construction Using Linear Time Approach
Building a Max Heap
When constructing a max heap from an array of N elements, the goal is to arrange the elemetns in a structure that satisfies the max heap property: every parent node must be greater than or equal to its child nodes.
There are two primary strategies:
Inserting elements one by one into an initially empty heap, wich results in ...
Posted on Sat, 08 Aug 2026 16:50:20 +0000 by wilburforce
Implementing a Priority Heap in Java
This article focuses on implementing a min-heap, which has the property that every parent node is less than or equal to its children. This ensures the smallest element is always at the root (index 1 in our array).
Heap Operations
A min-heap implementation should support these basic operations:
Insertion (I): Add a new element to the heap while ...
Posted on Fri, 17 Jul 2026 16:48:25 +0000 by Gonwee
JVM Memory Structure: Understanding the Heap
1. Structure Diagram
2. Heap
Objects reside in the heap: their size is unpredictable and can change dynamically.
The stack holds primitive values and object referances; each reference is typically 4 bytes.
2.1 Characteristics
Nearly all objects are allocated on the heap.
Heap memory is fully managed by the JVM through automatic garbage col ...
Posted on Sat, 20 Jun 2026 18:02:37 +0000 by atomm
Greedy Scheduling of Maximum Meetings and Reconstructing Target Arrays via Reverse Operations
Maximum Meetings Attendance
Given a list of meetings where each meeting is represented as [start, end], determine the largest number of meetings you can attend if you can only be in one meeting per day and you may pick any day within the inclusive interval [start, end] to attend that meeting.
Intuition
The key observation is that we want to fin ...
Posted on Thu, 18 Jun 2026 18:22:07 +0000 by cullouch
Merging Fruits and Fence Repair G Solution
[NOIP2004 Advanced Group] Merging Fruits / [USACO06NOV] Fence Repair G
Problem Description
In an orchard, Duoduo has already knocked down all the fruits and divided them into different piles according to their types. Duoduo decides to merge all the fruits into one pile.
Each time, Duoduo can merge two piles together, and the effort consumed equ ...
Posted on Thu, 18 Jun 2026 18:09:18 +0000 by mikeyca
Efficient Sorting and Merging with Heap Data Structures
Heap Data Structure Implementation
Heaps are specialized tree-based data structures that satisfy the heap property. They are commonly used to implement priority queues and for efficient sorting algorithms. This article explores two practical applications of heaps: heap sort and sequence merging.
Heap Sort Implemantation
Heap sort is an efficien ...
Posted on Thu, 18 Jun 2026 16:37:37 +0000 by Eddie Fisher
In-Place Heap Sort Using Max-Heap Adjustments
Replacing the Linear Scan in Selection Sort
Traditional selection sort repeatedyl picks the smallest element from the unsorted suffix and swaps it forward. The bottleneck is the linear scan that finds that minimum, giving an overall Θ(n²) runtime.
static void naiveSelection(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
int ...
Posted on Wed, 20 May 2026 07:03:31 +0000 by jynmeyer