Am I stupid or do both of the solutions to the problem "Replace each element of array with product of every other element without using / operator" use the / operator? My solution would involve summing the log() of the values in the array.
Data structures and algorithms interview questions and their solutions
21–30 of 36 posts
Re: Data structures and algorithms interview questions and their solutions
#22Re: Data structures and algorithms interview questions and their solutions
#23That's a great list worthy of study in any context.
Re: Data structures and algorithms interview questions and their solutions
#24If this isn't a metaphor for the programming interview I don't know what is: http://www.techiedelight.com/multiply-two-numbers-without-us... "Implement multiplication without using loops." "Uh, okay. What do you mean by loops?" "Don't use a conditional loop." "What do you mean by a conditional loop?" "Oh, you know, the standard definition." Time passes. "I'm stuck. What is the answer?" "Oh, you just have a loop on b…
The real way to multiply without loops is to use a lookup table, or unroll the (fixed iteration) shift-and-add loop. That page is both hilarious and sad at the same time. Hilarious because the second "solution" clearly has a loop, and sad because sites like those don't really help anyone. Some of the pages on that site are downright WTF s: http://www.techiedelight.com/generate-binary-numbers-1-n/
Can you elaborate on this? I understand the shifting but didn't understand the "loop unrolling fixed iteration part"
Re: Data structures and algorithms interview questions and their solutions
#25Earlier quoted context omitted.
Mult(A,B) = Exp(Log(A) + Log(B))
You didn't pass (overqualified, will likely be bored by the job).
Edit: how about
(Math.Pow(a+b, 2) - Math.Pow(a,2) - Math.Pow(b,2))/2
Re: Data structures and algorithms interview questions and their solutions
#26Earlier quoted context omitted.
The real way to multiply without loops is to use a lookup table, or unroll the (fixed iteration) shift-and-add loop. That page is both hilarious and sad at the same time. Hilarious because the second "solution" clearly has a loop, and sad because sites like those don't really help anyone. Some of the pages on that site are downright WTF s: http://www.techiedelight.com/generate-binary-numbers-1-n/
>"or unroll the (fixed iteration) shift-and-add loop" Can you elaborate on this? I understand the shifting but didn't understand the "loop unrolling fixed iteration part"
Re: Data structures and algorithms interview questions and their solutions
#27I'd rather just not interview at companies that have these kinds of interviews and save myself the hassle.
Interview processes are generally completely arbitrary, the interviewers chosen at the last minute by the hiring manager, and they're not changed because they're sort of good enough.
If you dislike these types of interviews sufficiently on their own merits that you want to avoid them, fine. But don't think you're learning anything about companies just because they use them.
Re: Data structures and algorithms interview questions and their solutions
#28Didn't most of us get in to this mathsy line of work precisely because we didn't need to memorise a load of stuff and could just work things out from first principles as and when required?
Re: Data structures and algorithms interview questions and their solutions
#29If this isn't a metaphor for the programming interview I don't know what is: http://www.techiedelight.com/multiply-two-numbers-without-us... "Implement multiplication without using loops." "Uh, okay. What do you mean by loops?" "Don't use a conditional loop." "What do you mean by a conditional loop?" "Oh, you know, the standard definition." Time passes. "I'm stuck. What is the answer?" "Oh, you just have a loop on b…
Re: Data structures and algorithms interview questions and their solutions
#30If this isn't a metaphor for the programming interview I don't know what is: http://www.techiedelight.com/multiply-two-numbers-without-us... "Implement multiplication without using loops." "Uh, okay. What do you mean by loops?" "Don't use a conditional loop." "What do you mean by a conditional loop?" "Oh, you know, the standard definition." Time passes. "I'm stuck. What is the answer?" "Oh, you just have a loop on b…
I was asked something like this in Amazon SE interview - find something without using loops, the answer was to use recursion. Sigh.
I would argue that a loop constructs an answer, while recursion deconstructs input.
There's a duality, so you can port algorithms between the two models, but there is an actual distinction.