FastPrepReaching Points with Perfect-Square Obstacles
Problems/Reaching Points with Perfect-Square Obstacles

Reaching Points with Perfect-Square Obstacles

IMC Trading logoIMC Trading● MediumFULLTIMEINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading online assessment. The report allows coordinates from 0 through 1000 and c from 1 through 15, and either endpoint may be blocked. Our method uses clear parameter names and returns "Yes" or "No". Our version is about 99% the same as the captured report.

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:

  1. Move to (x + y, y).
  2. Move to (x, x + y).
  3. 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) → String

Examples

Example 1

c = 1startX = 2startY = 1targetX = 3targetY = 5return = "Yes"
Example 1 illustration

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 <= 1000
  • 1 <= 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 sum 0.

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

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)
  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public String canReach(int c, int startX, int startY, int targetX, int targetY) {
        // Write your solution here.
    }
}
Checking account…