09. Assign Mice Holes
β GFG solution to the Assign Mice Holes problem: find optimal assignment to minimize maximum time using greedy approach with sorting. π
π§© Problem Description
π Examples
Example 1
Input: mices[] = [4, -4, 2], holes[] = [4, 0, 5]
Output: 4
Explanation: Assign the mouse at position 4 to the hole at position 4, so the time taken is 0 minutes.
Assign the mouse at position β4 to the hole at position 0, so the time taken is 4 minutes.
Assign the mouse at position 2 to the hole at position 5, so the time taken is 3 minutes.
Hence, the maximum time required by any mouse is 4 minutes.Example 2
Input: mices[] = [1, 2], holes[] = [20, 10]
Output: 18
Explanation: Assign the mouse at position 1 to the hole at position 10, so the time taken is 9 minutes.
Assign the mouse at position 2 to the hole at position 20, so the time taken is 18 minutes.
Hence, the maximum time required by any mouse is 18 minutes.π Constraints
β
My Approach
Greedy Sorting Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated