6 kyu

String reduction

506 of 908KenKamau

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 Trained1685
Total Skips65
Total Code Submissions4861
Total Times Completed908
JavaScript Completions361
Python Completions506
Ruby Completions55
Haskell Completions22
Total Stars37
% of votes with a positive feedback rating91% of 234
Total "Very Satisfied" Votes200
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