Page 1 of 1

I want to have a python version solution to this question, Thank you so much! And please show some explanations with tim

Posted: Fri Jul 01, 2022 5:42 am
by answerhappygod
I want to have a python versionsolution to this question, Thank you so much! And please show someexplanations with time complexity and space complexity.
* Given a jumbled collection of segments, each of which isrepresented as a Pair(startPoint, endPoint), this function sortsthe segments to make a continuous path.** A few assumptions you can make:* 1. Each particular segment goes in one direction only, i.e.: ifyou see (1, 2), you will not see (2, 1).* 2. Each starting point only have one way to the end point, i.e.:if you see (6, 5), you will not see (6, 10), (6, 3), etc.* For example, if you've passed a list containing thefollowing int arrays:
[(4, 5), (9, 4), (5, 1), (11, 9)]
* Then your implementation should sort it such:
[(11, 9), (9, 4), (4, 5), (5, 1)]
@param segments collection of segments, each representedby a Pair(startPoint, endPoint). @return The sorted segments such that they form a continuouspath. @throws Exception if there is no way to create one continuouspath from
all the segments passed into this function. Feel free to changethe Exception type as you think appropriate.