This a very simple program in python. Below is the code:
This program time complexity is O(n) as dictionary search is not considered as another loop in Python.
In last post I gave solution in C language. Time complexity is O(nlog(n)). But if we check the timings and memory is taken for Python and C code, it is huge in Python. I used leetcode for writing and execution of these solutions.
Below is the display from leetcode.
There is huge difference between Python and C solution optimization. Still Python is preferable across industry, may be because of many advantages.