You are viewing a single comment's thread. Return to all comments →
Scala Solution using Regex
val s: String = io.StdIn.readLine().trim val chars: Seq[String] = Seq( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "w", "y", "z" ) val groupPattern: Regex = chars.map(c => s"($c{2,})").reduce(_ + "|" + _).r val compressed: String = groupPattern.findAllIn(s).toVector .sortBy(_.length * -1) .foldLeft(s){ (acc, group) => acc.replace(group, s"${group.head}${group.length}") } println(compressed)
Seems like cookies are disabled on this browser, please enable them to open this website
String Compression
You are viewing a single comment's thread. Return to all comments →
Scala Solution using Regex