First Value At Least X
mediumQuestion 471Write a function int firstAtLeast(const set<int>& s, int x) that returns the smallest value in s that is greater than or equal to x. If every value in the set is smaller than x (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, and firstAtLeast(s, 50) returns -1.
Do NOT write a main function.
Expected output
30 -1 30
= newline. The output ends with a newline, so 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.