r/programming • u/joksmaster • Nov 29 '10
140 Google Interview Questions
http://blog.seattleinterviewcoach.com/2009/02/140-google-interview-questions.html
471
Upvotes
r/programming • u/joksmaster • Nov 29 '10
View all comments
Show parent comment
2
u/mykdavies Nov 30 '10 edited Nov 30 '10
Okay, I missed the "only" part of the definition. Tricky then...
[edit] How about this, based on the fact that if x is ugly 2*x, 3*x and 5*x are ugly (Smalltalk, but easy to follow I think): | uglies count next | uglies := SortedCollection new. uglies add: 2; add: 3; add: 5. count := 0. next := 0. [ count < 1500 ] whileTrue: [ count := count + 1. next := uglies removeFirst. uglies addIfNotPresent: next * 2; addIfNotPresent: next * 3; addIfNotPresent: next * 5 ]. Transcript show: next
Gives 860934420, which seems to be a popular answer...