← Back to STL Containers
Question 471
First Value At Least X
First Value At Least X
Write a functionint firstAtLeast(const set<int>& s, int x)that returns the smallest value insthat is greater than or equal tox. If every value in the set is smaller thanx(or the set is empty), return -1. For example, with the set {10, 20, 30, 40}:firstAtLeast(s, 25)returns 30,firstAtLeast(s, 30)returns 30, andfirstAtLeast(s, 50)returns -1. Do NOT write a main function.
Expected Output:
30 -1 30
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL ContainersSets
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.