In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 22nd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #06 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).
Stuart Bloom, owner of The Comic Center of Pasadena, is updating his digital inventory of comic book issues.
Unfortunately, the system he's using (probably coded by Howard) has a small bug and some issue numbers got entered more than once.
Now Stuart needs your help to find out which comic issues are duplicated so he can fix his records before Sheldon notices and starts a 3-hour lecture on "inventory optimization in pop culture memorabilia".
Write a function duplicates(lst) that receives a list of integers representing comic book issue numbers and returns a list of all numbers that appear at least twice, sorted in increasing order of the number.
The following limits are guaranteed in all the test cases that will be given to your program:
| 1 ≤ |lst| ≤ 50 000 | Number of integers in the list | |
| 1 ≤ lst[i] ≤ 109 | Range of each integer |
NOTE: the limits are high and you must have an efficient solution.
If your code check all previous issues to verify if an issue it not duplicated, it will result in a Time Limit Exceeded.
| Example Function Calls | Example Output |
print(duplicates([101, 203, 101, 405, 203, 203, 502])) print(duplicates([1, 2, 3, 4, 5])) |
[101, 203] [] |
Explanation of the first example
101 appears twice and 203 appears three times. Others numbers appear only once, so the duplicated issues are [101,203].
Explanation of the second example
There are no duplicates.