The Winner University - Problem

You have two tables representing exam scores from two universities:

NewYork table: Contains student scores from New York University
California table: Contains student scores from California University

There is a competition between the two universities. The winner is determined by which university has more excellent students (students who scored 90 or above).

Return:

  • 'New York University' if New York has more excellent students
  • 'California University' if California has more excellent students
  • 'No Winner' if both universities have the same number of excellent students

Table Schema

NewYork
Column Name Type Description
student_id PK int Primary key, unique student identifier
score int Student's exam score
Primary Key: student_id
California
Column Name Type Description
student_id PK int Primary key, unique student identifier
score int Student's exam score
Primary Key: student_id

Input & Output

Example 1 — California Wins
Input Tables:
NewYork
student_id score
1 90
2 80
California
student_id score
1 95
2 92
Output:
winner
California University
💡 Note:

New York has 1 excellent student (score >= 90): student 1 with score 90. California has 2 excellent students: student 1 with score 95 and student 2 with score 92. Since California has more excellent students (2 > 1), California University wins.

Example 2 — Draw
Input Tables:
NewYork
student_id score
1 89
2 91
California
student_id score
1 88
2 95
Output:
winner
No Winner
💡 Note:

New York has 1 excellent student (student 2 with score 91). California also has 1 excellent student (student 2 with score 95). Since both universities have the same number of excellent students (1 = 1), the result is a draw.

Example 3 — New York Wins
Input Tables:
NewYork
student_id score
1 93
2 97
3 88
California
student_id score
1 85
2 90
Output:
winner
New York University
💡 Note:

New York has 2 excellent students: student 1 with score 93 and student 2 with score 97. California has 1 excellent student (student 2 with score 90). Since New York has more excellent students (2 > 1), New York University wins.

Constraints

  • 1 ≤ student_id ≤ 10^5
  • 0 ≤ score ≤ 100
  • Both tables contain at least 1 student
  • Excellent student threshold is score ≥ 90

Visualization

Tap to expand
The Winner University INPUT NewYork Table student_id score 1 92 2 85 3 95 4 78 California Table student_id score 1 88 2 91 3 76 Excellent: score >= 90 ALGORITHM STEPS 1 Count NY Excellent Filter scores >= 90 92, 95 = 2 2 Count CA Excellent Filter scores >= 90 91 = 1 3 Compare Counts NY(2) vs CA(1) NewYork 2 > California 1 4 Determine Winner Higher count wins Tie = "No Winner" FINAL RESULT Winner: NewYork Summary NewYork excellent: 2 California excellent: 1 NewYork wins! (2 > 1) Key Insight: Use SQL COUNT with WHERE clause to filter excellent students (score >= 90) from each university table. Compare the counts using CASE statement: return winning university name, or "No Winner" if counts are equal. TutorialsPoint - The Winner University | Optimal Solution
Asked in
Amazon 12 Microsoft 8 Facebook 6
28.5K Views
Medium Frequency
~12 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen