Java: Maximum distinct elements after removing k elements

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:30:00

Lab Details

Problem Statement:

Given an array arr[] containing n elements. The problem is to find the maximum number of

distinct elements (non-repeating) after removing k elements from the array.

Note: 1 <= k <= n.

Example

Input:

arr[] = {5, 7, 5, 5, 1, 2, 2}, k = 3

Output:

4
Remove 2 occurrences of element 5 and
1 occurrence of element 2.
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this