[Spark Core Puzzle] How to calculate average of list numbers in Spark?(Solution should be scalable!)

apache-spark
rdd-api
#1

Given a list of numbers (could be huge file with integers) , Please provide the solution to calculate the average of those numbers.

P.S: This question is categorized under puzzles so think twice before posting your answer :slight_smile:

0 Likes

#2

val data = sc.parallelize(List.range(0,100))
val sum = data.reduce(+)
val avg = sum.toFloat/data.count()

2 Likes