Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a recursive, decrease-and-conquer function PERMUTATIONS that receives an array nums of distinct integers and returns all permutations of nums such that all permutations

 

Create a recursive, decrease-and-conquer function PERMUTATIONS that receives an array nums of distinct integers and returns all permutations of nums such that all permutations ending in an even number come before all permutations ending in an odd number. Your code must pass all test cases at https://leet code.com/problems/permutations/. Note: the given problem on Leet Code requires the permutations in any order. You must output the permutations in the order described above to receive full credit. Note also that there are some solutions posted on Leet Code that do not use decrease and conquer or recursion and do not output the permutations in the required order. These are not acceptable solutions. Some solutions posted may also be incorrect. In any case, if we find a solution that is largely copied from another source (e.g., verbatim or simply with different variable names), it will be considered a violation of the academic honesty policy. Example 1 input: [1, 4, 5] output: [[1, 5, 4], [5, 1, 4], [1, 4, 5], [4, 1, 5], [4, 5, 1], [5, 4, 1]] Example 2 input: [1, 2] output: [[1, 2], [2, 1]] Example 3 input: [1, 3, 5, 7] output: [[1, 3, 5, 7], [1, 3, 7, 5], [1, 5, 3, 7], [1, 5, 7, 3], [1, 7, 3, 5], [1, 7, 5, 3], [3, 1, 5, 7], [3, 1, 7, 5], [3, 5, 1, 7], [3, 5, 7, 1], [3, 7, 1, 5], [3, 7, 5, 1], [5, 1, 3, 7], [5, 1, 7, 3], [5, 3, 1, 7], [5, 3, 7, 1], [5, 7, 1, 3], [5, 7, 3, 1], [7, 1, 3, 5], [7, 1, 5, 3], [7, 3, 1, 5], [7, 3, 5, 1], [7, 5, 1, 3], [7, 5, 3, 1]]

Step by Step Solution

3.38 Rating (170 Votes )

There are 3 Steps involved in it

Step: 1

Here is the recursive decreaseandconquer function Pernotations in Python that generates permutations ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithm Analysis in Java

Authors: Mark A. Weiss

3rd edition

132576279, 978-0132576277

More Books

Students also viewed these Programming questions

Question

Prove Theorem 10.8. If ki =1 i Answered: 1 week ago

Answered: 1 week ago

Question

What are the basic assumptions in locational break-even analysis?

Answered: 1 week ago