Cody

# Problem 658. Find the biggest empty box

Solution 850114

Submitted on 13 Mar 2016 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
a = [1 0; 0 0]; [r1,r2,c1,c2] = biggest_box(a); sub = a(r1:r2,c1:c2); [m,n] = size(sub); len = 1; assert(isequal(sum(sub(:)),0)) assert(isequal(m,len)); assert(isequal(n,len));

c = 1 1 0 1 1 0 0 0 0 d = [] e = [] c = 1 0 0 0 d = 2 1 2 e = 1 2 2

2   Pass
a = [1 0 0; 0 0 0; 0 0 0]; [r1,r2,c1,c2] = biggest_box(a); sub = a(r1:r2,c1:c2); [m,n] = size(sub); len = 2; assert(isequal(sum(sub(:)),0)) assert(isequal(m,len)); assert(isequal(n,len));

c = 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 d = [] e = [] c = 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 d = 2 1 2 e = 1 2 2

3   Pass
a = eye(9); [r1,r2,c1,c2] = biggest_box(a); sub = a(r1:r2,c1:c2); [m,n] = size(sub); len = 4; assert(isequal(sum(sub(:)),0)) assert(isequal(m,len)); assert(isequal(n,len));

c = Columns 1 through 16 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 1 2 3 3 3 3 3 3 3 2 1 0 0 0 0 0 1 2 3 4 4 4 4 4 4 3 2 1 0 0 0 0 1 2 3 4 5 5 5 5 5 4 3 2 1 0 0 0 1 2 3 4 5 6 6 6 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 7 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 0 0 1 2 3 4 5 6 7 7 7 6 5 4 3 2 0 0 0 1 2 3 4 5 6 6 6 6 5 4 3 2 0 0 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