π Sliding Window API
A production-ready FastAPI-based REST API implementing high-performance array and stack/deque algorithms such as Sliding Window, Monotonic Stack, and Histogram problems.
This project focuses on clean architecture, O(n) optimized solutions, and real-world backend deployment.
π Features
- Optimized algorithms with O(n) time complexity
- FastAPI with automatic Swagger documentation
- Core DSA concepts: Stack, Deque, HashMap
- Fully deployable on Render
- Clean and modular code structure
βοΈ Installation & Run
1) Clone the repository
git clone https://github.com/anshkunj/sliding-window-api
cd sliding-window-api
2) Install dependencies
pip install -r requirements.txt
3) Run the server
uvicorn main:app --reload
π API Documentation
Swagger UI: http://127.0.0.1:8000/docs
ReDoc: http://127.0.0.1:8000/redoc
π Live API
Base URL:
https://sliding-window-api.onrender.com
Docs:
https://sliding-window-api.onrender.com/docs
π repo Structure
sliding-window-api/
βββ main.py # FastAPI app & routes
βββ logic.py # Core algorithm implementations
βββ models.py # Pydantic request models
βββ .gitignore
βββ requirements.txt
βββ render.yaml
βββ README.md # Project Overview
βββ LICENSE # Licence file (MIT)
π§ Algorithms Implemented
0οΈβ£ Health
Check status of service whether it is live or not.
1οΈβ£ Next Greater Element
Find the next greater element to the right of each element.
Example:
Input: [4, 2, 1, 5]
Output: [5, 5, 5, -1]
2οΈβ£ Daily Temperatures
Return the number of days until a warmer temperature.
Example:
Input: [73, 74, 75, 71, 69, 72, 76, 73]
Output: [1, 1, 4, 2, 1, 1, 0, 0]
3οΈβ£ Largest Rectangle in Histogram
Find the maximum rectangular area in a histogram.
Example:
Input: [2, 1, 5, 6, 2, 3]
Output: 10
4οΈβ£ Maximum Sliding Window
Find the maximum element in each sliding window of size k.
Example:
Input: [2, 1, 3, 4, 6, 3, 8, 9, 10, 12, 56], k = 4
Output: [4, 6, 6, 8, 9, 10, 12, 56]
π API Endpoints
GET /health
GET /next_greater
POST /next_greater
GET /daily_temperatures
POST /daily_temperatures
GET /largest_rectangle
POST /largest_rectangle
GET /max_sliding_window
POST /max_sliding_window
π§Ύ Request Format (JSON)
{ "arr": [1, 3, 2, 4], "k": 2 }
π€ Sample Response
{ "result": [3, 4, 4, -1] }
βΆοΈ Run Locally
pip install -r requirements.txt
uvicorn main:app --reload
Open in browser:
http://127.0.0.1:8000/docs
βοΈ Deployment (Render)
Build Command:
pip install -r requirements.txt
Start Command:
uvicorn main:app --host 0.0.0.0 --port 10000
π Tech Stack
- Python 3.10+
- FastAPI
- Pydantic
- Uvicorn
π― Learning Outcomes
- Mastery of Monotonic Stack
- Sliding Window optimization
- DSA + Backend integration
- Real-world API deployment experience
π License
MIT License
π€ Contributing
Contributors are welcome!
β’ Add new sliding window problems
β’ Improve explanations
β’ Optimise exists code
π€ Author
anshkunj
π« Letβs connect
- GitHub: https://github.com/anshkunj
- LinkedIn: https://linkedin.com/in/anshkunj
- LeetCode: https://leetcode.com/u/anshkunj
- Devpost: https://devpost.com/anshkunj
- HackerRank: https://www.hackerrank.com/profile/anshkunj
- AtCoder: https://atcoder.jp/users/anshkunj
- Codeforces: https://codeforces.com/profile/anshkunj
- Fiverr: https://www.fiverr.com/anshkunj
- Freelancer: https://www.freelancer.com/u/anshkunj
β Support
If you found this project helpful, give it a star β
It motivates me to build more real-world APIs π
πΉ Note
This repository is regularly updated with new scripts and improvements.


Log in or sign up for Devpost to join the conversation.