is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
"""
- biekan August 12, 2015Problem Breakdown
if i != j and matrix[i][j] == 1
i can't be influencer, otherwise j can't be
so everyone comparison, there is one exclude
There can only be one influencer
Use queue (FIFO) to arrange comparisons like sports match
for example, for 8 teams, there are 4+2+1=7 to get winner
pop two people, compare, get winner back in queue, until there is 1 winner
"""
class Solution:
def getInfluencer(self, matrix):
# Initialize data structure
N = len(matrix)
queue = range(N)
# Use N-1 compare to find potential influencer
while len(queue) > 1:
x = queue.pop(0)
y = queue.pop(0)
if matrix[x][y] == 1:
queue.append(y)
else:
queue.append(x)
# Check if winner is real influencer
z = queue[0]
for i in xrange(N):
if i != z and matrix[z][i] == 1:
return []
for i in xrange(N):
if i != z and matrix[i][z] == 0:
return []
return queue[0]