Back to course home
0% completed
Vote For New Content
Solution: Beautiful Array
Problem Statement
Given a positive integer N
, construct a beautiful array of size N
containing the number [1, N]
.
An array beautiful if it follows the conditions below.
- If for any three indices
i
,j,
k
(withi < j < k
),A[j] * 2
is not equal toA[i] + A[k].
Examples
Example 1
- Input:
4
- Expected Output:
[2, 1, 4, 3]
- Justification: In this array, no combination of
i
,j
,k
(wherei < j < k
) exists such that2 * A[j] = A[i] + A[k]
.
Example 2
- Input:
3
- Expected Output:
[1, 3, 2]
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page