Reaching Points with Perfect-Square Obstacles
Updated
Problem statement
A bot starts at the nonnegative integer coordinate (startX, startY) and wants to reach (targetX, targetY). A positive constant c is fixed for the entire journey.
From a coordinate (x, y), the bot may make exactly one of these moves:
- Move to
(x + y, y). - Move to
(x, x + y). - Move to
(x + c, y + c).
A coordinate is forbidden when x + y is a perfect square. The bot may never occupy a forbidden coordinate. This rule also applies to the starting and target coordinates.
Return "Yes" if a sequence of legal moves reaches the target. Otherwise, return "No".
Function
canReach(c: int, startX: int, startY: int, targetX: int, targetY: int) → StringExamples
Example 1
c = 1startX = 2startY = 1targetX = 3targetY = 5return = "Yes"The bot can move from (2, 1) to (3, 2) using the third move, then to (3, 5) using the second move. Neither visited sum is a perfect square.
Example 2
c = 2startX = 2startY = 7targetX = 10targetY = 12return = "No"The starting sum is 2 + 7 = 9, a perfect square, so no path is allowed.
Constraints
0 <= startX, startY, targetX, targetY <= 10001 <= c <= 15- Coordinates never decrease. On an axis, a move can leave the position unchanged.
- If either endpoint's coordinate sum is a perfect square, the answer is
"No". This includes sum0.
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Minimize Malware Spread by Removing a NodeVisa · OAVisa interview questions
- Minimize Malware Spread by Removing a NodeAkuna Capital · OAAkuna Capital interview questions
- Minimum Numeric Code TransformationAdobe · OAAdobe interview questions
- Satellite Network Message PropagationOptiver · OAOptiver interview questions
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Retryable URL MazeRamp · PHONE SCREENRamp interview questions
- Unit Conversion Across Independent FamiliesApple · PHONE SCREENApple interview questions
- Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Repeated-Roll Teleporter ReachabilitySplunk · PHONE SCREENSplunk interview questions