Problem Description
You are given a non-negative floating point number rounded to two decimal places celsius
, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit]
. Return the array ans
. Answers within 10^-5
of the actual answer will be accepted.
Note that:
- Kelvin = Celsius + 273.15
- Fahrenheit = Celsius * 1.80 + 32.00
Key Insights
- Conversion formulas must be applied correctly for both Kelvin and Fahrenheit.
- The output must be returned as an array containing both converted values.
- Precision is important; answers must be accurate to within
10^-5
.
Space and Time Complexity
Time Complexity: O(1) - The computation involves a constant number of arithmetic operations. Space Complexity: O(1) - The output is a fixed-size array regardless of the input size.
Solution
To solve this problem, we will use simple arithmetic calculations based on the provided conversion formulas for temperature. The input will be a floating-point number representing Celsius, and we will compute the corresponding Kelvin and Fahrenheit values. Finally, we will return the results as an array.
- Calculate Kelvin using the formula:
kelvin = celsius + 273.15
- Calculate Fahrenheit using the formula:
fahrenheit = celsius * 1.80 + 32.00
- Return the results as an array.