Skip to content

Practice Implement Rand10() Using Rand7()

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#470
LeetCode Problem

Implement Rand10() Using Rand7()

Problem Statement

Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API. Each test case will have one internal argument n, the number of times that your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10().

Source: Implement Rand10() Using Rand7() on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1
Output
[2]

# Example 2

Input
n = 2
Output
[2,8]

# Example 3

Input
n = 3
Output
[3,8,10]

Constraints

1 <= n <= 10^5

Related LeetCode Problems

Practice more problems similar to Implement Rand10() Using Rand7().

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.