n users, and ages[i] is the age of user i. Every user x sends a friend request to every other user y that meets both conditions:
- ages[y] ≤ ages[x]: y is not older than x;
- ages[y] > ages[x] / 2 + 7: y is not too young for x (this is ordinary division, not integer division).
Nobody sends a request to themselves. A request from x to y does not imply one from y to x. How many requests are sent in total?ages=[30, 30, 15] → 2
The two 30-year-olds write to each other: 2 requests. Nobody writes to the 15-year-old, since a 30-year-old only writes to people older than 30 / 2 + 7 = 22, and he writes to nobody because everyone else is older.
ages=[40, 25, 34, 14] → 2
40 → 34 (bound 27) and 34 → 25 (bound 24). No other pair works: 25 and 14 are too young for 40, and 14 is too young for 25 (bound 19.5).
ages=[14, 14] → 0
For age 14 the bound is 14 / 2 + 7 = 14 and the recipient must be strictly older than that, so there are no requests.
ages=[30, 30, 15]
2
Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.