BackmediumTrees Accenture

Maximize Element Fit Count Solution

Problem Statement

Given two integer arrays, elements and slots, determine the maximum number of elements that can be successfully placed into slots such that each element fits into its assigned slot.

Example 1
Input
[1, 2, 3, 4, 5], [1, 2, 2, 3, 4]
Output
2

Explanation: Step-by-step: Given elements [1, 2, 3, 4, 5] and slots [1, 2, 2, 3, 4], we can place elements 1 and 2 in slots 1 and 2 respectively. However, we cannot place element 3 in slot 2 as it's larger than the slot. Therefore, the maximum number of elements that can be placed is 2.

Example 2
Input
[4, 3, 2, 1, 5], [1, 2, 2, 3, 4]
Output
2

Explanation: Step-by-step: Given elements [4, 3, 2, 1, 5] and slots [1, 2, 2, 3, 4], we can place elements 1 and 2 in slots 1 and 2 respectively. However, we cannot place element 3 in slot 2 as it's larger than the slot. Therefore, the maximum number of elements that can be placed is 2.

Constraints

  • 1 <= elements.length, slots.length <= 10^5
  • 1 <= elements[i], slots[i] <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free