-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathProblem68.js
More file actions
23 lines (23 loc) · 821 Bytes
/
Problem68.js
File metadata and controls
23 lines (23 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Problem 68
//
// This problem was asked by Google.
//
// On our special chessboard, two bishops attack each other if they share the same diagonal. This includes bishops that have another bishop located between them, i.e. bishops can attack through pieces.
//
// You are given N bishops, represented as (row, column) tuples on a M by M chessboard. Write a function to count the number of pairs of bishops that attack each other. The ordering of the pair doesn't matter: (1, 2) is considered the same as (2, 1).
//
// For example, given M = 5 and the list of bishops:
//
// (0, 0)
// (1, 2)
// (2, 2)
// (4, 0)
//
// The board would look like this:
//
// [b 0 0 0 0]
// [0 0 b 0 0]
// [0 0 b 0 0]
// [0 0 0 0 0]
// [b 0 0 0 0]
// You should return 2, since bishops 1 and 3 attack each other, as well as bishops 3 and 4.