Fetch Items to Display⭐ ⭐
Implement the pagination on a list of products each with its name, relevance and price.
Input:
N, the number of products;
products: HashMap<String, PairInt>, key is the productName, value is a pair of (relevance, price);
orderBy: 0 for productName, 1 for relevance, 2 for price;
order: 0 for ascending, 1 for descending;
productsPerPage: number of products per page.
pageNum: the queried page.
Output:
Return the product names on that page.
Example1:
Input:
N = 3
products = {“product1” : (3, 2), “product2” : (13, 9), “product3” : (10, 5)}
orderBy = 2
order = 1
productsPerPage = 2
pageNum = 1
Output:
[“product3”]
Explanation:
Sort the products by the second dimension in desc: product2, product3, product1.
Get the second page (notice the pageNum is 0 based) from the result.
Return [“product3”]
More Amazon Online Assessment Questions 2021
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.