# Got 1 on the input example, but visual studio passed

• using namespace std;
class Solution {
public:
int minArea(vector<vector<char>>& image, int x, int y) {
int m = image.size();
int n = image[0].size();
int left = findLeft(image, y);
int right = findRight(image, y+1);
int top = findTop(image, left, right, x);
int bottom = findBottom(image, left, right, x+1);
return (right - left)*(bottom - top);
}

``````int findLeft(vector<vector<char>>& image, int y){
int m = image.size();
int left = 0, right = y, k;
while(left < right){
int mid = (left+right)/2;
for(k=0; k<m; k++){
if(image[k][mid] == 1)
break;
}
if(k<m)
right = mid;
else
left = mid+1;
}
return left;
}

int findRight(vector<vector<char>>& image, int y){
int m = image.size(), n = image[0].size();
int left = y, right = n, k;
while(left < right){
int mid = (left+right)/2;
for(k=0; k<m; k++)
if (image[k][mid] == 1)
break;
if(k < m)
left = mid+1;
else
right = mid;
}
return left;
}

int findTop(vector<vector<char>>& image, int left, int right, int x){
int top = 0, bottom = x, k;
while(top < bottom){
int mid = (top+bottom)/2;
for(k=left; k<=right; k++)
if(image[mid][k] == 1)
break;
if(k <= right)
bottom = mid;
else
top = mid+1;
}
return bottom;
}

int findBottom(vector<vector<char>>& image, int left, int right, int x){
int m = image.size();
int top = x, bottom = m, k;
while(top < bottom){
int mid = (top+bottom)/2;
for(k=left; k<=right; k++)
if(image[mid][k] == 1)
break;
if(k <= right)
top = mid+1;
else
bottom = mid;
}
return bottom;
}
``````

};

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.