BerSU Ball Problem

BerSU Ball Problem — ExecCode Medium DSA Practice

Solve the BerSU Ball problem on ExecCode. Free online medium DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Boys and girls want to dance. A boy and a girl can dance together only when their skills differ by at most 1. Each person dances at most once. Return the maximum number of dancing pairs. You are given: a — boys' skills b — girls' skills Return the maximum number of pairs. Sort both skill lists. Walk them with two pointers, pairing the current boy and girl when they are close enough and otherwise skipping the smaller skill.

Examples

Input {'a': [1, 4, 6, 2], 'b': [5, 1, 5, 7, 9]}; Output 3. Input {'a': [1, 2], 'b': [3, 4]}; Output 1. Input {'a': [5], 'b': [5]}; Output 1

Constraints

1 <= a.length, b.length <= 100000 1 <= a[i], b[j] <= 100

Practice BerSU Ball free on ExecCode. Browse DSA problems, topic map, and placement guides.