Doubt in output questions

1)vector< int > data = { 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6 };
auto lower = std::lower_bound(data.begin(), data.end(), 4);
auto upper = std::upper_bound(data.begin(), data.end(), 4);
for(auto it = lower; it != upper; it++)
cout << *it << ’ ';

Q5. Algorithms STL#5
Given the following code snippet :

bool comp(string s1, string s2)
{
if(s1.length() < s2.length())
return 1;
else if(s1.length() > s2.length())
return 0;
else return s1 < s2;
}

vector< string > data = {“b”, “a”, “c”, “abc”, “bca”, “xy”};
sort(data.begin(), data.end(), comp);
for(string item : data)
cout << item << " ";

Q10. Algorithms STL#10
Given the following code snippet :

string s = “bca”;

do {
cout << s << ’ ';
} while(next_permutation(s.begin(), s.end()));

cout << s;
What is the output of the given code?

hello @dipeshpandey2001

havent u studied lower and upper bound ?
answr is 4 4 4

here first we are comparing lengths of string i.e string of smaller size will come first and then larger size.

if lenght of both string is same then we are sorting them lexicographically (dictionary order),

it will be abc, read about next permutation function

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.