FastPrepMax Subjects Number
Problems/Max Subjects Number

Max Subjects Number

IBM logoIBM● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: 2026-07-17 — The example explanation was corrected to match the displayed sample input. The judged core task matches the visible source at about 99%.

Special thanks: ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧ Tons of thanks to the sunshine ~ spike~!

A student is taking a test on n different subjects. For each nth subject they have already answered answered[i] questions and have time to answer a total of q more questions overall. For each nth subject, the number of questions answered has to be at least needed[i] in order to pass. Determine the maximum number of subjects the student can pass if the additional answered questions are optimally distributed among the subjects.

For example, there are n = 2 subjects and needed = [4, 5] answered questions, respectively, to pass. The student has answered answered = [2, 4] questions in the two subjects so far, and can answer another q = 2 questions in all subjects combined. The best outcome is to answer an additional question in the second subject to pass it, and it is not possible to pass the first subject. The maximum number of subjects that can be passed is 1.

Complete the function maxSubjectsNumber in the editor below. The function must return an integer that represents the maximum number of subjects that can be passed.

maxSubjectsNumber has the following parameter(s):

  1. answered[answered[0],...answered[n-1]]: an array of integers
  2. needed[needed[0],...needed[n-1]]: an array of integers
  3. q: an integer

Function

maxSubjectsNumber(answered: int[], needed: int[], q: int) → int

Examples

Example 1

answered = [24, 27, 0]needed = [51, 52, 100]q = 100return = 2

Here answered = [24, 27, 0] and needed = [51, 52, 100]. The additional answers needed to pass the three subjects are [27, 25, 100].

Using 27 + 25 = 52 of the 100 additional answers allows the student to pass the first two subjects. Passing the third subject requires all 100 additional answers, so it is not possible to pass all three subjects. Therefore, the maximum number of subjects that can be passed is 2.

Example 2

answered = [24, 27, 0]needed = [51, 52, 100]q = 200return = 3

:)

Example 3

answered = [2, 4]needed = [4, 5]q = 1return = 1

There are n = 2 subjects and needed = [4, 5] answered questions, respectively, to pass. The student has answered answered = [2, 4] questions in the two subjects so far, and can answer another q = 1 questions in all subjects combined. The best outcome is to answer an additional question in the second subject to pass it, and it is not possible to pass the first subject. The maximum num of subjects that can be passed is 1 :)

Constraints

  • 1 ≤ n ≤ 10^5
  • 0 ≤ answered[i], needed[i] ≤ 10^9

More IBM interview questions

  • Missing IntervalsOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Group Students (AS Intern, it may apply to other interns) 🍑Amazon · OA
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Server ManagementRippling · OARippling interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
  • Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Compute Walking DistanceTikTok · OATikTok interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int maxSubjectsNumber(int[] answered, int[] needed, int q) {
      // write your code here
    }

}
Checking account…