Reach a Target by Adding Coordinates
Updated
Problem statement
Start at the point (a, b). In one move, replace (x, y) with either (x + y, y) or (x, x + y).
Return "Yes" if you can reach (c, d) using zero or more moves. Otherwise return "No".
Function
isPossible(a: int, b: int, c: int, d: int) → StringExamples
Example 1
a = 1b = 4c = 5d = 9return = "Yes"Use (1, 4) → (5, 4) → (5, 9). Both moves add one coordinate to the other.
Example 2
a = 1b = 2c = 2d = 3return = "No"The first move reaches (3, 2) or (1, 3). The first point already exceeds the target x-coordinate; moving from the second point next exceeds the target in one coordinate. Coordinates never decrease.
Example 3
a = 7b = 7c = 7d = 7return = "Yes"The start is already the target, so no moves are needed.
Example 4
a = 1b = 1c = 5d = 2return = "Yes"Use the path (1, 1) → (1, 2) → (3, 2) → (5, 2). Each step adds one coordinate to the other.
Constraints
1 <= a, b, c, d <= 1000
More JP Morgan Chase Onsite Interview questions
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU CacheONSITE INTERVIEW · Seen Nov 2026
- Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
- Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
- K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
- Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
- Two SumONSITE INTERVIEW · Seen Nov 2025
- Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
- Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
- Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024
Similar questions at other companies
- Integer BreakAmazon · ONSITE INTERVIEW
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions
- Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
- Maximum 69 NumberHSBC · ONSITE INTERVIEWHSBC interview questions
- Maximize the Chance of Selecting the Best CandidateGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximum Bananas Delivered by a CamelStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- Fewest Bills and CoinsCapital One · ONSITE INTERVIEWCapital One interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Task Scheduler with CooldownGoDaddy · OA
JP Morgan Chase interview experiences
- JPMorgan Chase Experienced SWE Java Interview: 1 Experience
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)