Add Two Promises — LeetCode 2723 Python Solution

EasyJavaScript
Problem
#2723
Reading time
2 min

The problem

Given two promises promise1 and promise2, return a new promise. promise1 and promise2 will both resolve with a number.

Example

Input
promise1 = new Promise(resolve => setTimeout(() => resolve(2), 20)),
Output
7
Explanation
The two input promises resolve with the values of 2 and 5 respectively. The returned promise should resolve with a value of 2 + 5 = 7. The time the returned promise resolves is not judged for this problem.

Complexity

MeasureComplexity
TimeO(n)
SpaceO(1) to O(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2723. Add Two Promises?
LeetCode 2723. Add Two Promises is rated Easy on LeetCode.
What topics does LeetCode 2723. Add Two Promises cover?
LeetCode 2723. Add Two Promises is tagged JavaScript on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview