Skip to content

Conversation

@Yatin-aggarwal
Copy link

Problem Description:

Given an array points where points[i] = [xi, yi] represents coordinates on the 2D plane, return the minimum time required to visit all points in order. In one second, you can move:
1 unit horizontally,
1 unit vertically,
OR 1 unit diagonally (both horizontal and vertical at the same time).

Approach:

  • For each pair of consecutive points:
    • Compute the distance in x and y directions:
      • x = abs(x2 - x1)
      • y = abs(y2 - y1)
  • To reach from one point to the next:
    • Take min(x, y) diagonal steps (covers both axes).
    • Then take abs(x - y) straight steps (either horizontal or vertical).
  • Therefore, the total time (steps) needed for each pair is:
    • min(x, y) + abs(x - y)
    • Which simplifies to: max(x, y)
  • Repeat this process for all consecutive point pairs in the list using a simple loop.

Complexity:

  • Time Complexity: O(n)
  • Space Complexity: O(1)

Let me know if you'd like it in a code comment style or in a rendered preview.

@Yatin-aggarwal Yatin-aggarwal changed the title Create 1266-Minimum-Time-Visiting-All-Points Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant