Asked inMathWorks,Engineering Development Group
Arrangement

You are given a number 'N'. Your goal is to find the number of permutations of the list 'A' = [1, 2, ......, N], satisfying either of the following conditions:

A[i] is divisible by i or i is divisible by A[i], for every 'i' from 1 to 'N'.

Input Format:
The first line of the input contains ‘T’ denoting the number of test cases.

The first line of each test case contains an integer N.
Output Format:
For each test case return the number of satisfying permutations in a new line.

Note:

You do not need to print anything or take input. This already has been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
0 <= N <= 15

Time Limit: 1 sec
CodingNinjas
author
2y
All possible permutations
  • In the brute force method, we can find out all the arrays that can be formed using the numbers from 1 to ‘N’(all permutations).
  • Then, we iterate over all the elements of every...read more
CodingNinjas
author
2y
Backtracking approach

The idea behind this approach is to construct permutations recursively while satisfying the divisibility criteria for each index as we build it.

We create a boolean array so that w...read more

Help your peers!
Add answer anonymously...
MathWorks Engineering Development Group Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter