![]() |
VOOZH | about |
Given a Set of integers set and an integer index, the task is to find the element in the set which is present at index. If the index is beyond limits, then print "Invalid index".
Examples:
Input: sett = {11, 44, 66, 72, 88, 99}, index = 2
Output: The element at index 2 is : 66
Explanation:
The element 66 is present in the set and it is present at index 2.
Input: sett = {11, 44, 66, 72, 88, 99}, index = 6
Output: Invalid index
Approach:
next() function returns an iterator pointing to the element after being advanced by certain number of positions. It is defined inside the header file.
Below is the implementation of the above approach:
The element at index 2 is 66
Time Complexity: O(N)
Auxiliary Space: O(1)