SubString in List

113 Views Asked by At

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!

0

There are 0 best solutions below