Day 23 : Tasks

23 December 2020

Technical

The circular wait condition can be prevented by _______.

  1. defining a linear ordering of resource types

  2. using threads

  3. using pipes

  4. all of the mentioned

Answer: defining a linear ordering of resource types

Coding Question

Find the lexicographically smallest sub sequence of exactly k length in a given string.

Input:
2
bbxabfc
3
iftygoprthxzad
6
‚Äč
Output:
abc
fghxad

Solution:

string lexico_smallest_sub_seq(string& s, int k) {
string p="";
deque<int>q;
for(int i=0;i<s.size();i++)
{
while(!q.empty() && s[q.back()]>s[i] && q.size()+s.size()-i-1>=k)
q.pop_back();
q.push_back(i);
}
while(!q.empty() && p.size()<k)
{
p+=s[q.front()];
q.pop_front();
}
return p;
}