Implement a function to calculate the maximum product of three numbers in an array.
MediumProblem Statement
Implement a function to calculate the maximum product of three numbers in an array.
Sample Input
Array: [-10, -10, 5, 2]
Sample Output
Maximum product: 500
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun maxProductOfThree(nums: List<Int>): Int {
// Add your code here to calculate the maximum product
}
fun main() {
val nums = listOf(-10, -10, 5, 2)
println("Maximum product: ${maxProductOfThree(nums)}")
}
Input
Array: [-10, -10, 5, 2]
Expected Output
Maximum product: 500