Tiktok | OA | Real Programmer's Game
Anonymous User
7370

None of my friends have been able to come up with a solution for this.

The Question basically asks:

Given an integer N indicating the health of a monster, what is the probability that you will kill the monster by swinging sticks at the monster K times? With each swing, you have the probability of reducing the monster by an evenly distributed random number from 0 to M.

For example,

N = 2, M = 1, K = 3
12.5% 0, 0, 0 Not Killed
12.5% 0, 0, 1 Not Killed
12.5% 0, 1, 0 Not Killed
12.5% 0, 1, 1 Killed
12.5% 1, 0, 0 Not Killed
12.5% 1, 0, 1 Killed
25.0% 1, 1 Killed

As you can see, there is a 50% probability we kill the monster, so we return 0.5.

This post has more info: https://leetcode.com/discuss/interview-question/945519/tiktok-oa-new-grad-2021

Comments (7)