0

Fewest Coins Problem in PHP

Can someone hekp me please solve this problem? Given a string comprised of lowercase letters in the range ascii[a-z],where each letter represents a coin type, determine the length of the shoortest substring that contains at least one of each type of coin. Example: coins: dabbcabcd The list of all caracters in the string is [a,b,c,d] two of the substrings that contains all letters are dabbc and abcd. the shortest substring that contains all of the letters is 4 characters long.

16th Apr 2020, 4:52 PM
User_96
1 Antwort
0
I have tried this but it only gives me the length of the distinct characters in the string function fewestCoins($coins){ $count=0; $strArray = count_chars($coins,1); foreach ( $strArray as $key=>$value){ if ($value>0) { $count++; } } echo($count); $testarr=substr_count($coins,"abcd"); echo($testarr); }
18th Apr 2020, 5:54 PM
User_96