Algorithm Interview Report
- 0of 0 votes
Answersgiven N people. one person can like one or more than one persons. But not mandatory to like any one. Find leader in that N people. Leader is a person , who is being liked by all , but he should not like any one else.
- gopi.komanduri December 28, 2011 in India
Idea I have is:
ex: lets assume set is A,B,C. A likes B,C. B likes C,A. C don't like any one.
Create an array of N and initialize to zero.
Now for every like to other person , decrement the corresponding value , and increment the liked person value.Now at the end , the index whose value is N-1 , will be leader.
In now example
step 1 arr[3] = 0,0,0
step 2 (a likes b , c) = -2,1,1
step 3: (b likes a and c) = -1 (-2 + 1 (because being liked by b),-1 (1 -2 (likes two people) , 2 (1 + 1 (being liked by b))
-1,-1,2.
So here C is the leader.
Please discuss if there are any flaws or abt better ideas.| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven two sorted arrays of sizes N,M (N > M).
- gopi.komanduri December 28, 2011 in India
N has M gaps even though it is sorted. (gaps can be in between . Not required to be at the end).
Best algorithm to merge these two arrays , with out using any extra space.| Report Duplicate | Flag | PURGE
Algorithm