Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
Anniversary

The Codefinity University is hosting a ballroom dance in celebration of its anniversary! n boys and m girls are already busy. We know that several boy and girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills.

Given an array of boys with dancing skill and array of girls with dancing skills, return the largest possible number of pairs that can be formed from boys and girls.

Example 1

Input:

boys = [1, 4, 6, 2]; girls = [5, 1, 5, 7, 9];

Output:

3
main.cpp

main.cpp

C++

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt