Problem · Math

Tracks in Hackathon

Learn this problem
MediumJPMorgan ChaseINTERNOA

Problem statement

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

countTeams(teamSize_1: int, teamSize_2: int, p: int) → int

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

Examples

Example 1

teamSize_1 = 3teamSize_2 = 4p = 7return = 2

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

More JPMorgan Chase problems

drafts saved locally
public int countTeams(int teamSize_1, int teamSize_2, int p) {
  // write your code here
}
teamSize_13
teamSize_24
p7
expected2
checking account