Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tasks Implement the following function that produces all the possible permutations of a given set of numbers. std::vector permute(std::vector &nums); Here are some example

image text in transcribed

Tasks Implement the following function that produces all the possible permutations of a given set of numbers. std::vector permute(std::vector &nums); Here are some example borrowed from LeetCode: Input: nums = [1,2,3] Output: [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] Input: nums = [1,0] Output: [[0,1],[1,0]] There is no duplicated numbers in the input array. The implementation should be O(1) space which means no additional memory buffer such as array/vector/stack/queue can be used. If you are not sure, check with the instructor. This quiz is an open form where you will be writing both the function and test. Upon completion, your tests should prove to the best of its effort that your function is correct. The instructor has his own set of test cases and your code will also be evaluated by that. Altough this does not directly determine the grade. Grading Standard 1. No late submission. Any late submission will be treated as no submission. Zero point. 2. At least 5 reasonable test cases need to be provided and passed. Here's a few possible cases to cover: empty innput, single number, sorted and unsorted inputs, unordered output. +5 for more than 5 test cases. Submission Same as homework, submit your PR in Canvas. What if there's duplicates (with credits counted towards your midterm) If there's duplicates in the input, how would you implement the permute instead? 10 extra credit (counted towards midterm): Write a separate function with its own tests that can handle input with duplicated numbers. For this part, it's okay to use additional buffer (hint: map).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions