Maximum number of distinct substrings

Pyth, 12 bytes

l.Ml{.:Z)^UE

Try it online.

Pure brute force.

Explanation

  • Implicit: append Q to the program.
  • Implicit: read and evaluate a line of input (n) in Q.
  • E: read and evaluate a line of input (k).
  • U: get a range [0, ..., k-1].
  • ^: get all n-length strings of [0, ..., k-1].
  • .M: find the ones that give a maximum for function f(Z):
    • .:Z: find the substrings of Z
    • {: remove duplicates
    • l: get the number of unique substrings
  • l: get the number of such strings

Jelly, 9 bytes

ṗµẆQLµ€ML

Try it online!

Input in reversed order. Brute force.


Mathematica, 96 bytes

Last[Last/@Tally[Length@Union@Flatten[Table[Partition[#,i,1],{i,s}],1]&/@Tuples[Range@#2,s=#]]]&