Greedy Constraint Resolution | Dart Solution | Time O(n) | Space O(n)
ApproachThe solution uses a greedy approach to reconstruct a valid binary matrix:

Two-Pass Construction:

First pass: Handle fixed-value columns (sums of 0 and
## Approach
The solution uses a greedy approach to reconstruct a valid binary matrix:

1. **Two-Pass Construction**:
   - First pass: Handle fixed-value columns (sums of 0 and 2)
   - Second pass: Distribute remaining 1s to satisfy row constraints

2. **Priority Assignment**:
   - For columns with sum=2: Place 1 in both rows
   - For columns with sum=0: Place 0 in both rows
   - For columns with sum=1: Prioritize first row until upper is satisfied, then second row

3. **Constraint Validation**:
   - Track remaining required 1s for each row (upper/lower counters)
   - Immediately return empty array when constraints cannot be met
   - Verify complete utilization (upper=lower=0) at the end

This greedy approach works because columns with sum 2 and 0 have only one valid configuration, while columns with sum 1 provide flexibility to satisfy row constraints.

## Complexity
- **Time Complexity**: $$O(n)$$
  - Two passes through array of length n
  - Constant time operations per element

- **Space Complexity**: $$O(n)$$
  - Output matrix requires 2×n space
  - No additional significant data structures

# Code
```dart []
class Solution {
  List<List<int>> reconstructMatrix(int upper, int lower, List<int> colsum) {
    List<int> firstRow = List.filled(colsum.length, -1);
    List<int> secondRow = List.filled(colsum.length, -1);
    for (var i = 0; i < colsum.length; i++) {
      if (colsum[i] == 2 && upper > 0 && lower > 0) {
        firstRow[i] = 1;
        secondRow[i] = 1;
        upper--;
        lower--;
      } else if (colsum[i] == 0) {
        firstRow[i] = 0;
        secondRow[i] = 0;
      } else if (colsum[i] == 2) {
        return [];
      }
    }
    for (var i = 0; i < colsum.length; i++) {
      if (colsum[i] == 1 && upper > 0) {
        firstRow[i] = 1;
        secondRow[i] = 0;
        upper--;
      } else if (colsum[i] == 1 && lower > 0) {
        firstRow[i] = 0;
        secondRow[i] = 1;
        lower--;
      } else if (colsum[i] == 1) {
        return [];
      }
    }
    if (upper == 0 && lower == 0) {
        return [firstRow, secondRow];
    } else {
        return [];
    }
  }
}
```
['Array', 'Greedy', 'Matrix', 'Dart']