Permuting Two Arrays

  • + 0 comments

    Scala

     def twoArrays(k: Int, A: Array[Int], B: Array[Int]): String = {
            val arraySize = A.length
            val sortedA = A.sorted
            val sortedB = B.sorted.reverse
           
           for(i <- (0 until arraySize).toArray)    
               if(sortedA(i)+sortedB(i) < k ) return "NO"
           
            return "YES"
        }