You are given a non-negative floating point number celsius, that denotes the temperature in Celsius. Your task is to convert the temperature from Celsius to both Kelvin and Fahrenheit, and return in a list [kelvin, fahrenheit].
The conversions are defined as follows:
celsius?
celsius is a non-negative floating point number.celsius = 0 and very large values of celsius.To implement the solution:
celsius.celsius to kelvin using the formula kelvin = celsius + 273.15.celsius to fahrenheit using the formula fahrenheit = celsius * 1.80 + 32.00.[kelvin, fahrenheit].By following these steps, we can ensure accurate conversion from Celsius to both Kelvin and Fahrenheit.
def convertTemperature(celsius: float) -> list:
kelvin = celsius + 273.15
fahrenheit = celsius * 1.80 + 32.00
return [kelvin, fahrenheit]
# Example usage:
print(convertTemperature(0)) # Expected output: [273.15, 32.00]
print(convertTemperature(100)) # Expected output: [373.15, 212.00]
print(convertTemperature(37.5)) # Expected output: [310.65, 99.50]
The time complexity for this problem is O(1) because the operations we are performing (addition and multiplication) are constant time operations. We are performing a fixed number of operations regardless of the size of the input. Thus, the solution is effectively constant time.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?