Code Logo

Check Speed Limit Warning

Published at19 Apr 2026
Easy 0 views
Like0

This problem is based on a very common driving check. You have the current speed of a car and the speed limit for that road, and you need to decide which message should be shown.

If the car is within the limit, the message should be OK. If the car is going over the limit, the message should be SLOW DOWN.

For example, if the speed is 60 and the limit is 50, the answer is SLOW DOWN. But if the speed is 45 and the limit is 50, the answer is OK.

So the task is to compare two numbers and return the message that matches the situation.

Example Input & Output

Example 1
Input
speed = 50, limit = 50
Output
OK
Explanation

Matching the limit is still allowed.

Example 2
Input
speed = 45, limit = 50
Output
OK
Explanation

The speed is still within the allowed limit.

Example 3
Input
speed = 60, limit = 50
Output
SLOW DOWN
Explanation

The speed is above the limit, so a warning is needed.

Algorithm Flow

Recommendation Algorithm Flow for Check Speed Limit Warning
Recommendation Algorithm Flow for Check Speed Limit Warning

Solution Approach

A good way to solve this is to use one simple comparison.

First, read the two values: the current speed and the speed limit. After that, you only need to check whether the speed is greater than the limit.

The condition is:

speed > limit

If that condition is true, then the driver is over the limit, so you print SLOW DOWN.

If that condition is false, then the speed is still allowed, so you print OK.

This problem is really just one decision, which is why it works well as a quick practice exercise for conditionals.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.