« Back to blog

My First TopCoder Problem

Well, i was looking into some old and favorite codes and algorithms i developed while in college. That is when nostalgia hit me a little when i got reminded of my first Top Coder problem. It was a witty problem, which hardly required any coding skills, but expected you to be a real thinker. So here it is - used in the Single Round Match 449 Round 1 - Division II, Level One, The Mountain Road Problem:
Media_httpwwwtopcoder_aekkh
Problem Summary: This picture represents a probable path your friend took while he was vacationing in the mountains. Now the mountains are represented as right angled isosceles triangles, with their hypotenuse lying on the ground. The entire trail or the path taken by your friend is guaranteed to be continuously along the slopes of the mountains. Thus, e.g. in the given picture, your friend took the path shown in bold lines. Given the start and end points of all the mountains (the mountain co-ordinates, assuming the base as the x-axis starting from 0), what is the total distance traveled by your friend. For instance, the mountain co-ordinates in the given figure is: {{0,5} , {3,9} , {4,6}} I will leave the answers for you to figure it. Trust me it is simpler than rocket science. Hint: Try using high school math, you should get it.