Frequency of lengthiest word in a paragraph

How to find the number of occurrence of the lengthiest word in a paragraph…

val rdd = sc.textFile(“path”) // Here We read the data
val paired = rdd.flatMap(.split("\s+")).map(x=>(x,1)) //split the line with multiple spaces and make paired rdd (word,1)
paired.reduceByKey(
+_).sortBy(x=> - x._1.length()).collect().foreach(println) //Here we get each key count and sorted based on length of key

2 Likes