probably if you don't use binary search-trees you will end up with a worstcase of O(n) and a best case of O(1).
you could build indexes with all "a"s and so on to get an 0(1) in read time complexity -> like '{"a-1" : 0, "a-3" : 1, "a-4" : 2 }' but you increase space complexity in favor of time complexity.
if you need a more complex system where a or b maybe doesn't exist you could think of bitmasks as a prefilter to have a reduced set for the real filtering a = "01011101001" as an "bit representation of the position of all sets with "a"s
or you could just use [].filter() and keep it simple for starters :)
the next question is do you need always just 1 result ? .reduce() would be 1 answer to that.
you could use the workers to sort your hashmaps on regular basis to optimize them but than you have the classic CAPs problem :) "when to trust my query" :) you could solve this with a central list queue "deterministic state machines"