AbhiM
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
I do not think this could be done in databases. Databases are represented as sets and each tuple is a unique entity. It is impossible to determine an order of elements in a table without any field that signifies an order such as timestamp, autoincrement number etc.
- AbhiM December 21, 2009Comment hidden because of low score. Click to expand.
0
of 0 vote
1) In O(N) traverse and modify the given list such that we have two lists (two heads), one that is prepared of all sublists having ascending order and another having sublists in descending order. Theses lists might not be in sorted (any order) order.
2) Now sorted these two lists in NlogN time.
3) Now we have two sorted lists. Merge them in O(N) time.
Complexity: N+2NlogN+N = O(NlogN)
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Thanks lucas.eustaquio. I built the following solution on top of your solution.
- AbhiM August 02, 2013