FastPrepSimpleRDD Word Count
Problems/SimpleRDD Word Count

SimpleRDD Word Count

DatologyAI logoDatologyAI● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names a SimpleRDD word-count pipeline over flatMap, groupByKey, union, and collect. The batch adapter preserves its ordered collection result in a portable form.

Use the semantics of a small RDD pipeline to count words across a batch of sentences. Split each sentence on one or more whitespace characters, ignore empty tokens, and treat words as case-sensitive.

Return one row [word, count] for each distinct word. Rows must follow the order in which each word first appears while scanning the sentences from left to right.

Function

simpleRddWordCount(sentences: String[]) → String[][]

Examples

Example 1

sentences = ["hello world","hello spark","world hello"]return = [["hello","3"],["world","2"],["spark","1"]]

Rows retain first-occurrence order.

Example 2

sentences = ["a  a\tb","","b c"]return = [["a","2"],["b","2"],["c","1"]]

Runs of spaces and tabs are delimiters and empty sentences add no words.

Example 3

sentences = ["Data data DATA"]return = [["Data","1"],["data","1"],["DATA","1"]]

Word equality is case-sensitive.

Constraints

  • 0 <= sentences.length <= 100000.
  • The total number of characters is at most 1000000.
  • Sentences contain printable ASCII characters and whitespace.

More DatologyAI problems

  • Multiline Text Editor with Cursor MovementPHONE SCREEN · Seen Oct 2026
  • SimpleRDD Multiset IntersectionPHONE SCREEN · Seen Sep 2026
See DatologyAI hiring insights
Saved
class Solution {
    public String[][] simpleRddWordCount(String[] sentences) {
        // Write your solution here.
    }
}
Checking account…