InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
In operating systems, define spooling. |
|
Answer» Spooling is the temporary storage of data so that it can be used and processed by a device, software, or system. Data is supplied to and stored in MEMORY or other volatile storage until it is required by a programme or computer for execution. SPOOL is an abbreviation for "Simultaneous Peripheral Operations Online." The spool is typically stored in physical memory, buffers, or interrupts for Input/Output devices on the computer. To process the spool in ascending order, the FIFO (first in, first out) approach is employed. Spooling is the process of gathering data from a large number of Input/Output processes and STORING it in a buffer. This buffer is a memory or hard disc area that Input/Output devices can access. In a distributed context, an operating system does the following:
Printing is the most visible application of spooling. Before being added to the printing queue, the PAPERS to be printed are held in the SPOOL. Several programmes can run and use the CPU during this period without having to wait for the printer to FINISH printing on each paper individually. Many additional features, such as defining priorities, receiving notifications when the printing process is complete, and selecting different types of paper to print on based on the user's preferences, can be added to the Spooling printing process. Useful Interview Resources
|
|
| 2. |
What is Servlet Collaboration? |
|
Answer» The PROCESS of COMMUNICATING information among the servlets of a Java web application is known as servlet collaboration. This enables data to be transmitted from one servlet to another via method invocations. Java's Servlet API (Application Programming Interface), which exposes TWO interfaces, is the primary method for ACHIEVING Servlet Collaboration.
These two interfaces contain the approaches for achieving the purpose of servlet information exchange. |
|
| 3. |
What is the difference between Swapping and Paging. |
||||||||||
|
Answer» The main differences between Swapping and PAGING are given below:
|
|||||||||||
| 4. |
Write functional code for solving the problem given below: Detect whether or not a given linked list contains a cycle. |
|
Answer» C ++ function which solves the given Data STRUCTURES and Algorithm problem is given below: bool detectCycle(ListNode* root){ ListNode *slow = root, *fast = root; while (slow && fast && fast -> link) { slow = slow->link; fast = fast->link->link; if (slow == fast) { return true; } } return false;}For solving this question, we can use Floyd's Approach to Find cycle in a linked list. It is stated below:
|
|
| 5. |
Write functional code for solving the problem given below: |
|
Answer» Return the result of a sequence of enqueue and dequeue actions without utilising a queue data structure. The FOLLOWING op are presented in the form of a linked list:
The end result should be returned as a linked list. As an auxiliary data structure, use two stacks. It is not permitted to use a queue. C ++ code SNIPPET which solves the given Data Structures and Algorithm problem is given below: Node* makeAnswerList(Node *root, Node *last, int VALUE){ if (root == NULL) { root = new Node(value); last = root; } else { Node *node = new Node(value); last->link = node; last = last->link; } return last;}int dequeue(stack &stk1, stack &stk2){ if (stk1.empty() && stk2.empty()) { return -1; } // If the second stack is not empty, popping and returning from it. if (stk2.empty() == false) { int value = stk2.top(); stk2.pop(); return value; } /* Otherwise we pop each and every element from the first stack and push into the second stack. */ while (stk1.empty() == false) { stk2.push(stk1.top()); stk1.pop(); } // Lastly, we pop and return the root of the second stack. int value = stk2.top(); stk2.pop(); return value;}Node* implementingQueue(Node* op){ stack stk1, stk2; Node *root = NULL; Node *last = NULL; while (op != NULL) { if (op->val >= 0) { stk1.push(op->val); } else { last = makeAnswerList(root, last, dequeue(stk1, stk2)); if (!root) { root = last; } } op = op->link; } return root;}In this question, we use two stacks to implement the queue data structure. As soon as a non-negative integer is found, we add it into the first stack and when we get a -1 in the input list, we perform the dequeue operation using the following criteria:
This way, the FIFO (First In First Out) property of a queue is preserved and we get our required answer list. |
|
| 6. |
Write functional code for solving the problem given below |
|
Answer» "You have been GIVEN the string s (which consists of only uppercase English characters) and the integer k. You can replace any character in the string with ANOTHER uppercase English character. This operation can be performed at most k times. After executing the preceding procedures, RETURN the length of the longest substring containing the same letter." Sample input and output is shown below: Input: s = "AABABBA", k = 1 C ++ function which solves the given Data Structures and Algorithm problem is given below: int replaceCharacters(string s, int k) { int n = s.length(); int maxLength = 0, maxFreq = 0, l = 0; vector<int> freq(26); for(int r = 0; r < n; r ++){ int ascii = s[r] - 'A'; freq[ascii] ++; maxFreq = max(maxFreq, freq[ascii]); while(r - l + 1 - maxFreq > k){ freq[s[l] - 'A'] --; l ++; } maxLength = max(maxLength, r - l + 1); } return maxLength; }In this question, we use the sliding window technique along with two pointers "l" and "r" to get our answer. We keep moving the pointer "r" by one from left to right each iteration and update the frequency of all characters in the window starting from index l to r. If the difference of the subarray length l to r and maximum frequency among all the characters in the window of l to r is greater than the given VALUE k, we move l forward until the same condition does not hold (l's value is incremented hence subarray length, that is, the value of "r - l + 1" keeps decreasing). In the end, we update our answer variable with the value of the length of the subarray "r - l + 1" since we can guarantee that after performing at most k op, all characters in the subarray can be made the same. |
|