Description
Solutions
Tracks in Hackathon
🤘 INTERN

There is a hackathon organized by HackerRank which has 2 separate tracks, healthcare and e-commerce. For track 1, the required team size is teamSize_1, while for track 2, the required team size is teamSize_2. The total number of participants is p.

Find the minimum number of teams into which the participants can be divided such that each participant belongs to exactly one team (either of track 1 or track 2), and each team has a size equal to either teamSize_1 or teamSize_2. If no such division is possible, return -1.

Function Description

Complete the function countTeams in the editor.

The function countTeams has the following parameters:

  1. int teamSize_1: the number of participants in teams of track 1
  2. int teamSize_2: the number of participants in teams of track 2
  3. int p: the total number of participants

Returns

int: the minimum number of teams into which the participants can be divided

Example 1:

Input:  teamSize_1 = 3, teamSize_2 = 4, p = 7
Output: 2
Explanation:

Optimally there is 1 team of 3 and 1 team of 4. The minimum number of teams is 2.

Constraints:
    • 1 ≤ teamSize_1, teamSize_2 ≤ 10^5
    • 1 ≤ p ≤ 10^5
Thumbnail 0
Testcase

Result
Case 1

input:

output: