Floor and Ceil in Sorted Array
📖 Scenario: You are working with a sorted list of house numbers on a street. You want to find the closest house number that is less than or equal to a given number (floor) and the closest house number that is greater than or equal to that number (ceil).
🎯 Goal: Build a program that finds the floor and ceil values for a given number in a sorted array of house numbers.
📋 What You'll Learn
Create a sorted array of integers called
houses with exact valuesCreate an integer variable called
target for the number to find floor and ceilWrite a function
findFloorAndCeil that takes houses and target and returns two integers: floor and ceilPrint the floor and ceil values in the format:
Floor: X, Ceil: Y💡 Why This Matters
🌍 Real World
Finding floor and ceil values is useful in real estate, pricing, and scheduling where you need closest matches in sorted data.
💼 Career
Understanding floor and ceil concepts helps in algorithm design, data querying, and optimization tasks common in software development.
Progress0 / 4 steps