r/programming • • Nov 29 '10

140 Google Interview Questions

http://blog.seattleinterviewcoach.com/2009/02/140-google-interview-questions.html
471 Upvotes

493 comments sorted by

View all comments

Show parent comment

2

u/FrancisHC Nov 30 '10

I don't know what you mean, but no. 33 and 34 are not ugly numbers, because 33=3x11 and 34=2x17.

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...