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(). Return the result as a string.
Examples
Input:
m = 3, n = 1Output:
[[1,0],[0,0],[2,0]]Explanation:
Random cell selection.
Input:
m = 1, n = 4Output:
[[0,3],[0,0],[0,2],[0,1]]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:
[[1,1],[0,0],[1,0],[0,1]]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⁶