Finding a duplicate number in an array in Python and C comparison

Jyothi
Dec 16, 2021

This a very simple program in python. Below is the code:

code for finding duplicate in python

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.

run time and memory taken by Python and C solutions.

There is huge difference between Python and C solution optimization. Still Python is preferable across industry, may be because of many advantages.

--

--