You are on page 1of 3

1.

• You have to design a Cache .., expiration time is given along with the priority data needs to be
kept .. You have to design the Cache
• You should have knowledge about Caching , Data Structure to optimize the problem & Basic
fundamental.. Plain/ Simple Cache will not do
• Eviction should be based upon expiration then priority like that you have to design
• Glassdoor also has the same question but the solution is not present..
2.
• Developing a component using DSA
• LRU case
• They will be assessing based upon these parameters;
• How you handle edge case
• How you used DS & collection
• How you implement the solution
• Link for LRU Preparation: https://www.geeksforgeeks.org/lru-cache-implementation/
3.
• We need to evict an expire item
• Least possible used item
• How to implement hashmap
• How to find index in array
• How does hashing work
• How to manage collusion
• How to implement heap
• Link list
• LRU
4. LRU Case is all about these 3 cases - Questions would be based upon these 3 cases each;
• Expiration
• Priority
• Least used / recently used
• You have to design a Cache .., expiration time is given along with the priority data needs to be
kept .. You have to design the Cache
• You should have knowledge about Caching , Data Structure to optimize the problem & Basic
fundamental.. Plain/ Simple Cache will not do
• Eviction should be based upon expiration then priority like that you have to design
• And the eviction with full traversal won't work, you need to optimize finding the eviction node
further.
• I used a priority queue and pushed items based on the expiration, which will order the elements
with respect to expiration value.
• Learning more about the working of priority queue would help solving the task.
5.
• Priority expiration cache
• How to add items into the cache
• Update items into the cache
• How the cache will work if the cache is full
• Which item you will remove
• Mostly explanation with pseudo code
6.
List of books, list of Genre of books and book ratings was given, all list were of equal length.
book[], genre[], rating[] of equal length n

Now there were 2 methods which we need to implement,


1. getHighestRatingBookByGenre("Genre_name") If same rating books then lexographical order
2. updateBookRatingbyBookName("book_name", int rating)

7.
// You have been given the task to develop a system that manages ratings of different books from
various genres. You need to implement a class, BookRatings, which can perform the following tasks:

// Initialise the System : The system should be initialised with three arrays - books (representing the
book titles), genres (representing the corresponding genres of the books), and ratings (representing
the initial ratings of the books). All arrays will be of length n.

// Modify the Rating of a Book : The system should be able to modify the rating of any given book.

// Return the Highest Rated Book : The system should be able to return the highest rated book for a
given genre. If there is a tie in ratings, return the lexicographically smaller book name.

// Your solution should efficiently handle these operations.

// Method Signatures:

// BookRatings(String[] books, String[] genres, int[] ratings): Initializes the system.

// void changeRating(String book, int newRating): Changes the rating of the book.

// String highestRated(String genre): Returns the name of the highest-rated book of the given genre.

//Constraints :
// n == books.length == genres.length == ratings.length

// books[i], genres[i] consist of lowercase English letters.

// All the strings in books are distinct.

// Book will be the name of a book in the system across all calls to changeRating.

// Genre will be a genre of at least one book in the system across all calls to highestRated.

// At most 2 * 10^4 calls in total will be made to changeRating and highestRated.

// Example 1:
// BookRatings bookRatings = new BookRatings(
// ["The Hobbit", "Harry Potter", "The Lord of the Rings", "Pride and Prejudice", "To Kill a
Mockingbird", "The Great Gatsby"],

// ["fantasy", "fantasy", "fantasy", "romance", "classic", "classic"],

// [13, 12, 8, 15, 14, 7]);


// bookRatings.highestRated("fantasy"); // return "The Hobbit"
// bookRatings.highestRated("classic"); // return "To Kill a Mockingbird"
// bookRatings.changeRating("The Lord of the Rings", 16);
// bookRatings.highestRated("fantasy"); // return "The Lord of the Rings"
// bookRatings.changeRating("The Hobbit", 16);
// bookRatings.highestRated("fantasy"); // return "The Hobbit"

You might also like