Min Stack Implementation
Function Name: MinStack
Description
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Implement the 'MinStack' class:
- 'MinStack()' initializes the stack object.
- 'void push(int val)' pushes the element val onto the stack.
- 'void pop()' removes the element on the top of the stack.
- 'int top()' gets the top element of the stack.
- 'int getMin()' retrieves the minimum element in the stack.
* You must implement a solution with O(1) time complexity for each function.
Requirements
- The 'MinStack' class should be designed to be initialized without any arguments.
- 'push', 'pop', 'top', and 'getMin' methods must all operate in O(1) time complexity.
- Consider using auxiliary data structure(s) to maintain the minimum element with the stack operations.
- All the above operations must satisfy the basic properties of a stack.
- Constraints:
- -2^31 <= val <= 2^31 - 1
- Methods 'pop', 'top', and 'getMin' will be called only on a non-empty stack.
- At most 3 * 10^4 calls will be made to push, pop, top, and getMin.
Examples
minStack = new MinStack();minStack.push(-2);minStack.push(0);minStack.push(-3);minStack.getMin(); // Returns -3.minStack.pop();minStack.top(); // Returns 0.minStack.getMin(); // Returns -2.
Links
Simple File Parser
Tue Nov 26 2024
In this challenge, you are required to write a function named `parseLogFile` that processes a simple log file. The log file is represented as a single string, with each entry separated by a newline character. Each entry in the log starts with a timestamp (in the format 'YYYY-MM-DD HH:MM:SS'), followed by a space, then a log level (either 'INFO', 'WARNING', or 'ERROR'), another space, and finally the log message. Your function should return the number of log messages for each log level.
Circular Queue Implementation
Thu Nov 28 2024
Implement a Circular Queue using an array. The Circular Queue should support the following operations: enqueue, dequeue, peek, and isEmpty. The enqueue operation adds an item to the back of the queue, the dequeue operation removes an item from the front of the queue, and the peek operation retrieves the item at the front of the queue without removing it. The isEmpty operation should return a boolean indicating whether the queue is empty. The Circular Queue should also have a fixed size specified at the time of creation and should handle the wrap-around when the end of the array is reached.