4 kyu

Fastest Code : Count animals

94 of 124myjinxin2015

Description:

This is the Performance version of coding 3min series. If your code runs more than 6000ms, please optimize your code or try the simple version

Task:

Give you some chars, and they can combine many animal names.

Return the maximum number of animal names that can be combined by chars.

Animal names have been preload by variable names

One char can not use twice, for example:

    chars="goatcode"
    When you got a "dog" first time, chars left "atcoe", 
    second time you can got a "cat".
    result=2
    When you got a "goat" first time, chars left "code", 
    no animals will be found at next time.
    result=1
    So we should return the maximum number, sc("goatcode")=2

Examples:

    names=["dog","cat","bat","cock","cow","pig","fox",
           "ant","bird","lion","wolf","deer","bear","frog",
           "hen","mole","duck","goat"]
    
    sc("dogcat")=2("dog" and "cat")
    
    sc("bcaatt")=2("bat" and "cat")
    
    sc("dogdog")=2("dog" and "dog")
    
    sc("dopig")=1(only contains one of "dog" or "pig")
    
    some corner case:
    
    sc("goatcode")=2  should return 2("dog","cat"), not 1("goat")
    
    sc("cockdogwdufrbir")=4 
    should return 4("cow","duck","frog","bird") not 2("cock" and "dog")
                                    

Series:

Puzzles
Games

Stats:

CreatedApr 16, 2016
PublishedApr 16, 2016
Warriors Trained645
Total Skips87
Total Code Submissions833
Total Times Completed124
JavaScript Completions94
Haskell Completions26
Python Completions7
Total Stars35
% of votes with a positive feedback rating93% of 48
Total "Very Satisfied" Votes42
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes1
Total Rank Assessments4
Average Assessed Rank
4 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • user9644768 Avatar
  • dfhwze Avatar
Ad