Code Logo

Check Speed Limit Warning

Published at19 Apr 2026
Logic & Conditionals Easy 6 views
Like0

Given the current speed and the posted speed limit, determine whether a warning should be issued. Return true if the speed exceeds the limit, false otherwise.

For example, at speed 75 with limit 65, return true (speeding). At speed 60 with limit 65, return false (within the limit). At speed exactly 65 with limit 65, return false (not exceeding). At speed 0 with limit 25, return false.

Speed limit checking is a simple threshold comparison used in navigation apps, fleet management systems, and driver assistance features. It teaches the greater-than comparison operator and boolean return values — the simplest form of decision logic in programming.

The solution compares the current speed to the limit using the greater-than operator (>). If speed > limit, the driver is exceeding the speed limit and a warning should be issued. If speed is less than or equal to the limit, no warning is needed.

Edge cases include speed exactly equal to the limit (no warning), speed of 0 (no warning), and negative speeds which are not expected but would technically not exceed the limit.

Learn about our pseudocode specification
Guide

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

Compare the current speed to the speed limit using the greater-than operator.

function checkSpeed(speed, limit)
  return speed > limit

Return the result of speed > limit. This expression evaluates to true when the current speed is strictly greater than the posted limit (indicating the driver is speeding) and false when the speed is at or below the limit. Using strict greater-than ensures that driving exactly at the speed limit is not considered a violation.

Time complexity is O(1), space complexity is O(1).

Best Answers

Pseudocode - Approach 1
program check_speed_limit_warning
dictionary
   speed, limit: integer
algorithm
   input(speed, limit)
   if speed > limit then
      output("SLOW DOWN")
   else
      output("OK")
   endif
endprogram