Question bank › Dynamic Programming
Dsa Dynamic Programming Warm-up

Optimal Seating Arrangement

Imagine you are arranging seats in a classroom for students. Each student has their own preference rating for how much they enjoy sitting next to others. The aim is to maximize the total enjoyment rating of all students for a given seating arrangement. You are given an integer 'n' representing the number of students and a list of lists of integers where the inner lists contain each student’s enjoyment ratings when seated next to each other. Write a function to calculate the maximum enjoyment rating possible by seating students optimally. Input Format: - The first line contains an integer n (1 <= n <= 10). - The next n lines each contain n integers representing the enjoyment ratings for each pair of students. Output Format: - An integer representing the maximum enjoyment rating. Example: Input: 3 0 5 2 5 0 3 2 3 0 Output: 10 Note: The enjoyment rating for the seating arrangement [0, 1, 2] is calculated as 5 (between 0 and 1) + 3 (between 1 and 2) + 2 (between 2 and 0).

Key concepts

dynamic_programmingbacktrackinggreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.