Tech Interview

Prime number problem

You need to a number of floors in a building. There are 68 floors (numbered 1 to 64).

Conditions:
1. Can’t buy floors which numbers are prime.
2. Cannot buy floors which number contains a prime digit.
3. Can’t buy floor number 1.
4. Distance between all purchased floors must be different (i.e. you can’t buy floors 4, 6, and 8 because they both have 1 floor between them).
5. Distance between all purchased floors must be prime.

Using code or pseudocode figure out:
1. Maximum number of floors you can buy using conditions 1, 2 and 3?
2. Maximum number of floors you can buy using all conditions?

Exit mobile version