Implement the validateBookingCapacity method that checks whether a booking request fits within the available capacity.

The input contains three integers: booked, requested, and capacity. These values represent the number of already booked seats, the number of new seats requested, and the total available capacity.

Your task is to check whether the new booking can be accepted without crossing the total capacity.

For example, if booked = 8, requested = 2, and capacity = 10, the booking is valid because the final total is exactly 10.

Example 1

Input
booked (int) = 8
requested (int) = 2
capacity (int) = 10
Returns (boolean) true

Example 2

Input
booked (int) = 8
requested (int) = 3
capacity (int) = 10
Returns (boolean) false

Example 3

Input
booked (int) = 0
requested (int) = 5
capacity (int) = 5
Returns (boolean) true

Add the already booked count and the requested count.

If this total is less than or equal to the capacity, the booking can be accepted. If the total is greater than the capacity, accepting the booking would overfill the available limit.

This problem only needs a direct condition check because there is no need to loop through any collection.

Pseudocode:

function validateBookingCapacity(booked, requested, capacity):
    total = booked + requested
    if total <= capacity:
        return true
    return false
Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.