@StefanPochmann I think this algorithm won't work if there are two cycles to the same source. For ex JFK-->A , JFK ---> B, JFK--->C--->JFK, JFK--->D--->JFK.
With this algorithm we will print the itinerary like this
JFK D JFK C JFK B A
@StefanPochmann I think this algorithm won't work if there are two cycles to the same source. For ex JFK-->A , JFK ---> B, JFK--->C--->JFK, JFK--->D--->JFK.
With this algorithm we will print the itinerary like this
JFK D JFK C JFK B A
@ckcz123 this solution is wrong. Try giving input "abcdcgha". It maximum palindrome is 3 but your algorithm gives 5.
@mzchen It is not similar to find the max sum in an array. In max sum we can discard the previous sum as soon as it is zero. In multipication , we can not do it as product of two negative numbers become positive numbers
@selim heap is always constructed from bottom up in an array.
Geting elements in sorted order from heap is O(n)(logn). Building heap is O(n).
http://stackoverflow.com/questions/9755721/how-can-building-a-heap-be-on-time-complexity
Why can't we change it to heap sort and then do inorder traversal. It would have complexity of O(n)
Every rectangle would have two intervals (y1,y2) on y axis and (x1, x2) on x axis. We need to sort all the y coordinates first based on this intervals and then x coordinates based on this interval.