Description
Given an m x n binary matrix with all 0s, randomly flip one 0 to 1. Each 0 should have equal probability. Implement flip() and reset().
Examples
Input:
m = 3, n = 1Output:
[random cells]Explanation:
Random cell selection.
Input:
m = 1, n = 4Output:
[random cells from single row]Explanation:
With a 1×4 matrix, all cells are in one row. Each flip() call randomly selects from positions (0,0), (0,1), (0,2), or (0,3), demonstrating uniform selection across a horizontal layout.
Input:
m = 2, n = 2Output:
[random cells from 2×2 grid]Explanation:
A 2×2 matrix has 4 possible positions: (0,0), (0,1), (1,0), (1,1). This square matrix example shows uniform random selection across both rows and columns with equal probability.
Constraints
- •
1 ≤ m × n ≤ 10⁶