Print Permutations of an array with duplicate elements
Vložit
- čas přidán 7. 09. 2024
- Given an array with duplicate elements. Print all the unique permutations of elements of the array. In part-1 of this problem we discussed the solution where there are no duplicates in the array.
Part-1: • Print Permutations of ...
Covers Following Leetcode Problems:
46. leetcode.com/p...
47. leetcode.com/p...
-----------------------------------------------------
Join our 30-days online course to prepare for coding interviews of companies like Google, Amazon, Facebook, Microsoft, etc.
Course On Coding: www.ritambhara....
Course On System Design: www.ritambhara....
We have our office in Greater Noida (India) where we run courses for students to prepare them for placements in Top IT companies. For Placement Preparation and Industrial Training call us.
Call: +91-8377803450
Email: krawat@ritambhara.in
Call us to conduct a workshop in your college campus.
Buy our books and prepare for coding interviews on your own.
www.amazon.in/...
For detailed discussions on Interview Questions visit:
www.ritambhara.in/
Clear and Concise. Amazing video!
loved it sir!
hash map solution is so easy
great explanation
7:40 The video starts here
Thank you
BRILLIANT
well explained!!
Nice video. However, I still haven't understood which part of the logic prevent the printing 122, 122. 1 is the only non-repeating element. But after fixing that 1 you are left with the subset {2,2} and this subset is then permuted. Shouldn't there be a condition/contrain on that subset to prevent the same permutation being printed twice?.
Your logic, to my understanding, only goes to show how to avoid fixing a duplicate element in a given set more than once. Hence compressing the output: 212, 221 and 221,212 into just 212 and 221.
Exactly
Having the hashset at each level will solve the issue.
After fixing 1, then we call recursively same function again for 2,2 and hence again there will be a hashmap to prevent permutation
Sir how to show 100 ^ 50 permutation list,plz answer me
what's the space complexity of this approach? Will it be O(N) or O(N*N) as the recursion goes deep till n and at each level we could have a HashSet of size N.
should be O(N*N)
O(N*N!)
Getting wrong answer
public class Solution {
ArrayList ans = new ArrayList();
public int[][] permute(int[] A) {
ArrayList a = new ArrayList();
for(int i=0; i 0)
cols = ans.get(0).size();
int[][] r = new int[rows][cols];
for(int i=0; i
Thank you