Saplings and pots
You have N saplings and M pots with the given widths. A sapling of width r fits a pot of width p when r ≤ p ≤ 2r. Each pot holds at most one sapling. Find the largest number of saplings you can pot.
Reported in: Infosys (SP / DSE · 22 Nov 2026) (memory-based)
Input
First line: N M. Second line: N sapling widths. Third line: M pot widths.
Output
The largest number of potted saplings.
Constraints
1 ≤ N, M ≤ 10^5; 1 ≤ widths ≤ 10^9.
Example 1
Input:
3 3
2 3 5
4 6 11
Output:
2Example 2
Input:
2 3
1 4
3 2 1
Output:
1Example 3
Input:
3 2
5 5 5
5 10
Output:
2Hint: Sort both lists. Go through the saplings from narrowest. Pots narrower than the current sapling are too narrow for every later sapling too, so skip them; use the next pot if it is at most twice the width.