Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋
Your team at AmzAn is building a quiz-style application to help students prepare for certification exams. Each quiz module tests one or more subjects and limits the number of review attempts each student has been asked to examine. To do this, please review each of the certification exams provide. You have within quiz modules answered[i] questions in each allows students to "pass" certain subjects with a total of q more questions overall. For each answer the following: Imagine a student has already answered needed[i] in order to pass. For each of the n subjects, and still has answered has to be at least pass if the q additional answered of the subject, the number of questions the student can pass determine the maximum number among the subjects. The questions are optimally distributed.
For example, consider that there are n = 2 subjects and needed = [4, 5] answered questions, respectively, to pass. Imagine another q = 1 questions across all subjects combined. In that case, the best outcome is to answer an additional question in the second subject, in order to pass it, as 2 more answers are required to pass the first subject. The maximum number of subjects that can be passed is 1.
Complete the function findMaximumNum in the editor below. The function must return an integer that represents the maximum number of subjects that can be passed.
findMaximumNum has the following parameter(s):
int[] answered: an array of integersint[] needed: an array of integersint q: an integer
꧁༺࿅ིཽ• Credit to whale and spike! 🐳 •࿅ིཽ༻꧂
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ n ≤ 10^5
- 0 ≤ answered[i], needed[i], q ≤ 10^9