Find Cutoff Score for Each School - Problem
๐ซ School Admission Cutoff Calculator
Every year, schools face a crucial challenge: setting the perfect minimum score requirement for student applications. Set it too high, and they miss out on qualified students. Set it too low, and they get overwhelmed with applications they can't accommodate!
You're given two tables:
- Schools table: Contains each school's
school_idand maximumcapacity(number of students they can accept) - Exam table: Contains
scorevalues andstudent_count(number of students who achieved at least that score)
Each school wants to:
- ๐ Maximize the number of potential applicants
- ๐ฏ Ensure they can accept everyone who meets the requirement (even if all qualified students apply)
- ๐ Use only scores that exist in the Exam table
- โฌ๏ธ Choose the smallest score if multiple scores work
Goal: Find the optimal minimum score requirement for each school. Return -1 if no suitable score exists.
Input & Output
example_1.sql โ Basic Case
$
Input:
Schools: [[1,2],[2,3]] Exam: [[500,4],[600,3],[700,1]]
โบ
Output:
[[1,700],[2,600]]
๐ก Note:
School 1 (capacity 2): Can accept scores 700(1 student) or 600(3 students). Since 3>2, only 700 works. School 2 (capacity 3): Can accept 700(1 student) or 600(3 students). Choose 600 for maximum students.
example_2.sql โ No Valid Score
$
Input:
Schools: [[1,1]] Exam: [[500,5],[600,3],[700,2]]
โบ
Output:
[[1,-1]]
๐ก Note:
School 1 has capacity 1, but all exam scores have student counts โฅ 2. No valid cutoff score exists, so return -1.
example_3.sql โ Tie Breaking
$
Input:
Schools: [[1,3],[2,5]] Exam: [[400,3],[500,3],[600,1]]
โบ
Output:
[[1,400],[2,400]]
๐ก Note:
Both schools can accept scores 400 and 500 (both have 3 students). Since both give same max students, choose the smaller score (400).
Constraints
- 1 โค number of schools โค 103
- 1 โค school capacity โค 106
- 1 โค number of exam records โค 103
- 1 โค score โค 106
- 0 โค student_count โค 106
- Important: Higher scores always have โค student counts than lower scores
Visualization
Tap to expand
Understanding the Visualization
1
Analyze Demand
Cross-reference school capacities with student score distributions
2
Find Sweet Spot
Identify scores where student count โค school capacity
3
Maximize Efficiency
Choose the score that accepts the most students possible
4
Optimize Selection
When tied, pick the lowest score to be more inclusive
Key Takeaway
๐ฏ Key Insight: Find the highest student count that fits within capacity, then pick the lowest score that achieves it - this maximizes both accessibility and enrollment!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code