由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - matrix question
相关主题
大牛们看看这题:Find Peak Element II请教leetcode N-Queens II问题
电面题一个新鲜onsite面经
leetcode中那道Set Matrix Zeroes怎么做拿到offer,分享之前的一些onsite面试
Set Matrix Zeroes const space solutionleetcode wordsearch的时间复杂度?
问个sql问题这题就够凶残的了吧
问个面试题g 家面经
AMAZON PHONE SCREEN 1 基本死掉。Amazon algorithm question, google
顺时针打印MxN矩阵的简洁递归解法~~问两道AMAZON电面题
相关话题的讨论汇总
话题: matrix话题: row话题: false话题: column话题: elements
进入JobHunting版参与讨论
1 (共1页)
H*M
发帖数: 1268
1
agiven n by n matrix( elements are either 0 or 1)
find out if there exist a row i and column j such that
1) all elements of row i are zeros
2) all elements of column j are 1s
3)(i,j) entry can be either 0 or 1
my thinking is:
sum each row and each column
if sumRow[i] > 1 mark it false
if sumCol[i] also for those rows and cols,if they are not marked false, record the 1 posi
tions for row and 0 positions for col when doing sum.
for those cols and rows that are not marked false
m*****f
发帖数: 1243
2
to get the row, multiply matrix with a nx1 vector with all 1.
to get the column, do the same with its transpose matrix
the all-1/0-row/columns are recorded as n/0 in the result vector
H*M
发帖数: 1268
3
没看懂.能写清楚点不?
结论是什么?可以有更有效的方法?

【在 m*****f 的大作中提到】
: to get the row, multiply matrix with a nx1 vector with all 1.
: to get the column, do the same with its transpose matrix
: the all-1/0-row/columns are recorded as n/0 in the result vector

m********0
发帖数: 2717
4
you forgot the complexity of
matrix multiplication itself.
in this case, still O(n^2).
and '+' is faster than '*' in general.
So what you offer is a worse solution.

【在 m*****f 的大作中提到】
: to get the row, multiply matrix with a nx1 vector with all 1.
: to get the column, do the same with its transpose matrix
: the all-1/0-row/columns are recorded as n/0 in the result vector

l***i
发帖数: 632
5

I don't understand 3)... Isn't it already an assumption that the matrix is
binary?
posi

【在 H*M 的大作中提到】
: agiven n by n matrix( elements are either 0 or 1)
: find out if there exist a row i and column j such that
: 1) all elements of row i are zeros
: 2) all elements of column j are 1s
: 3)(i,j) entry can be either 0 or 1
: my thinking is:
: sum each row and each column
: if sumRow[i] > 1 mark it false
: if sumCol[i] : also for those rows and cols,if they are not marked false, record the 1 posi

m*****f
发帖数: 1243
6
虽然是矩阵乘法, 可是计算的时候用的都是加法阿...
本来就是O(n^2), 要判断某行某列是否都是1/0, 起码要scan整个matrix一遍罢,
不太可能少于O(n^2).

【在 m********0 的大作中提到】
: you forgot the complexity of
: matrix multiplication itself.
: in this case, still O(n^2).
: and '+' is faster than '*' in general.
: So what you offer is a worse solution.

1 (共1页)
进入JobHunting版参与讨论
相关主题
~~问两道AMAZON电面题问个sql问题
请教一道careercup 150上的题问个面试题
LeetCode上word search问题的几个例子不对AMAZON PHONE SCREEN 1 基本死掉。
interleave string 的题目顺时针打印MxN矩阵的简洁递归解法
大牛们看看这题:Find Peak Element II请教leetcode N-Queens II问题
电面题一个新鲜onsite面经
leetcode中那道Set Matrix Zeroes怎么做拿到offer,分享之前的一些onsite面试
Set Matrix Zeroes const space solutionleetcode wordsearch的时间复杂度?
相关话题的讨论汇总
话题: matrix话题: row话题: false话题: column话题: elements