Back to course home
0% completed
Beautiful Array (medium)
Problem Statement
Given a positive integer N
, construct a beautiful array of size N
containing the number [1, N]
.
An array is 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!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible