Letty is hired as a Sales Executive and her role is to sell items which are given to her in a bag. The bag contains

Answered step by step Verified Expert Solution
Question
76 users unlocked this solution today!

Letty is hired as a Sales Executive and her role is to sell items which are given to her in a bag. The bag contains n items where each item has an associated ID. Letty is inherently lazy and plans to delete a few items from her bag, but if she deletes more than m items, her mischief will be easily discovered. She also knows that selling like items makes her task simpler, so she wants her bag to contain as few different IDs as possible. Determine the minimum number of different IDs the final bag can contain if she can perform at most m deletions. 

For example, she has a bag with n = 6 items, ids = [1, 1, 1, 2, 3, 2], and the maximum number of items she can delete is m = 2. Two possible actions are delete two items with ID = 2 or one with ID = 2 and one with ID = 3. Either way she will have 2 item IDs in the final bag: either ids = [1, 1, 1, 3] or ids = [1, 1, 1, 2]. 

Function Description Complete the function deleteProducts in the editor below. The function must return an integer that represents the minimum number of item IDs in her bag after at most m deletions. deleteProducts has the following parameters: ids[ids[0],...ids[n-1]]: an array of integers m: an integer 

Constraints 

1 ≤ n ≤ 100000 

1 ≤ ids[i] ≤ 1000000 

1 ≤ m ≤ 10000 Input Format For Custom Testing The first line contains an integer, n, that denotes the number of elements in ids. Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer that describes ids[i]. The next line contains an integer, m, that denotes the maximum number of items that can be deleted. Sample Case 0 Sample Input For Custom Testing 4 1 1 11 2 Sample Output 1 Explanation The bag contains 4 items of the same kind. Whichever item Letty deletes, she will have items of only ID = 1. Sample Case 1 Sample Input For Custom Testing 6 1 2 3 1 2 2 3 Sample Output 1 Explanation At most m = 3 items can be deleted from ids = [1, 2, 3, 1, 2, 2]. It is optimal to choose the items having IDs 1 or 3, leaving 3 items with ID = 2.

Step by Step Solution

3.55 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Link Copied!
Step: 1

Required function def delete Productsidsm Creating an empty dictio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

100% Satisfaction Guaranteed-or Get a Refund!

Step: 2Unlock detailed examples and clear explanations to master concepts
blur-text-image_2
Step: 3Unlock to practice, ask and learn with real-world examples
blur-text-image_3

See step-by-step solutions with expert insights and AI powered tools for academic success

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon Order free textbooks.
  • tick Icon 100% Satisfaction Guaranteed-or Get a Refund!

Students Have Also Explored These Related Programming Questions!

Claim Your Hoodie Now!

hoodie-image

Recommended Textbook for

Conceptual Physics

Conceptual Physics

Authors: Paul G. Hewitt

11th edition

321568095, 9780-032166256, 321662563, 978-0321568090

More Books
flashcard-anime

Study Smart with AI Flashcards

Access a vast library of flashcards, create your own, and experience a game-changing transformation in how you learn and retain knowledge

Explore Flashcards