Coding with design constraints
Problem Statement
Design and implement a class or system that solves a specific problem under one or more of the following design constraints:
You must clearly describe your design decisions and how your implementation adheres to the given constraints.
✅ Functional Requirements
Depending on the selected example scenario, the system should:
⚙️ Non-Functional Requirements
Aspect with Description
Efficiency
Optimize time and/or space complexity within given limits.
Simplicity
Avoid unnecessary abstractions or violations of constraints.
Thread-Safety
Ensure correct behavior in concurrent scenarios (if required).
Extensibility
Design should allow extension if constraints change in future.
💡 Example Scenarios -----------------------------------------------------------
1. Design a Thread-Safe Counter
Constraint: Must be thread-safe without using built-in synchronization primitives like synchronized or Lock.
Goal: Increment and get counter value correctly under concurrent access.
2. Design an Immutable Stack
Constraint: The stack must be completely immutable (no internal state changes).
Goal: Implement push(), pop(), and peek() without modifying existing instances.
3. Design a Fixed-Size Cache (Memory Constraint)
Constraint: Cache can store a maximum of N items, evicting the least recently used item when full.
Goal: Maintain O(1) lookup and insertion operations (similar to an LRU cache).
4. Design a File Reader for Large Files
Constraint: The system cannot load the entire file into memory (stream-based design).
Goal: Implement methods to read large files line by line efficiently.
5. Design a Real-Time Data Processor
Constraint: Each operation must complete within a fixed time bound (e.g., <10 ms).
Goal: Process incoming events and output results continuously without delay accumulation.
🧠 Discussion Points (for Interview)
🧾 Final Interview Prompt
Design and implement a system or class under strict design constraints.
For example, design a thread-safe counter without synchronization primitives, or an immutable data structure that supports updates without mutation.
Clearly explain the constraint, justify design choices, and demonstrate how your code satisfies both functional and non-functional requirements.