Dropbox Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

Approach 1 :

We precompute the value of factorial modulo p in an array..
then we get an expression of the form (a/b)%p
We evaluate this with the help of the euler phi function..

Approach 2:
Use Lucas theorem.. Much more elegant method..
For non-negative integers m and n and a prime p, the following congruence relation holds:

\binom{m}{n}\equiv\prod_{i=0}^k\binom{m_i}{n_i}\pmod p,

where

    m=m_kp^k+m_{k-1}p^{k-1}+\cdots +m_1p+m_0,

and

    n=n_kp^k+n_{k-1}p^{k-1}+\cdots +n_1p+n_0

are the base p expansions of m and n respectively. This uses the convention that \tbinom{m}{n} = 0 if m < n.

- coffeewithkaran007 July 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How does approach 2 work in the case where p is not a prime (as asked in the question) ?

- Pankaj September 29, 2017 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More