#C14348. Word Occurrences
Word Occurrences
Word Occurrences
Given N sentences, your task is to determine for each unique word (case‐sensitive) the list of sentence indices (0-indexed) in which it appears. For every sentence, split it by whitespace into words, and if a word occurs multiple times in the same sentence, record the sentence index only once. Finally, output the result as a JSON object where each key is a word and its value is an array of sentence indices.
Note: The order of keys in the output should follow the order in which the word first appears in the input.
Formula:
\(output = \{ word: [i_1, i_2, \dots, i_k] \}\)
inputFormat
The first line contains an integer N, representing the number of sentences. Each of the next N lines contains a sentence.
outputFormat
Print a JSON object (dictionary) where each key is a word (as it appears in the sentences) and its corresponding value is an array of distinct 0-indexed sentence indices in which the word appears.
## sample1
This is a test
{"This": [0], "is": [0], "a": [0], "test": [0]}