The computational complexity of my answer in Question 1:
- Time complexity : O(n). I iterate the n elements vector two times. Because the look up time in map is O(1), the time complexity is O(n).
- Space complexity : O(n). The needed space is based on the elements number in the map, which is n.