shreya
BAN USER
Questions (2)
Reputation 25
- 1of 1 vote
AnswersGive an matrix of m *n with all the elements=1, Also given is a list of (x,y) points. The question is to zero out all the elements of xth row and yth column.
- shreya in United States
def mat(alist, xylist):
row = len(alist) #Find num of rows
col = len(alist[0]) #Finf num of columns
for tup in xylist:
x = tup[0]
y = tup[1]
for i in range(row):
alist[i][y] = 0 #Zero out the yth column in each row
for j in range(col):
alist[x][j] = 0 #Zero out the xth row in each column
#Print the final matrix
for list in alist:
print list
def main():
mat([[1,2,3],[4,5,6],[7,8,9], [10,11,12]], [(2,2),(1,1)])
if __name__ == '__main__':
main()| Report Duplicate | Flag | PURGE
Cloudera Software Engineer / Developer - -3of 3 votes
AnswersArray Pair Sum. Solve it in O(N) time complexity
- shreya in United States| Report Duplicate | Flag | PURGE
Cloudera Software Engineer / Developer Arrays
Page:
1
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.