FastPrepProfessors Teaching Outside Their Department
Problems/Professors Teaching Outside Their Department

Professors Teaching Outside Their Department

Patreon logoPatreon● EasyINTERNOA

Updated Apr 2023

QuestionConstraints

Problem statement

Source note: Reported in a Patreon software engineer intern HackerRank online assessment as a short SQL question about professors, departments and courses. The report gives no tables or query goal.

The three tables, their columns and the goal of finding courses taught outside a professor's own department are our practice assumptions.

Our version is about 30% the same as the reported question.

A university stores its departments, its professors (each belongs to one department) and its courses (each belongs to one department and is taught by one professor).

Find every course that a professor teaches outside their own department. For each such course, return the professor's name as professor_name, the course name as course_name, and the name of the course's department as course_department.

Return the rows in any order.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

departments

ColumnTypeNullableDescription
department_idPKIntegerNo—
nameTextNo—

professors

ColumnTypeNullableDescription
professor_idPKIntegerNo—
nameTextNo—
department_idIntegerNo—

Foreign key: department_id → departments(department_id)

courses

ColumnTypeNullableDescription
course_idPKIntegerNo—
nameTextNo—
department_idIntegerNo—
professor_idIntegerNo—

Foreign key: department_id → departments(department_id)

Foreign key: professor_id → professors(professor_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
professor_nameTextNo—
course_nameTextNo—
course_departmentTextNo—

Row order: any order is accepted. Numeric tolerance: 0.

Constraints

  • For this exercise, assume 1 to 100 departments, 1 to 1000 professors and 0 to 10000 courses.
  • All IDs are positive integers, unique within their table.
  • Every professor and course references an existing department, and every course references an existing professor.
  • Names are nonempty strings of at most 100 characters and need not be unique.

More Patreon interview questions

  • Sum of Subarray RegionsOA · Seen Oct 2024
  • Three SumOA · Seen Sep 2024
  • Binary Cardinality SortingOA · Seen Apr 2023
  • Maximum Books From BundlesOA · Seen Apr 2023
  • Sliding-Window API Rate LimiterPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Build Taxi Driver Performance FeaturesBoston Consulting Group · OABoston Consulting Group interview questions
  • Students Scoring Above AverageCapstone Investment Advisors · OA
  • Bond Interest Summary Above 3%Wells Fargo · OAWells Fargo interview questions
  • Employee Promotion OpportunitiesIntuit · OAIntuit interview questions
  • Students and Their SubjectsBirla Pivot · OA
  • Companies with Average Salary Above 40000AT&T · OAAT&T interview questions
  • Weekend Appointments for Consular Services ReschedulingMcKinsey & Company · OAMcKinsey & Company interview questions
  • Companies Above a Salary ThresholdVerisk · OA
  • Customer Resource Usage AnalysisIBM · OAIBM interview questions
  • Customers Who Never OrderedAccenture · OAAccenture interview questions
All Patreon interview questionsSee Patreon hiring insights