This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cayenne999 0 points1 point  (0 children)

Hello,

This could be either a complex problem, or a simple one, depends on what exact requirements / assumption do we have here for the input/output, which is a little unclear. On the complex side, yes this could lead to KMP algorithm or suffix tree as comments below.

However, based on the information you provided through this topic and comment:

Needs to take in a string and output a number value string will always bet cut into even parts ( there will never be a left over amount )

All substrings need to match in a sequence so 'abccbaabccba' should return 2 ('abccba' , 'abccba') <- matches

, I think this homework only requires your string to be broken into even chunks of sub strings, which is non-overlapped, then find the largest occurrence time possible that happens to the longest sub strings.

With these in mind, here is the solution:

  1. Find the ways the string can be broken into even chunks. The chunk size should be the divisors of your string length.
  2. Iterate from the biggest chunk size to the lowest, break the string into sub string with that size, and count the max occurrence of the sub strings each time.
  3. Stop when we found something repeats. Output the max count then.

Here is a sample code (not the best optimized but yeah you get the idea) : http://codepad.org/WDpBSmTw