So, I have start number, end number and a list of segments.
start = 10
end = 100
li = [(50, 60), (10, 20), (10, 40), (40, 60), (60, 80), (75, 95), (95, 100), (35, 45)]
And I need to find the least number of segments to get from point A to point B. If there are not enough segments, the program should indicate this.
I think that thanks to the illustration it will become clearer what I need.
In addition, I am not allowed to use any libraries or even import's. Of course, the less memory and time is used, the better.
As for me, I've wrote terrible code:
for el in li:
for el1 in li:
if el != el1 and el[0] >= el1[0] and el[1] <= el1[1]:
li.remove(el)
elif el != el1 and (el[1] == el1[0] or el[0] == el1[1]):
tmp = (min(el[0], el1[0]), max(el[1], el[1]))
for el2 in li:
if el != el2 and el1 != el2 and el2[0] >= tmp[0] and el2[1] <= tmp[1]:
li.remove(el2)
However, in my program there are three levels of nested loops, and in the middle of the third there is also remove, so my code do not work quickly and efficiently.
