bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 667. Beautiful Arrangement II

667. Beautiful Arrangement II

Leetcode Solutions

Approach #: Construction

  1. Initialize an empty list answer.
  2. Add the numbers from 1 to n - k - 1 to answer in increasing order.
  3. Set left to n - k and right to n.
  4. For i from 0 to k, alternate between adding left and right to answer:
    • If i is even, add left to answer and increment left.
    • If i is odd, add right to answer and decrement right.
  5. Return the constructed answer list.
UML Thumbnail

Approach #: Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...