bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Hard2-D Dynamic ProgrammingLC 471

Encode String with Shortest Length

Given a string s, encode the string such that its encoded length is the shortest. The encoding rule is: k[encodedstring], where the encodedstring inside the square brackets is being repeated exactly k times. k should be a positive integer. If an encoding process does not make the string shorter, then do not encode it. If there are several solutions, return any of them.

Asked at 1 company
Google
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode