• + 1 comment

    Your solution is O(n+m) runtime and O(n) space complexity, which is slower than what you mentioned in your post, but is still great. The O(n+m) is a result of the fact that m may be larger than n. The space complexity is due to you creating an array of size n.

    I do the same in my efficient Java solution.

    HackerRank solutions.