Problem · Math
MediumGoldman SachsFULLTIMEOA

Problem 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):

  1. int a: first value in (a, b)
  2. int b: second value in (a, b)
  3. int c: first value in (c, d)
  4. 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 <= 1000

More Goldman Sachs problems

drafts saved locally
public String isPossible(int a, int b, int c, int d) {
  // write your code here
}
a1
b1
c5
d2
expected"Yes"
checking account