Find Permutation Problem Statement
Given an integer N
, determine an array of size 2 * N
that satisfies the following conditions:
- Each number from
1
toN
appears exactly twice in the array. - The distance between the second and first occurrence of each number is equal to the number itself.
If no valid array can be constructed, return an empty array.
Example:
Input:
N = 3
Output:
[3, 1, 2, 1, 3, 2]
Constraints:
1 ≤ T ≤ 5
1 ≤ N ≤ 8
- Time Limit: 1 second
Input:
The input starts with an integer 'T' (the number of test cases).
For each test case, there is one line containing a single integer 'N'.
Output:
The output will indicate "Valid" if the returned permutation meets all the conditions, otherwise "Invalid". If an empty array is returned, the output will be -1.
Each test case result should be on a new line.
Note:
You are not required to print anything; implementation of the function suffices, as the result verification is handled automatically.

AnswerBot
4mo
The task is to find a permutation array of size 2*N with specific conditions.
Create an array of size 2*N to store the permutation.
Ensure each number from 1 to N appears exactly twice in the array.
Chec...read more
Help your peers!
Add answer anonymously...
Top Machine Learning Engineer Interview Questions Asked at JPMorgan Chase & Co.
Q. Subset Sum Equal To K Problem Statement Given an array/list of positive integers...read more
Q. Maximum Number by One Swap You are provided with an array of N integers represen...read more
Q. Paths in a Matrix Problem Statement Given an 'M x N' matrix, print all the possi...read more
Interview Questions Asked to Machine Learning Engineer at Other Companies
Top Skill-Based Questions for JPMorgan Chase & Co. Machine Learning Engineer
Machine Learning Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Python Interview Questions and Answers
200 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

