Please suggest me how to design an algorithm to find the most repeated word/string in a sentence efficiently.
Is the array sorted previously? if not then use std::sort
in <algorithm>
library(put the strcmp
function in). Once we sorted, all the same strings will stand next to each other, find the longest contiguous sub-sequence with all the strings equal to each other. Complexity: O(n log n)
1 Like