Idiomatic Scala solution


#1
class Solution {
      def longestCommonPrefix(A: Array[String]): String = {
        val lastIndex = (0 until A.map(_.length).min).lastIndexWhere(index => A.forall(_.charAt(index) == A(0).charAt(index)))
        if (lastIndex < 0) "" else A(0).substring(0, lastIndex + 1)
      }
    }