Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create 1266-Minimum-Time-Visiting-All-Points.py#4343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Yatin-aggarwal wants to merge1 commit intoneetcode-gh:main
base:main
Choose a base branch
Loading
fromYatin-aggarwal:patch-2

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:
    • Takemin(x, y) diagonal steps (covers both axes).
    • Then takeabs(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-aggarwalYatin-aggarwal changed the titleCreate 1266-Minimum-Time-Visiting-All-PointsCreate 1266-Minimum-Time-Visiting-All-Points.pyJul 6, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@Yatin-aggarwal

[8]ページ先頭

©2009-2025 Movatter.jp