Category : permutation

I have written a letter case permutation, which perfectly for 8 letters, but gives me an error of time limit exceed in Leetcode for string size = 9. What can be optimized? Works for "L2tcnhpZ" but exceeds limit for "L2tcnhpZK" vector<string> result; vector<string> MyletterCasePermutation(string s) { genPerm(s, 0, s.size()-1); return result; } void genPerm(string s, ..

Read more

I’m currently trying to make a very fast anagram solver, and right now it’s bottlenecked by the creation of the permutations. is there another way to do the whole program or to optimize the permutation creation? here’s my code: #include <string> #include <vector> #include <algorithm> #include <iostream> #include <fstream> #include <unordered_set> #include <vector> #include <boost/asio/thread_pool.hpp> ..

Read more

Consider the code snippet: #include <vector> #include <algorithm> #include <stdio.h> int main(){ int szvec = 4; std::vector<int> vecint(szvec); for (size_t i = 0, szi = szvec; i < szi; i++){ vecint[i] = i; } do{ for (size_t i = 0, szi = vecint.size(); i < szi; i++){ printf("%dt", vecint[i]); } printf("n"); } while (std::next_permutation(vecint.begin(), vecint.end())); ..

Read more

Consider the code snippet: #include <vector> #include <algorithm> #include <stdio.h> int main(){ int szvec = 4; std::vector<int> vecint(szvec); for (size_t i = 0, szi = szvec; i < szi; i++){ vecint[i] = i; } do{ for (size_t i = 0, szi = vecint.size(); i < szi; i++){ printf("%dt", vecint[i]); } printf("n"); } while (std::next_permutation(vecint.begin(), vecint.end())); ..

Read more