Skip to content

feat(others): add sliding window maximum with edge-case handling#3185

Open
hemanth2k6 wants to merge 1 commit into
TheAlgorithms:masterfrom
hemanth2k6:fix/sliding-window-edge-cases
Open

feat(others): add sliding window maximum with edge-case handling#3185
hemanth2k6 wants to merge 1 commit into
TheAlgorithms:masterfrom
hemanth2k6:fix/sliding-window-edge-cases

Conversation

@hemanth2k6

Copy link
Copy Markdown

Description

Added the "Sliding Window Maximum" algorithm to the others/ directory. The solution uses a monotonic deque approach to optimize lookup efficiency down to linear time.

Type of Change

  • New algorithm implementation
  • Defensive edge-case handling additions

Complexity

  • Time Complexity: $\mathcal{O}(N)$ where $N$ is the total number of elements.
  • Space Complexity: $\mathcal{O}(K)$ where $K$ is the window size.

Validation & Testing Done

  • Added robust assertions inside the execution block (static void test()).
  • Validated defensive guard clauses against:
    1. Completely empty vectors (nums = {})
    2. Sub-zero or zero window sizes (k <= 0)
    3. Window configurations scaling larger than the array size (k > nums.size())
  • Registered the target inside others/CMakeLists.txt to guarantee clean automated compilation builds.

Closes #4092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant