Beautiful Array
Medium · Array, Math, Divide and Conquer
An array nums of length n is beautiful if:
Given the integer n, return any beautiful array nums of length n. There will be at least one valid answer for the given n.
Example 1
Input: n = 4 Output: [2,1,4,3]
Example 2
Input: n = 5 Output: [3,1,2,5,4]
Constraints
- 1 <= n <= 1000
Starter code (python)
class Solution(object):
def beautifulArray(self, n):
"""
:type n: int
:rtype: List[int]
"""
Related problems
- Two Sum (Easy)
- Add Two Numbers (Medium)
- Median of Two Sorted Arrays (Hard)
Previous: Minimum Falling Path Sum · Next: Shortest Bridge · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.