Skip to main content
ARCHOS 525 BLUEPRINT · /d/dgm_code-monotonic-stack-core

Monotonic Stack Core (Next Greater Element & Span Queries)

6 COMPONENTS · 6 FLOWS · UPDATED 2026-11-24
GITHUB README / PR PREVIEW CARD
[![Monotonic Stack Core (Next Greater Element & Span Queries) — ArchOS Architecture](https://archos.sageideas.dev/d/dgm_code-monotonic-stack-core/opengraph-image)](https://archos.sageideas.dev/d/dgm_code-monotonic-stack-core)

*Interactive architecture diagram powered by [ArchOS Studio](https://archos.sageideas.dev/d/dgm_code-monotonic-stack-core)*
NOTION / DOCS / CONFLUENCE EMBED
<iframe src="https://archos.sageideas.dev/embed/dgm_code-monotonic-stack-core" width="100%" height="580" style="border:1px solid rgba(240,236,225,0.14);border-radius:6px;" loading="lazy" title="Monotonic Stack Core (Next Greater Element & Span Queries) — Interactive in ArchOS"></iframe>
PORTABLE MERMAID SPEC (GITHUB / NOTION / RFC)
flowchart LR
  client_0["Input Series"]
  n1_1["Scan Cursor"]
  n2a_2[("Monotonic Stack")]
  n2b_3["Boundary Resolver"]
  n3_4["Span Result Array"]
  downstream_5["Downstream & OTel"]
  client_0 -->|"1. Next item · O1"| n1_1
  n1_1 -->|"2a. Pop · Stack"| n2a_2
  n1_1 -->|"2b. Resolve · O1"| n2b_3
  n2a_2 -->|"3a. Record · ON"| n3_4
  n2b_3 -->|"3b. Merge · RAM"| n3_4
  n3_4 -.->|"4. Emit / · OTLP/API"| downstream_5

COMPONENT STACK (6)

  • Input SeriesSTATELESS
    Array / Prices / Heights
  • Scan CursorSTATELESS
    Iterates elements 0..N-1
  • Monotonic StackSTATEFUL
    Indices in increasing/decreasing
  • Boundary ResolverSTATELESS
    Popped item finds right/left bound
  • Span Result ArraySTATELESS
    Nearest greater/smaller per idx
  • Downstream & OTelSTATELESS
    Consumers, metrics & SLOs

REQUEST & DATA FLOW (6)

  1. Input Series → Scan Cursor (Next item)[O1]
  2. Scan Cursor → Monotonic Stack (Pop)[Stack]
  3. Scan Cursor → Boundary Resolver (Resolve)[O1]
  4. Monotonic Stack → Span Result Array (Record)[ON]
  5. Boundary Resolver → Span Result Array (Merge)[RAM]
  6. Span Result Array → Downstream & OTel (Emit /)[OTLP/API]
Configure NGINX / Postgres / K8s →60-Sec L4–L7 Diagnostic →