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.
Nullability
Do we have both?
Report a typo
Sample Input 1:
1 4 3 8
3 5 1 8Sample Output 1:
Some(Sum is 9)Write a program in Scala 3
def sumHeadLast(left: Vector[Int], right: Vector[Int]): ??? =
for
leftHead <- ???
rightHead <- ???
yield ???
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.