Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $people=[
- ['b'=>1930, 'd'=>1934],
- ['b'=>1965, 'd'=>1995],
- ['b'=>1956, 'd'=>1966],
- ['b'=>1856, 'd'=>1915],
- ['b'=>1760, 'd'=>1826],
- ['b'=>1, 'd'=>1909],
- ['b'=>2000, 'd'=>2007],
- ['b'=>1450, 'd'=>1687]
- ];
- echo getYearWithMaxNumberHumanAlive($people);
- function getYearWithMaxNumberHumanAlive(array $people)
- {
- $yearWithMaxLiveHuman = 0;
- $maxCount = 0;
- for($year=1900; $year<2000; $year++) {
- $count = 0;
- foreach($people as $human) {
- if($human['b'] < $year && $human['d'] >= $year) {
- $count++;
- }
- }
- if($maxCount < $count) {
- $yearWithMaxLiveHuman = $year;
- $maxCount = $count;
- }
- }
- return $yearWithMaxLiveHuman;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement