Solution: Find the Floor and Ceil of a Number in a Sorted List
The review discusses the solution for finding the floor and ceil value of a given number from a sorted list, from basic to extensive level.
Solution: 1
The naive approach to this problem would be:
- Traverse the list starting from 0th
index
to the lastindex
- Compare value at each index
lst[i]
with the given inputinteger
- When you hit the maximum value lesser than equal to , store it as the value
- Similarly, the minimum value greater than equal to will be stored as value, while you linearly traverse the list
- Terminate the traversal when you reach the end of the list
Time complexity
Since the loop iterates every single element at least once, the running complexity for this solution would be , where is the size of the list.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.