Reputation: 77
I have a class and method
class Dictionary {
public Dictionary(List<String> dic) {
// ...
}
public int getCount(String substr) {
// ...
}
}
What should occur:
in method getCount you need to use list from constructor of the class and find all strings which starts on substring substr
I use this solution on my interview
return (int) this.dic.stream().filter(s -> s.startsWith(substr)).count();
Complexity is O(n)
Are there better solutions?
Thank you!
Upvotes: 1
Views: 110