A clan of people eat their dinners from a large pan that can hold K servings of food. When a
hungry person wants to eat, s/he helps himself from the pan with one serving, unless it is empty.
if the pan is empty, the person wakes up the cook and then waits until the cook has refilled the pan.
A hungry person thread executes the following unsynchronized code:
while (true) {
getServingFromPan();
eat();
}
Thus as shown above, a hungry person p will invoke this getServingFromPan() as long as he is
hungry and there is food in the pan. In a single invocation of getServingFromPan(), the p will get
one serving.
The single cook thread runs the following unsynchronzied code:
while (true) {
putServingsInPan(K);
}
The synchronization constraints are:
• Persons cannot invoke getServingFromPan if the pan is empty.
• The cook can invoke putServingsInPan only if the pan is empty.
Fare per Kilometer
Given total fare
fare and distance travelled in kilometers distance for a rental bike, write a JS constructor function with a method to calculate the fare per kilometer.
Quick Tip
The formula to calculate the fare per kilometer is,
fare per kilometer = fare / distance
The first line of input contains a number
The output should be a single line containing the fare per kilometer
Update Pickup Point
Given a previous pickup point in the prefilled code, and updated pickup point
Write a C++ program in which, read a c-string from user. Now your task is to find either the entered string is a palindrome or sub-palindrome
Consider a system consisting of n processes/threads and k identical resources where k<n. Each
thread of which has a unique priority number. Each thread request for a single resource at a time. If
the resource is available then it is immediately allocated. If the resource is not available then the
thread is made to wait. Thus in the course of time, multiple threads may wait to access the resource.
Once the resource is available, the resource is given to the waiting thread with the highest priority.
Develop a monitor that achieves this. Specifically, the monitor should the following methods:
void request-resource(int thr_priority); // Here thr_priority is the priority of the invoking thread
void release-resource();
Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.
Sample Input 1
4 4
1 2 3 4
5 6 7 8
7 8 9 10
11 12 13 14
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Update Pickup Point
Given a previous pickup point in the prefilled code, and updated pickup point
Remove Words Given a string, write a program to remove all the words with K length. Input The first line of the input will contain a string A. The second line of the input will contain an integer K. Output The output should contain a string after removing all the words whose length is equal to K. Explanation For example, string A is "Tea is good for you", k is 3 then output should be "is good." Here words "Tea", "for", "you" length is equal to 3, so these words are removed from string.
Explain why PCI performs better than EISA and VL-Bus