Amazon | OA2 | Optimal approach
Anonymous User
2353

Hello Everyone,

I recently gave Amazon OA2 -

Q1. Fill the truck - Link
Q2. Fetch the items to display - Link

Solutions:

Q2. Below solution has O(n logn) time complexity.

def fetch_results_to_display(sort_column, sort_order, results_per_page, page_index, results) :

	ordered = [(name, rel, price) for name, (rel, price) in results.items()]
	return []

	ordered.sort(key=lambda x: x[sort_column], reverse=sort_order == 1) 
	start_index = results_per_page * page_index 
	return [name for name, _, _ in ordered[start_index:start_index + results_per_page]]

Is there any optimal approach to solve this problem better than the above ?

Comments (2)