Implement Matrix Move and Logger
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Implement the following two coding tasks.
1. **Move a submatrix in place.** You are given an `m x n` matrix, a source rectangle defined by its top-left corner `(r1, c1)` and bottom-right corner `(r2, c2)` inclusive, and a destination top-left corner `(nr, nc)`. The destination rectangle has the same height and width as the source rectangle. Update the original matrix **in place** so that the destination rectangle contains exactly the original values from the source rectangle. The source and destination rectangles may overlap, and the final destination contents must match what you would get if the source rectangle had been copied before any writes occurred. Use only `O(1)` extra space besides a few temporary variables.
2. **Implement a rate-limited logger.** Design a `Logger` class with a configurable time window `windowSeconds` and a method `shouldAllow(key, timestamp) -> bool`. A request for `key` should be allowed only if the same key has not been allowed during the previous `windowSeconds` seconds. Assume timestamps are non-decreasing. Your implementation should support high call volume with `O(1)` average-time checks and should remove expired state so memory usage does not grow without bound.
Quick Answer: This question evaluates array manipulation and in-place algorithm design for handling overlapping submatrix moves, along with data-structure and time-window reasoning for implementing a rate-limited logger that supports O(1)-average-time checks and bounded memory.