6 kyu

String reduction

358 of 896KenKamau

Description:

In this Kata, we are going to see how a Hash (or Map or dict) can be used to keep track of characters in a string.

Consider two strings "aabcdefg" and "fbd". How many characters do we have to remove from the first string to get the second string? Although not the only way to solve this, we could create a Hash of counts for each string and see which character counts are different. That should get us close to the answer. I will leave the rest to you.

For this example, solve("aabcdefg","fbd") = 5. Also, solve("xyz","yxxz") = 0, because we cannot get second string from the first since the second string is longer.

More examples in the test cases.

Good luck!

Fundamentals

Stats:

CreatedNov 2, 2017
PublishedNov 3, 2017
Warriors Trained1669
Total Skips65
Total Code Submissions4822
Total Times Completed896
JavaScript Completions358
Python Completions497
Ruby Completions54
Haskell Completions21
Total Stars37
% of votes with a positive feedback rating91% of 230
Total "Very Satisfied" Votes196
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes6
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • KenKamau Avatar
  • ITSOES Avatar
  • smile67 Avatar
  • Voile Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad