由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Amazon算法问题请教
相关主题
面试问题请教An interview problem: largest submatrix
请教一道算法题一些算法题。
问个算法题这道题目用 brute force 好慢阿
刚看了leetcode 上的maximum rectangular sub matrix那题一道有意思的Google面试题
求Leetcode OJ Maximal Rectangle的n^2解法An interview question from a well-known small company
leetcode一道题challenge: 找bug
The time complexity on finding the kth largest element in a再问一道老题
问一道G家面试题histogram问题
相关话题的讨论汇总
话题: largest话题: matrix话题: time话题: find话题: square
进入JobHunting版参与讨论
1 (共1页)
a***w
发帖数: 168
1
You are given a M x N matrix with 0's and 1's
1. Find the largest square matrix with 1's
2. Find the largest rectangular matrix with 1's
没想出哪种比Brute-force 列举更好的办法,哪位有啥hint?
b********h
发帖数: 119
2
How about dynamic programming?
Let S(i,j) be the largest square that ends at row i, column j.
Then
S(i,j) = 0, if (i,j)==0
= min(S(i-1,j), S(i,j-1)) + 1, if (i,j)==1 && S(i-1,j)!=S(i,j-1)
= S(i-1,j) + 1, if (i,j)==1 && S(i-1,j)==S(i,j-1) && (i-k,j-k)==1

The answer is max(S(i,j)). Time complexity is O(m*n).
n******h
发帖数: 50
3
我做不到Time complexity O(m*n)
suppose Matrix is m*n (m for the largest square, time O(m*m*n), space O(m*n)
for the largest rectangle, time O((m+n)*m*n), space O(m*n*n)
r**u
发帖数: 1567
4
这个可以reduce成find max rectangle in柱状图。考古一下。Another hint: 先找到
每行的连续序列。
e.g., convert 1 0 1 1 1 0 --> 1 0 1 2 3 0.

【在 a***w 的大作中提到】
: You are given a M x N matrix with 0's and 1's
: 1. Find the largest square matrix with 1's
: 2. Find the largest rectangular matrix with 1's
: 没想出哪种比Brute-force 列举更好的办法,哪位有啥hint?

1 (共1页)
进入JobHunting版参与讨论
相关主题
histogram问题求Leetcode OJ Maximal Rectangle的n^2解法
问个largest rectangle in histogram的问题leetcode一道题
leetcode: largest rectangle in histogram求帮助The time complexity on finding the kth largest element in a
Largest Rectangle in Histogram问一道G家面试题
面试问题请教An interview problem: largest submatrix
请教一道算法题一些算法题。
问个算法题这道题目用 brute force 好慢阿
刚看了leetcode 上的maximum rectangular sub matrix那题一道有意思的Google面试题
相关话题的讨论汇总
话题: largest话题: matrix话题: time话题: find话题: square