Ad
  • Custom User Avatar

    To answer the question, not quite. If you had two eggs and 14 tries, and observed the first egg break on the Nth try, you then have one egg and 14-N tries remaining. In other words, the tries are cumulative. Notice therefore that increasing n beyond m has no effect, since you can use up at most m eggs no matter your strategy.

  • Custom User Avatar

    I agree 100% that this is an off-by-one error. If, as the description suggests, the target_floor (highest floor before the egg breaks) is 1 <= target_floor <= max_floor, and we are to find max_floor, then (n, m) = (0, 0) implies that max_floor = 1.

    If you instead use the definition that 0 <= target_floor <= max_floor then this is equivalent to solving the problem from the other perspective and then subtracting 1 from the resulting max_floor. Indeed, if you consider the algorithm for finding the target_floor, and if from the start it is assumed that k <= target_floor for some k, then it is useless for the algorithm to check any floors at or below k. This effectively shifts the algorithm's search by k - 1 places and thus shifts the resulting max_floor by the same amount.

  • Custom User Avatar

    Respectable approach for sure, but I still feel that being able to prove the answer is what you suspect it to be is also a pretty important skill (not sure if that's what you meant or not).

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Oxford comma, anyone?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    In python specifically (don't know about other languages), the predefined test cases are all of lengths divisible by three, which makes for very clean encoding and decoding. Among the random cases, however, those that violate this property are inevitably encountered. It would be helpful if some of the predefined/sample cases had this property so that it would be easier to debug an issue related to this.

  • Default User Avatar