Alphabetically arr and input , which is O (nlogn), and if you can do this when creating arrays, it might be useful for you.
Let me explain my idea with an example:
var arr = [ {"a": "x"}, {"ab": "i"}, {"ab": "4"}, {"abc": "L"} {"bc": "x"}, ]; var input = ["ab", "bc"];
Find input[0] in arr (linearly or even with binary search to speed it up). Mark the index.
Find input[1] in arr , but consider only the arr subarray, by the index noted in the previous step, to the end.
If you find all input elements, then click on results (for this you can save a temporary object for it).
Now we need to search again for input[0] , as it may be that two or more entries share this key. You saved the index that I mentioned earlier, so that you start looking for this index again, and since arr sorted, you only need to check the very next element, etc.
Lead time:
Sort your arrays (if you could not sort them when creating them): O (nlogn), where n is the number of arr elements.
Arr binary search for input[0] : O (logn)
Now the next search step (for input[1] ) is much shorter than the length arr , so O (n) will be a very pessimistic estimate. In practice, it will not be O (n), of course, and if you want, you can also do a binary search for input[1] , which will cost O (logm), where m is the size of arr[index_stored: -1] .
At this point, we proceed to search for the next occurrence of input[0] , if it is finite, but since we have saved the index, we know exactly where to start the search, and we only need to check the next element that the constant cost is, therefore, O ( one).
And then we do the same for input[1] , as indicated above, which is again cheap.
Now it all depends on the length of the input , which is k , and it seems that k < n and how many occurrences of the key you have, right?
But if we assume that the situation is normal, then the whole procedure has time, supplementing:
About (NlogN)
However, note that you need to pay a little extra memory to store indexes, which depend on the number of occurrences that the key has. With brute force aglrotihm, which will be slower, you will not need to pay anything extra for memory.