[Kotlin] Simple and Fast Implementation | Beats 100%
Intuition\nWe iterate through numbers from 1 to n, checking if each number is divisible by 3, 5, both, or neither, and add the corresponding string to the resul
# Intuition\nWe iterate through numbers from 1 to n, checking if each number is divisible by 3, 5, both, or neither, and add the corresponding string to the result list.\n\n# Approach\n1. Initialize an empty mutable list `result` to store the FizzBuzz strings.\n2. Iterate from 1 to n.\n3. Check if the current number is divisible by 3 (`divisibleBy3`) and by 5 (`divisibleBy5`).\n4. Based on the divisibility:\n   - If divisible by both 3 and 5, add "FizzBuzz" to `result`.\n   - If only divisible by 3, add "Fizz" to `result`.\n   - If only divisible by 5, add "Buzz" to `result`.\n   - If not divisible by 3 or 5, add the number itself as a string to `result`.\n5. Return the `result` list.\n\n# Complexity\n- Time complexity: O(n) where n is the input number.\n- Space complexity: O(n) for storing the result list.\n\n# Code\n```\nclass Solution {\n    fun fizzBuzz(n: Int): List<String> {\n        val result = mutableListOf<String>()\n        for (i in 1..n) {\n            val divisibleBy3 = i % 3 == 0\n            val divisibleBy5 = i % 5 == 0\n            \n            when {\n                divisibleBy3 && divisibleBy5 -> result.add("FizzBuzz")\n                divisibleBy3 -> result.add("Fizz")\n                divisibleBy5 -> result.add("Buzz")\n                else -> result.add(i.toString())\n            }\n        }\n        return result\n    }\n}\n\n```
['Kotlin']