Category : backtracking

Two strings s1 and s2 are Twiddles if they have the same length and each character in the same position differs by at most 2. For instance, "eschew" and "craggy" are Twiddles as the differences between consecutive characters are respectively -2, -1, -2, -1, 2, 2. I’m trying to write a function listTwiddles that takes ..

Read more

I’m testing my app, which has a lot of C++, in debug. Even though it’s compiled in debug, and the C++ code is compiled by my own app (thus is compiled in debug mode also), I get crash backtraces like this: 09-23 19:16:32.672 14123 14123 F DEBUG : Build fingerprint: ‘motorola/griffin/griffin:8.0.0/OPL27.76-71-2-3/3:user/release-keys’ 09-23 19:16:32.672 14123 14123 ..

Read more

vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int>>subset; vector<int>v; dfs(subset,0,nums,v); return subset; } void dfs(vector<vector<int>> subset, int index, vector<int>&nums, vector<int>&v){ subset.push_back(v); for(int i=index;i<nums.size();i++) { v.push_back(nums[i]); dfs(subset,i+1,nums,v); v.pop_back(); } } Why is the above code for printing the powerset of a set of integers, giving wrong answer? Actually, it is only printing empty set. What mistake am I making? ..

Read more