JAVA BEATS 100% || EASY AND SIMPLE SOLUTION WITH APPROACH
Intuition1. Tracking Changes with a Difference Array:Instead of iterating over every year for every person (which would be inefficient), the solution uses a dif
# Intuition
#### 1. Tracking Changes with a Difference Array:
Instead of iterating over every year for every person (which would be inefficient), the solution uses a **difference array** approach:
- Increment the population count for the birth year (`arr[birthYear]++`).
- Decrement the population count for the death year (`arr[deathYear]--`).
  - This marks the start and end of a person's lifespan.

This ensures that we only record the **net change in population** at specific years. Later, we can calculate the actual population for each year using a cumulative sum.

---

#### 2. Finding the Year with Maximum Population:
After populating the `arr` array:
1. Compute the cumulative population using a running total (`temp`).
2. Track the year with the highest cumulative population using a variable (`max`).
3. If the current year's population (`temp`) exceeds `max`, update `max` and store the corresponding year.

# Approach 
1. **Initialize a Population Array**:
   - Create an array `arr` of size 2051 (to cover years from 1950 to 2050).
   - Initialize all values in `arr` to `0`.

2. **Update the Array for Births and Deaths**:
   - For every `log` entry `[birthYear, deathYear]`:
     - Increment `arr[birthYear]` to denote a birth.
     - Decrement `arr[deathYear]` to denote the end of life.

3. **Calculate Cumulative Population**:
   - Iterate through the years from `1950` to `2050`.
   - Maintain a running total (`temp`) to compute the cumulative population.
   - Keep track of the maximum population (`max`) and the corresponding year (`year`).

4. **Return the Year**:
   - Return the year with the maximum population.

# Complexity
- Time complexity:
O(N) where N is the size of the given array logs.

- Space complexity:
Constant space complextity O(1).
# Code
```java []
class Solution {
    public int maximumPopulation(int[][] logs) {
       int[]  arr = new int[2051];
       for(int[] pop: logs){
        arr[pop[0]]++;
        arr[pop[1]]--;
       } int max=0,year=0,temp=0;
    
       for(int i=1950;i<2051;i++){
          temp+=arr[i];
          if(temp>max){
            max=temp;
            year=i;
          }
       }
       return year;
    }
}
```
['Array', 'Counting', 'Prefix Sum', 'Java']