Do we have both?

Report a typo

We need a function that will take the first element of the left vector and the last element of the right vector and return a message with the sum Sum is $sum. If at least one vector is empty, it should return None. Use the features of Option to prevent runtime errors.

Sample Input 1:

1 4 3 8
3 5 1 8

Sample Output 1:

Some(Sum is 9)
Write a program in Scala 3
def sumHeadLast(left: Vector[Int], right: Vector[Int]): ??? =
for
leftHead <- ???
rightHead <- ???
yield ???
___

Create a free account to access the full topic