Beats 100 % | Brute to Optimal | Java Solution | Greedy | Array | ArrayLists | Collections | 
BruteForce Approach -> Beats 7%Complexity
Time complexity: O(2n)

Space complexity: O(1)
CodeOptimal Approach ->  Beats 100 %Complexity
Time complexity: O(n)

S
# BruteForce Approach -> Beats 7%
# Complexity
- Time complexity: O(2n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public List<List<Integer>> reconstructMatrix(int upper, int lower, int[] colsum) {
        
        List<List<Integer>> ans = new ArrayList<>();
        ans.add(new ArrayList<Integer>());
        ans.add(new ArrayList<Integer>());
        int setBits = 0;
        //First Giving Priority to 2colsum 
        for(int i = 0; i < colsum.length; i++)
        {
            ans.get(0).add(0);
            ans.get(1).add(0);
            if(colsum[i] == 2){
                colsum[i] = 0;
                lower -= 1;
                upper -= 1;
                ans.get(0).set(i, 1);
                ans.get(1).set(i, 1);
            }
            setBits += colsum[i];
            if((upper < 0) || (lower < 0)){
                List<List<Integer>> empty = new ArrayList<>();
                return empty;
            }
        }
        //Invalid Case
        if((upper + lower) != setBits)
        {
            List<List<Integer>> empty = new ArrayList<>();
            return empty;
        }
        //Traversing and filling Upper Row and then Lower Row
        for(int col = 0; col < colsum.length; col++){
            if(upper > 0 && colsum[col] > 0){
                ans.get(0).set(col, 1);
                colsum[col] -= 1;
                upper -= 1;
            }
            if(lower > 0 && colsum[col] > 0){
                ans.get(1).set(col, 1);
                colsum[col] -= 1;
                lower -= 1;
            }
        }
        return ans;
    }
}
```
# Optimal Approach ->  Beats 100 %
<!-- Describe your first thoughts on how to solve this problem. -->


# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public List<List<Integer>> reconstructMatrix(int upper, int lower, int[] colsum) {
        int n = colsum.length;
        int mat[][] = new int[2][n];
        for(int i = 0; i < n; i++)
        {
            if(colsum[i] == 0)
                continue;
            else if(colsum[i] == 2)
            {
                lower -= 1;
                upper -= 1;
                mat[0][i] = 1;
                mat[1][i] = 1;
            }
            else if(upper > lower)
            {
                mat[0][i] = 1;
                upper -= 1;
            }
            else{
                mat[1][i] = 1;
                lower -= 1;
            }
        }
        if(upper != 0 || lower != 0){
            return new ArrayList<>();
        }
        return new ArrayList(Arrays.asList(mat[0], mat[1]));
    }
}
```
['Array', 'Greedy', 'Java']