-
Notifications
You must be signed in to change notification settings - Fork 1
/
Simple Fun #1 Seats in Theater.js
62 lines (27 loc) · 2.01 KB
/
Simple Fun #1 Seats in Theater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Task
// Your friend advised you to see a new performance in the most popular theater in the city. He knows a lot about art and his advice is usually good, but not this time: the performance turned out to be awfully dull. It's so bad you want to sneak out, which is quite simple, especially since the exit is located right behind your row to the left. All you need to do is climb over your seat and make your way to the exit.
// The main problem is your shyness: you're afraid that you'll end up blocking the view (even if only for a couple of seconds) of all the people who sit behind you and in your column or the columns to your left. To gain some courage, you decide to calculate the number of such people and see if you can possibly make it to the exit without disturbing too many people.
// Given the total number of rows and columns in the theater (nRows and nCols, respectively), and the row and column you're sitting in, return the number of people who sit strictly behind you and in your column or to the left, assuming all seats are occupied.
// Example
// For nCols = 16, nRows = 11, col = 5 and row = 3, the output should be
// seatsInTheater(nCols, nRows, col, row) === 96
// Here is what the theater looks like:
// Input/Output
// [input] integer nCols
// An integer, the number of theater's columns.
// Constraints: 1 ≤ nCols ≤ 1000.
// [input] integer nRows
// An integer, the number of theater's rows.
// Constraints: 1 ≤ nRows ≤ 1000.
// [input] integer col
// An integer, the column number of your own seat (with the rightmost column having index 1).
// Constraints: 1 ≤ col ≤ nCols.
// [input] integer row
// An integer, the row number of your own seat (with the front row having index 1).
// Constraints: 1 ≤ row ≤ nRows.
// [output] an integer
// The number of people who sit strictly behind you and in your column or to the left.
///////////// Solution //////////////
function seatsInTheater(nCols, nRows, col, row) {
return (nRows - row) * (nCols - (col - 1))
}