A subarray is any contiguous block of an array's elements. Given an array of integers, find the sum
of all elements of all subarrays of that array.
Example
For example, a three element array [4, 5, 6] can be made into the following subarrays:
1 element subarrays: [4], [5], [6]
2 element subarrays: [4,5], [5,6]
3 element subarrays: [4, 5, 6]
The sum of all subarrays is 4 + 5 + 6 + (4+5)
Asked in: No companies listed
Students in a class are asked to stand in ascending order according to their heights for the annual
class photograph. Determine the number of students not currentlylstanding in their correct
positions.
Example
height = [1, 1, 3, 3, 4, 1]
The 3 students indicated in red at indices 2, 4 and 5, are not in the right positions. The correct
positions are [1, 1, 1, 3, 3, 4]. Return 3.
Functi
Asked in: No companies listed
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
Asked in: Amazon
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
Asked in: No companies listed
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
Asked in: No companies listed
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
Asked in: No companies listed
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
Asked in: No companies listed
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
Asked in: Google
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
Asked in: No companies listed