# Missing Permutations in a list

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

1) We create a set of all given strings.

2) And one more set of all permutations.

3) Finally return difference between two sets.

`#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `void` `find_missing_strings(string Permutation_given[], ` `size_t` `Size_Permutation_given) ` `{ ` ` ` `// vector "permutation" containing all ` ` ` `// the permutation of input string ` ` ` `vector<string> permutations; ` ` ` ` ` `// Here we can take any string ` ` ` `// from the given list and do ` ` ` `// the necessary permutation ` ` ` `string input = Permutation_given[0]; ` ` ` `permutations.push_back(input); ` ` ` ` ` `// In the loop we will store ` ` ` `// all the permutations of the string ` ` ` `// in the vector "permutation". ` ` ` `while` `(` `true` `) { ` ` ` ` ` `string p = permutations.back(); ` ` ` ` ` `// Getting next permutation of input string ` ` ` `next_permutation(p.begin(), p.end()); ` ` ` `if` `(p == permutations.front()) ` ` ` `break` `; ` ` ` ` ` `permutations.push_back(p); ` ` ` `} ` ` ` ` ` `// vector containing all the ` ` ` `// missing strings in permutation ` ` ` `vector<string> missing; ` ` ` ` ` `// given_permutations contains the ` ` ` `// permutation of the input string ` ` ` `set<string> given_permutations(Permutation_given, ` ` ` `Permutation_given + Size_Permutation_given); ` ` ` ` ` `// Through the set difference we will get ` ` ` `// the missing words in vector missing ` ` ` `set_difference(permutations.begin(), permutations.end(), ` ` ` `given_permutations.begin(), ` ` ` `given_permutations.end(), ` ` ` `back_inserter(missing)); ` ` ` ` ` `// printing all the missing string ` ` ` `for` `(` `auto` `i = missing.begin(); i != missing.end(); ++i) ` ` ` `cout << *i << endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `string Permutation_given[] = { ` ` ` `"ABCD"` `, ` `"CABD"` `, ` `"ACDB"` `, ` `"DACB"` `, ` ` ` `"BCDA"` `, ` `"ACBD"` `, ` `"ADCB"` `, ` `"CDAB"` `, ` ` ` `"DABC"` `, ` `"BCAD"` `, ` `"CADB"` `, ` `"CDBA"` `, ` ` ` `"CBAD"` `, ` `"ABDC"` `, ` `"ADBC"` `, ` `"BDCA"` `, ` ` ` `"DCBA"` `, ` `"BACD"` `, ` `"BADC"` `, ` `"BDAC"` `, ` ` ` `"CBDA"` `, ` `"DCAB"` ` ` `}; ` ` ` ` ` `// size of permutation list ` ` ` `size_t` `Size_Permutation_given = ` ` ` `sizeof` `(Permutation_given) / ` ` ` `sizeof` `(*Permutation_given); ` ` ` ` ` `find_missing_strings(Permutation_given, ` ` ` `Size_Permutation_given); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

Output:

DBAC DBCA

## Recommended Posts:

- Generate all binary permutations such that there are more or equal 1's than 0's before every point in all permutations
- Permutations of a given string using STL
- Problem on permutations and combinations | Set 2
- Number of palindromic permutations | Set 1
- Check if two arrays are permutations of each other
- All permutations of a string using iteration
- Distinct permutations of the string | Set 2
- Find the missing value from the given equation a + b = c
- Generate all cyclic permutations of a number
- Print all permutations of a string in Java
- Find the number of good permutations
- Print k different sorted permutations of a given array
- Count permutations that are first decreasing then increasing.
- Sum of all numbers that can be formed with permutations of n digits
- Count the number of special permutations

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.