Here are the first two solutions I wrote in Scala: import java.io.BufferedReader
import scala.io.Source /** * Created by meir on 06/04/19. */ object Solution { val not4 = "[^4]".r def processTest(in: BufferedReader): String = { val n = in.readLine() val a = not4.replaceAllIn(n,"0").replaceAllLiterally("4","1").dropWhile(_ == '0') val b = n.replaceAllLiterally("4","3") a + " " + b } def main(args: Array[String]) { val in = Source.stdin.bufferedReader() val N = in.readLine().toInt Range(1, N + 1).foreach(i => printf("Case #%d: %s\n", i, processTest(in))) } } import java.io.BufferedReader import scala.io.Source /** * Created by meir on 06/04/19. */ object Solution { def not(c: Char) = if (c == 'E') 'S' else 'E' def processTest(in: BufferedReader): String = { val n = in.readLine().toInt val p = in.readLine() if (p.head != p.last) { (Seq.fill(n-1)(p.last) ++ Seq.fill(n-1)(p.head)).mkString("") } else { val a=p.head val b=not(p.head) val c=p.indexOf(""+b+b) val cnt=p.substring(0,c).count(_ == b) (Seq.fill(cnt+1)(b) ++ Seq.fill(n-1)(a) ++ Seq.fill(n - cnt - 2)(b)).mkString("") } } def main(args: Array[String]) { val in = Source.stdin.bufferedReader() val N = in.readLine().toInt Range(1, N + 1).foreach(i => printf("Case #%d: %s\n", i, processTest(in))) } } Scala is not a slow language, I believe it's almost entirely compile and startup time issues. Problem B can be done simpler, but this is what I wrote at the time, and it should be plenty fast enough. Equivalent Java programs (Regex and all) worked without issue. By problem three I already got the hint and solved in Java first and not in Scala. -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/2e452694-ab74-4c60-afe7-f0088d2b3352%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.