Find Permutation Problem Statement

Given an integer N, determine an array of size 2 * N that satisfies the following conditions:

  1. Each number from 1 to N appears exactly twice in the array.
  2. 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!
Select
Add answer anonymously...

JPMorgan Chase & Co. Machine Learning Engineer interview questions & answers

A Machine Learning Engineer was asked Q. Subset Sum Equal To K Problem Statement Given an array/list of positive integers...read more
A Machine Learning Engineer was asked Q. Maximum Number by One Swap You are provided with an array of N integers represen...read more
A Machine Learning Engineer was asked Q. Paths in a Matrix Problem Statement Given an 'M x N' matrix, print all the possi...read more

Popular interview questions of Machine Learning Engineer

A Machine Learning Engineer was asked Q1. Subset Sum Equal To K Problem Statement Given an array/list of positive integers...read more
A Machine Learning Engineer was asked Q2. Maximum Number by One Swap You are provided with an array of N integers represen...read more
A Machine Learning Engineer was asked Q3. Paths in a Matrix Problem Statement Given an 'M x N' matrix, print all the possi...read more
JPMorgan Chase & Co. Machine Learning Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits