Problem Description
Given a non-negative floating point number representing the temperature in Celsius, convert it into Kelvin and Fahrenheit. Use the formulas Kelvin = Celsius + 273.15 and Fahrenheit = Celsius * 1.80 + 32.00, and return the results as an array [kelvin, fahrenheit].
Key Insights
- The conversion formulas are straightforward arithmetic operations.
- Kelvin is obtained by simply adding 273.15 to the Celsius temperature.
- Fahrenheit is calculated by multiplying the Celsius value by 1.80 and then adding 32.
- The solution runs in constant time and space since it requires only basic arithmetic operations without iterations.
Space and Time Complexity
Time Complexity: O(1)
Space Complexity: O(1)
Solution
The approach is to directly apply the arithmetic formulas to convert Celsius to Kelvin and Fahrenheit. No complex data structures or algorithms are required. We simply compute:
- Kelvin = Celsius + 273.15
- Fahrenheit = Celsius * 1.80 + 32.00 These computed values are then returned as an array. This method is efficient and trivial with constant time and space requirements.