As an aspiring developer at Amazon, you are building a prototype for a cart management
service. There is an array of integers, items, that represents the item ids present in the cart initially.
Given an array of qintegers, query, your service must perform as follows. Each integer is an item id
to be added to or removed from the cart.
- If the query integer is positive, add the integer repres...
Amazon Prime Games is designing a game. The player needs to pass n rounds sequentially in this
game. Rules of play are as follows:
- The player loses power[i] health to complete round
- The player's health must be greater than 0 at all times.
- The player can choose to use armor in any one round. The armor will prevent damage of min(armor, power[il).
Determine the minimum starting health fo...
Oldest Book per Genre
You have been provided with two tables, library_books and book_genres, containing information about books and their corresponding genres.
Write an SQL query to find the oldest book (based on publication_year) in each genre. If there are multiple books with the same publication year in a genre, return the one that appears first alphabetically by title.
Table descripti...
Winner Winner
Alice and Bob are playing a game to decide who is better. They both play alternatively. Alice starts first. The subjects and the books are read sequentially.
The rules of the game are as follows:
- Both of them have N subjects.
- Let array S denote the number of books in each subject.
- Let array P denote the points for completing a book in a particular subject.
- All books o...
Watering plants
Imagine you are a park ranger responsible for maintaining N plants along a hiking trail. The plants are arranged in a straight line and numbered from 0 to N - 1: with the ith plant located at x = i. You have a water source at x = -1, which you must use to refill your watering can.
Each plant requires a different amount of water and you must water them in order, from left to r...
Profits
John is a shopkeeper. He can buy N items from the producer, the ith of which costs cost[i]. He can sell the it item at sell[i]. Initially, he has K dollars and O items in his shop. At any moment, his store can accommodate at most 1 item, which means he has to sell the previous item before buying the
next one from the producer.
What is the maximum profit he can achieve?
Notes
- He ...
Balanced mixture
Given A number of powerful resources and B number of weak resources. You have to select a balanced mixture of these resources. A balanced mixture has C resources containing no less than 4 powerful resources and no less than one weak resource. You are given integers A, B, and C. Each powerful and weak
resource is unique in itself. Hence, two mixtures with the same number of pow...
Software developers at Amazon are developing a new library for Natural Language Processing. In one of its
modules, every string needs to be preprocessed in a particular manner to find the length of its longest self-sufficient
proper substring
A self-sufficient proper substring is one where
1. the substring is not the entire string s
2.no letter that occurs inside the substring also occurs out...