VOOZH about

URL: https://www.geeksforgeeks.org/dsa/missing-permutations-list/

⇱ Missing Permutations in a list - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Missing Permutations in a list

Last Updated : 4 Oct, 2023

Given a list of permutations of any word. Find the missing permutation from the list of permutations. 

Examples:

Input : Permutation_given[] = {"ABCD", "CABD", "ACDB", 
"DACB", "BCDA", "ACBD", "ADCB", "CDAB",
"DABC", "BCAD", "CADB", "CDBA", "CBAD",
"ABDC", "ADBC", "BDCA", "DCBA", "BACD",
"BADC", "BDAC", "CBDA", "DCAB"};
Output : DBAC DBCA

Approach:

  1. We create a set of all given strings. 
  2. And one more set of all permutations. 
  3. Finally return difference between the two sets. 

Implementation:


Output
DBAC
DBCA

Time Complexity: O(n!) where n is the length of the first string in the input
Auxiliary Space: O(n!), because we need to store all possible permutations of the input string in memory

Comment