2621. Sleep LeetCode Solution
In this guide, you will get 2621. Sleep LeetCode Solution with the best time and space complexity. The solution to Sleep problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Sleep solution in C++
- Sleep solution in Java
- Sleep solution in Python
- Additional Resources

Problem Statement of Sleep
Given a positive integer millis, write an asynchronous function that sleeps for millis milliseconds. It can resolve any value.
Example 1:
Input: millis = 100
Output: 100
Explanation: It should return a promise that resolves after 100ms.
let t = Date.now();
sleep(100).then(() => {
console.log(Date.now() – t); // 100
});
Example 2:
Input: millis = 200
Output: 200
Explanation: It should return a promise that resolves after 200ms.
Constraints:
1 <= millis <= 1000
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
2621. Sleep LeetCode Solution in C++
async function sleep(millis: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, millis);
});
}
/* code provided by PROGIEZ */
2621. Sleep LeetCode Solution in Java
N/A
// code provided by PROGIEZ
2621. Sleep LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.