Find all possible substring in fastest way [duplicate]

You can’t create O(N^2) strings in better than O(N^2) time. It is a mathematical impossibility. Even if creating a string took one instruction, that is still a O(N^2) computation.

Putting complexity aside, I don’t think your code can be improved upon in any significant way.


Can we make it faster?

Probably not.

Optimizing this particular piece of code is a futile activity. Since you are writing the strings to standard output, the actual performance will be dominated by the overheads of writing the characters … and whatever the OS does with the output.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)