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.
I am new to this website. I don't know why I can't submit a reply to a reply. So I copy my previous (fixed) answer, appended by my explanation to it.
- skw_kevin March 29, 2016Find the greatest common divisor (GCD) of N and L. Then the ball comes back to person #1 after N/GCD(N,L) passing. So the answer should be (M-1)*N/GCD(N,L).
Oh there is a tiny mistake in my previous formula. I think I have fixed it. It should be (M-1)*N/GCD(N,L), instead of M*N/GCD(N,L), because once a person reaches the ball for M times, the game stops, and the M-th round is not completed. Only (M-1) rounds are completed.
The intuition of the formula is this: When the group of people passing the ball, starting from person #1, the ball must come back to #1 some time. (Why? Hint: the number of people is finite. Hint2: proof by contradiction.)
How many passing has been made before the ball comes back? The answer is N*GCD(N,L). (Why? Hint: When GCD(N,L)=1, how many numbers have been covered before the ball comes back to #1? Does every number covered? When GCD(N,L)=2, how many numbers have been covered before the ball comes back to #1? Does every number covered? or only half? If only half have been covered, will the other half of numbers be covered if the ball starts at person#2? What if GCD(N,L)=3?)
Think about the above questions, you will find that if GCD(N,L)=x, only 1/x of those people have touched the ball before the ball comes back to person#1. If you start passing the ball from person#k (where 1<k<x) instead of person#1, another group of people will touch the ball. See this wikipedia page for more theoretical knowledge: en.wikipedia[DOT]org/wiki/Ring_(mathematics) )
So, starting from person#1, when the ball comes back to person#1 there have been N/GCD(N,L) people touch the ball once. Or equivalently, there have been N/GCD(N,L) many passing. Then, no matter whether the passing direction is changed, those people who have touched the ball will touch it again within the next N/GCD(N,L) passing. If the limit M is not reached, these N/GCD(N,L) people keep passing the ball. Other people will never have opportunity to touch it.
When will the repetition stop? When SomeONE is going to touch the ball for the M-th time. How many times has the ball come back to person#1 before that? M-1. So there are (M-1)*(N/GCD(N,L)) many passing.