Sum of two maps

Report a typo

You are given two Pairs (Pair<Int,Int>) as input. Write a function named sum() that receives two integer Pairs and returns a new Pair with the sum of the two pairs. The sum is obtained as the sum of the respective components.

Sample Input 1:

1 2
3 4

Sample Output 1:

(4, 6)

Sample Input 2:

-1 1
1 -1

Sample Output 2:

(0, 0)
Write a program in Kotlin
fun sum(p1: Pair<Int, Int>, p2: Pair<Int, Int>): Pair<Int, Int> {
// write your code here
}

/* Do not change code below */
fun main() {
val (a, b) = readLine()!!.split(' ').map { it.toInt() }
val (c, d) = readLine()!!.split(' ').map { it.toInt() }
val pairOne = Pair(a, b)
val pairTwo = Pair(c, d)
println(sum(pairOne, pairTwo))
}
___

Create a free account to access the full topic