On Wednesday, 19 August 2020 10:41:57 UTC+1, 洪嘉鴻 wrote: > > Hello! > This <https://play.golang.org/p/vPqBAUroadV> is the code which I'm trying. > The generation of map is the candidates from the string s1. > However, the answer should be "345", which the count is not the most. >
Your program says that the string "345" occurs 4 times - which is correct. However, it also says that there are other sequences which occur more times - e.g. "34" occurs 5 times. And there are longer repeating patterns which occur fewer times, e.g. "3453" occurs 2 times. These are all correct. So you have to think: what is your reason that "345" should be selected as "the best" answer, given that there are other answers which are better in terms of number of repeats or length of sequence? You could create a score which is the length of the string times the number of repeats - e.g. "345" length 3 x 4 occurrences = score 12: https://play.golang.org/p/7npKJ5B5VZR But then there are non-repeating sequences which score higher. Do you want to exclude sequences with a repeat count of 1 ? https://play.golang.org/p/_Dg6s4nMOgw -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5f22cd5e-d333-4232-a55b-66616b51926bo%40googlegroups.com.
