CJCoding With Joseph
15free / daySign inCreate account

First Value At Least X

Write 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 — print one after the last line.

Hints4 available
Topics:
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.