All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1801_1900.s1854_maximum_population_year.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.32
Show newest version
package g1801_1900.s1854_maximum_population_year

// #Easy #Array #Counting #2023_06_22_Time_148_ms_(90.00%)_Space_34.5_MB_(90.00%)

class Solution {
    fun maximumPopulation(logs: Array): Int {
        val arr = IntArray(101)
        for (log in logs) {
            arr[log[0] - 1950]++
            arr[log[1] - 1950]--
        }
        for (i in 1..100) {
            arr[i] += arr[i - 1]
        }
        var maxyear = 1950
        var max = 0
        for (i in 0..100) {
            if (arr[i] > max) {
                max = arr[i]
                maxyear = i + 1950
            }
        }
        return maxyear
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy