Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

98. Permutations

MediumDay 28 of 60Recursion & Backtracking

Given an array nums of distinct integers, return every possible ordering (permutation) of its elements. You may return the permutations in any order.

Example 1
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2
Input: nums = [0,1]
Output: [[0,1],[1,0]]
Constraints
  • 1 <= nums.length <= 6
  • -10 <= nums[i] <= 10
  • All values are distinct
Hints
Frequently asked at: Amazon, Microsoft, Google, LinkedIn
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min