Friends and Candies
Updated
Problem statement
Student i wants exactly demands[i] candies. There are budget candies and undirected friendship pairs in friends. A student may receive candies only if they receive their entire demand and every friend also receives their entire demand. Return the greatest number of students who can be fully served. You may leave candies unused.
Friendship is transitive for this condition: every connected group must be served in full or skipped in full. Student indices are zero-based; duplicate friendship pairs do not change the condition.
Function
maximumStudents(demands: int[], friends: int[][], budget: int) → intExamples
Example 1
demands = [2,3,2]friends = [[0,1]]budget = 4return = 1The first two students require five together, so only student 2 can be served.
Example 2
demands = [2,3,2]friends = [[0,1]]budget = 5return = 2Serve the connected first two students together.
Constraints
- For this exercise, assume at most 200 students, at most 2000 friendship pairs, 1 <= demands[i] <= 10^6, and 0 <= budget <= 100000. All friendship endpoints are valid and distinct within a pair.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Cities on Shortest Delivery RoutesMathWorks · OAMathWorks interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions