Re: interview question on primes
- From: quasi <quasi@xxxxxxxx>
- Date: Mon, 25 Feb 2008 20:34:30 -0500
On Mon, 25 Feb 2008 16:54:03 -0800 (PST), Digital Puer
<digital_puer@xxxxxxxxxxx> wrote:
Got this on a software engineering interview question:
given two integers A and B, find all primes between them.
I basically wrote an initial function, bool isPrime(int i), which
loops over all numbers between 2 and sqrt(i) to see if i%num == 0,
in which case the number is not a prime. With this function, I then
loop between A and B, calling isPrime() on each value.
Any better ideas?
For an interview, I think that's fine -- no need to get fancy.
In fact, had you tried for greater order of magnitude efficiency at
the expense of clarity, that would have shown bad judgement.
Think about it from the _interviewer's_ point of view. Why are they
asking this question? They can't assume that the applicant is a Number
Theory expert, hence they would naturally expect a simple algorithm.
If the applicant can't even manage get _some_ algorithm, or makes
manages one, but makes a mess of it, that shows a lack of basic
mathematical understanding and/or a lack of programming skills.
On the other hand, if the applicant goes overboard and tries to make a
research project out of it, that's also bad sign. It suggests that for
real world projects, there would likely be missed deadlines, not to
mention complex, hard to maintain code.
Based on that analysis, I think you handled it just right.
quasi
.
- References:
- interview question on primes
- From: Digital Puer
- interview question on primes
- Prev by Date: AAA Fashion DKNY Replica Watches At AAA-Replica-Watches.com
- Next by Date: "What is the purpose of life?"
- Previous by thread: Re: interview question on primes
- Next by thread: Re: interview question on primes
- Index(es):
Relevant Pages
|