Sprint Challenge
Overview
This sprint challenge will test your understanding of stacks, queues, computer hardware, immutability, and caching concepts covered in this sprint. You'll demonstrate your ability to apply these concepts to solve practical problems.
Challenge Objectives
- Implement stack and queue data structures to solve programming problems
- Demonstrate understanding of computer hardware and OS concepts
- Apply immutability principles in Java applications
- Design and implement an in-memory caching solution
Challenge Tasks
Part 1: Stack Implementation
Implement a custom stack data structure that maintains a running minimum value. Your implementation should support the following operations:
push(value)
: Add a value to the top of the stackpop()
: Remove and return the value at the top of the stackpeek()
: Return the value at the top of the stack without removing itgetMin()
: Return the minimum value in the stack in O(1) time
Each operation should have O(1) time complexity.
public class MinStack {
// Your implementation here
public void push(int val) {
// Add val to the top of the stack
}
public int pop() {
// Remove and return the top element
return 0;
}
public int peek() {
// Return the top element without removing it
return 0;
}
public int getMin() {
// Return the minimum value in O(1) time
return 0;
}
}
Part 2: Queue Application
Implement a message processing system that uses a queue to handle incoming messages in order. Your system should:
- Accept incoming messages and add them to a queue
- Process messages in FIFO order
- Implement priority handling for urgent messages
- Include metrics tracking for average wait time
public class MessageProcessor {
// Your implementation here
public void addMessage(Message message) {
// Add message to the queue
}
public Message processNextMessage() {
// Process and return the next message
return null;
}
public double getAverageWaitTime() {
// Calculate and return the average wait time
return 0.0;
}
// Additional methods as needed
}
Part 3: Immutable Class
Create an immutable class that represents a customer record with the following requirements:
- Include fields for customer ID, name, email, and purchase history
- Ensure the class is truly immutable (including collections)
- Implement methods to create new instances with updated fields
- Include proper documentation explaining your design choices
public final class Customer {
// Your implementation here
// Constructor(s)
// Accessor methods
// Methods to create new instances with updated fields
}
Part 4: Caching Implementation
Create a generic caching solution that includes:
- TTL (Time-To-Live) functionality for cached items
- LRU (Least Recently Used) eviction policy
- Size-based constraints
- Thread-safe operations
- Statistics tracking (hit rate, miss rate, eviction count)
public class GenericCache<K, V> {
// Your implementation here
public GenericCache(int maxSize, long ttlMillis) {
// Initialize your cache
}
public V get(K key) {
// Retrieve a value from the cache
return null;
}
public void put(K key, V value) {
// Add a value to the cache
}
public void clear() {
// Clear the cache
}
public CacheStats getStats() {
// Return cache statistics
return null;
}
// Additional methods as needed
}
Part 5: Computer Hardware Essay
Write a 500-word essay addressing the following topics:
- How RAM, CPU, and storage differences impact Java application performance
- Strategies for optimizing Java applications for different hardware configurations
- Trade-offs between memory usage and CPU utilization in your cache implementation
Submission Requirements
- All code should be well-documented with JavaDoc comments
- Include unit tests for each component
- Submit a README.md explaining your implementation decisions
- All implementations should follow best practices for Java development
Your solution will be evaluated on correctness, efficiency, code quality, and documentation.