For some fixed n, an array nums is beautiful if it is a permutation of the integers 1, 2, ..., n, such that for every i < j, there is no k with i < k < j such that nums[k] * 2 = nums[i] + nums[j]. Given n, return any beautiful array nums. (It is guaranteed that one exists.)
Computer scienceProgramming languagesJavaInterview preparationAlgorithms and problem solving techniques
Understand the problem
Beautiful array
Report a typo
Sample Input 1:
4Sample Output 1:
[1, 3, 2, 4]Write a program in Java 17
import java.util.Arrays;
import java.util.Scanner;
class BeautifulArray{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
//write your code here
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.