Simulation: Build Generations
This was a very interesting problem in my opinion. It is a classic exercise in simulation, especially related to population growth. The constraints are small enough that you can brute-force and you'll be fine. Some techniques worth mentioning: 1/ Use a hash set for quick verification whether a point is in the generation 2/ Hash using the boundaries - using 7 as a seed works, hence x*7*7 + y*7 + z is a solid hash without the worry of overflowing 3/ Use two lists for generations: current and next 4/ Build next generation using an N^2 approach (it is OK since N = 6) 5/ Prune using the fact that the points in the next generation always have smaller numbers (due to the floor((a+b)/2)), hence if ever any of the indexes of your target is larger than the largest corresponding index in the current generation, you can safely assume that there won't be a solution. Also, prune using the fact that if the next generation isn't larger than the previous one, no solution will be found Code ...