Convert the Temperature - 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

Input & Output

Example 1 — Basic Case
$ Input: celsius = 36.50
Output: [309.65, 97.70]
💡 Note: Kelvin = 36.50 + 273.15 = 309.65, Fahrenheit = 36.50 × 1.80 + 32.00 = 97.70
Example 2 — Zero Degrees
$ Input: celsius = 122.11
Output: [395.26, 251.798]
💡 Note: Kelvin = 122.11 + 273.15 = 395.26, Fahrenheit = 122.11 × 1.80 + 32.00 = 251.798
Example 3 — Freezing Point
$ Input: celsius = 0.00
Output: [273.15, 32.00]
💡 Note: At freezing point: Kelvin = 0 + 273.15 = 273.15, Fahrenheit = 0 × 1.80 + 32 = 32.00

Constraints

  • 0 ≤ celsius ≤ 1000

Visualization

Tap to expand
Convert the Temperature INPUT C celsius = 36.50 Temperature in Celsius (non-negative float) rounded to 2 decimals ALGORITHM STEPS 1 Read Input Get celsius value: 36.50 2 Calculate Kelvin K = C + 273.15 36.50 + 273.15 = 309.65 Kelvin Result 3 Calculate Fahrenheit F = C * 1.80 + 32.00 36.50 * 1.80 + 32 = 97.70 Fahrenheit Result 4 Return Array ans = [kelvin, fahrenheit] FINAL RESULT Output Array: ans Index 0 309.65 Kelvin Index 1 97.70 Fahrenheit [309.65, 97.70] OK - Verified! Conversion Summary 36.50 C --> 309.65 K 36.50 C --> 97.70 F Key Insight: This is a direct formula application problem with O(1) time and space complexity. The formulas Kelvin = Celsius + 273.15 and Fahrenheit = Celsius * 1.80 + 32.00 are standard temperature conversion equations. Precision is maintained with floating-point arithmetic. TutorialsPoint - Convert the Temperature | Optimal Solution
Asked in
Google 25 Microsoft 20
21.4K Views
Low Frequency
~5 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen