Problem · Math
Is Possible
Learn this problemProblem statement
Consider a pair of integers, (a, b). The following operations can be performed on (a, b) in any order, zero or more times.
- (a, b) → (a + b, b)
- (a, b) → (a, a + b)
Return a string that denotes whether or not (a, b) can be converted to (c, d) by performing the operation zero or more times.
Function
isPossible(a: int, b: int, c: int, d: int) → String
Complete the function isPossible in the editor.
isPossible has the following parameter(s):
int a: first value in (a, b)int b: second value in (a, b)int c: first value in (c, d)int d: second value in (c, d)
Returns
string: "Yes" if possible, otherwise "No"
Examples
Example 1
a = 1b = 1c = 5d = 2return = "Yes"Perform the operation (1, 1 + 1) to get (1, 2), perform the operation (1 + 2, 2) to get (3, 2), and perform the operation (3+2, 2) to get (5, 2). Alternatively, the first operation could be (1+1, 1) to get (2, 1) and so on. The diagram below demonstrates the example that represents the pairs as Cartesian coordinates:
[Graph with points (1,1), (1,2), and (3,2) plotted, leading to the "Goal" point (5,2)]
Constraints
1 <= a, b, c, d <= 1000More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Word LadderPHONE SCREEN · Seen Jun 2026