Data Structure Assignment Name-Pragya Bharadwaj Admission-SEC-3 DATE-03/04/2020
Data Structure Assignment Name-Pragya Bharadwaj Admission-SEC-3 DATE-03/04/2020
Data Structure Assignment Name-Pragya Bharadwaj Admission-SEC-3 DATE-03/04/2020
Name-Pragya Bharadwaj
Admission-
SEC-3
DATE-03/04/2020
Problem 1 : Given a char array representing tasks CPU need to do. It contains capital letters A to Z where
different letters represent different tasks. Tasks could be done without original order. Each task could be
done in one interval. For each interval, CPU could finish one task or just be idle.
However, there is a non-negative cooling interval n that means between two same tasks, there must be
at least n intervals that CPU are doing different tasks or just be idle.
You need to return the least number of intervals the CPU will take to finish all the given tasks.
Example:
Constraints:
Source code:
for(char &c:tasks)
{ counter[c - 'A']++;
}
max(v, max_val);
max_val) max_cnt++;
};
OUTPUT-
Source code-
class Stack {
queue<int> q1, q2;
int curr_size;
public: Stack()
{ curr_size =
0;
}
void push(int x)
{ curr_size
++;
q2.push(x);
while (!q1.empty()) {
q2.push(q1.front()); q1.pop();
}
queue<int> q = q1;
q1 = q2; q2 = q;
}
void pop()
{
if (q1.empty())
return; q1.pop();
curr_size--;
}
int top() {
if (q1.empty())
return -1; return
q1.front();
}
int size() {
return curr_size;
}
};
int main() {
Stack s;
s.push(1);
s.push(2);
s.push(3);
OUTPUT-