Medium
Quiz
#470 Implement Rand10() Using Rand7()
APPROACH
You are given access to rand7(), which uniformly returns a random integer in [1, 7]. Implement rand10() so that it uniformly returns a random integer in [1, 10]. You may only call rand7(); no other random API is permitted.
Each test case has an internal count n indicating how many times your rand10() will be called.
Example 1:
Input: n = 1
Output: [2]
Example 2:
Input: n = 2
Output: [2,8]
Example 3:
Input: n = 3
Output: [3,8,10]
1 of 4
1:00
What is the optimal approach for this problem?