- Related Questions & Answers
- Minimum Cost to make two Numeric Strings Identical in C++
- Minimum Number of Steps to Make Two Strings Anagram in C++
- Minimum Swaps to Make Strings Equal in C++
- Minimum number of given operations required to make two strings equal using C++.
- Minimum Cost to Connect Sticks in C++
- Minimum Cost to Merge Stones in C++
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character in C++
- Minimum Cost For Tickets in C++
- Minimum move to end operations to make all strings equal in C++
- Minimum ASCII Delete Sum for Two Strings in C++
- Minimum Cost to Hire K Workers in C++
- C Program for Minimum Cost Path
- Find the minimum number of preprocess moves required to make two strings equal in Python
- Cost to make a string Panagram in C++
- Using Counter() in Python 3.x. to find minimum character removal to make two strings anagram

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two strings A and B, and another two cost values like CostA, and CostB. We have to find the minimum cost to make A and B identical. We can delete characters from string, the cost for deleting from string A is CostA, and cost for deleting from string B is CostB. Cost of removing all characters from a string is same. Suppose the string A = “wxyz”, B = “wyzx”, CostA is 10 and CostB is 20. So the output will be 30. If we delete x from both the strings, then A and B will be identical. So cost is 10 + 20 = 30.

This is one of the variation of Longest Common Subsequence problem. We have to find the length of LCS from A and B, then subtract LCS length from A and B, thus we can get the number of characters to be removed.

#include <iostream> using namespace std; bool isRepresentedInDDigits(int num, int d, int base) { if (d==1 && num < base) return true; if (d > 1 && num >= base) return isRepresentedInDDigits(num/base, --d, base); return false; } bool checkNumber(int num, int d) { // Check for all bases one by one for (int base=2; base<=32; base++) if (isRepresentedInDDigits(num, d, base)) return true; return false; } int main() { int num = 8; int dig = 2; if(checkNumber(num, dig)) cout << "Can be represented"; else cout << "Can not be represented"; }

Can be represented

Advertisements