# Convert the Temperature
**Difficulty:** EASY
[External](https://leetcode.com/problems/convert-the-temperature)
Canonical: https://scaleengineer.com/dsa/problems/convert-the-temperature
**Patterns:** [Math](https://scaleengineer.com/dsa/patterns/math)
---
## Problem
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`

**Example 1:**

**Input:** celsius = 36.50
**Output:** [309.65000,97.70000]
**Explanation:** Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.

**Example 2:**

**Input:** celsius = 122.11
**Output:** [395.26000,251.79800]
**Explanation:** Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.

**Constraints:**

* `0 <= celsius <= 1000`

# Approaches
## Direct Calculation using Formulas
This problem is a straightforward application of mathematical formulas. The most efficient and logical approach is to directly implement the given conversion formulas to calculate the Kelvin and Fahrenheit temperatures from the input Celsius value.
**Time:** O(1) - The time complexity is constant because the solution involves a fixed number of arithmetic operations (one addition, one multiplication, and one addition). These operations take the same amount of time regardless of the value of `celsius`. · **Space:** O(1) - The space required is constant. We only need to allocate space for the output array of a fixed size (2), which does not depend on the input value.
**Pros:** Extremely simple and easy to understand and implement.; Most efficient solution possible with constant time and space complexity.; Directly addresses the problem requirements without any overhead.
**Cons:** There are no significant disadvantages to this approach as it is the most direct and optimal solution for this problem.
### Explanation
The solution involves performing two simple arithmetic operations based on the formulas provided in the problem description. 

First, we calculate the Kelvin temperature by adding `273.15` to the input `celsius`. 

Second, we calculate the Fahrenheit temperature by multiplying the `celsius` value by `1.80` and then adding `32.00`. 

Finally, these two resulting values are placed into a new array of doubles of size two, which is then returned. This approach is optimal as it involves a constant number of operations.

```java
class Solution {
    public double[] convertTemperature(double celsius) {
        // Calculate Kelvin using the provided formula
        double kelvin = celsius + 273.15;
        
        // Calculate Fahrenheit using the provided formula
        double fahrenheit = celsius * 1.80 + 32.00;
        
        // Return the results in a new double array
        return new double[]{kelvin, fahrenheit};
    }
}
```
### Algorithm
1.  Define a function that takes a single floating-point argument, `celsius`.
2.  Calculate the temperature in Kelvin using the formula: `Kelvin = celsius + 273.15`.
3.  Calculate the temperature in Fahrenheit using the formula: `Fahrenheit = celsius * 1.80 + 32.00`.
4.  Create a new array of doubles with a size of 2.
5.  Store the calculated Kelvin value at the first index (index 0) of the array.
6.  Store the calculated Fahrenheit value at the second index (index 1) of the array.
7.  Return the newly created array.

# Solutions
### Java

```java
class Solution {
public
  double[] convertTemperature(double celsius) {
    return new double[]{celsius + 273.15, celsius * 1.8 + 32};
  }
}

```

### CPP

```cpp
class Solution {
public:
  vector<double> convertTemperature(double celsius) {
    return {celsius + 273.15, celsius * 1.8 + 32};
  }
};

```

### Python

```python
class Solution:
    def convertTemperature(
        self, celsius: float) -> List[float]: return [celsius + 273.15, celsius * 1.8 + 32]

```
