6 kyu

Repeated Substring

895 of 2,062opportunity356

Description:

For a given nonempty string s find a minimum substring t and the maximum number k, such that the entire string s is equal to t repeated k times.

The input string consists of lowercase latin letters.

Your function should return :

  • a tuple (t, k) (in Python)
  • an array [t, k] (in Ruby and JavaScript)
  • in C, return k and write to the string t passed in parameter

Examples:

"ababab" ---> (t = "ab", k = 3)

"abcde" ---> (t = "abcde", k = 1)
because for this string, the minimum substring 't'
such that 's' is 'k' times 't', is 's' itself.
Algorithms

More By Author:

Check out these other kata created by opportunity356

Stats:

CreatedDec 17, 2014
PublishedDec 17, 2014
Warriors Trained4168
Total Skips262
Total Code Submissions10191
Total Times Completed2062
Python Completions895
Ruby Completions461
JavaScript Completions743
C Completions30
COBOL Completions6
Total Stars77
% of votes with a positive feedback rating93% of 311
Total "Very Satisfied" Votes272
Total "Somewhat Satisfied" Votes36
Total "Not Satisfied" Votes3
Ad
Contributors
  • opportunity356 Avatar
  • jhoffner Avatar
  • OverZealous Avatar
  • Balkoth Avatar
  • GiacomoSorbi Avatar
  • FArekkusu Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad