Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Assign Cookies

Easy
greedysortingtwo-pointers

Child i is content with a cookie of size ≥ g[i]. Each child gets at most one cookie. Given greed factors g and cookie sizes s, return the maximum number of content children.

Input

  • Line 1: space-separated greed factors g
  • Line 2: space-separated cookie sizes s (may be empty)

Output: the maximum number of content children.

Example 1
Input:
1 2 3
1 1
Output:
1
Example 2
Input:
1 2
1 2 3
Output:
2

Constraints

  • 1 ≤ g.length ≤ 3·10^4
  • 0 ≤ s.length ≤ 3·10^4
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.