Solve two coding assessment tasks
Problem 1: Maximize Store Revenue
You are given an integer array quantity of length n, where quantity[i] represents the current inventory of product i. When a unit of product i is sold, it generates revenue equal to its current inventory value immediately before the sale. After the sale, the inventory quantity[i] decreases by 1.
There are m customers, and each customer buys exactly one unit. You can assume that 0 <= m <= sum(quantity).
Your task is to determine which product to sell to each of the m customers such that the total revenue generated is maximized.
Return the maximum possible total revenue.
Problem 2: Find Top Word Frequencies
You are given a string text. Your goal is to count the occurrences of each word within this text, treating uppercase and lowercase letters as the same.
A word is defined as a maximal sequence of English letters. Any non-letter character should be considered a separator between words.
Return at most 3 distinct words, sorted according to the following criteria:
- Primary sort: By descending frequency.
- Secondary sort (for words with the same frequency): By ascending alphabetical order.
If the text contains fewer than 3 distinct words, return all of them, sorted as specified.
AI interview prep
Core dilemma
Demonstrating proficiency in selecting and implementing optimal data structures and algorithms for distinct problem patterns, specifically involving dynamic state management for greedy optimization and robust text processing with custom sorting.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve two coding assessment tasks
Problem 1: Maximize Store Revenue
You are given an integer array quantity of length n, where quantity[i] represents the current inventory of product i. When a unit of product i is sold, it generates revenue equal to its current inventory value immediately before the sale. After the sale, the inventory quantity[i] decreases by 1.
There are m customers, and each customer buys exactly one unit. You can assume that 0 <= m <= sum(quantity).
Your task is to determine which product to sell to each of the m customers such that the total revenue generated is maximized.
Return the maximum possible total revenue.
Problem 2: Find Top Word Frequencies
You are given a string text. Your goal is to count the occurrences of each word within this text, treating uppercase and lowercase letters as the same.
A word is defined as a maximal sequence of English letters. Any non-letter character should be considered a separator between words.
Return at most 3 distinct words, sorted according to the following criteria:
- Primary sort: By descending frequency.
- Secondary sort (for words with the same frequency): By ascending alphabetical order.
If the text contains fewer than 3 distinct words, return all of them, sorted as specified.