ALT-TAB Window
While using a computer, a user uses the ALT-TAB key to switch between
applications. The ALT-TAB window works on the principle of holding the ALT
key for MRU (Most Recently Used) listing. Hence, the applications arrange
themselves in such a way that the most recently used application will be the first
item in the ALT-TAB window and so forth.
You are given the list of opened applications and the number of times that the
user presses the 'Tab key' to switch between applications. Find the final
arrangement of applications in the ALT-TAB window.
Example
in the given picture, Libraries application is focused, which means that holding
the ALT key, the user presses the Tab key twice. Internet Explorer being the
most recently used application followed by Libraries and so on.
Answers
Answer:
Program for K Most Recently Used (MRU) Apps
Given an integer K and an array arr[] of N integers which contains the ids of the opened apps in a system where
arr[0] is the app currently in use
arr[1] is the app which was most recently used and
arr[N – 1] is the app which was least recently used.
The task is to print the contents of the array when the user using the system presses Alt + Tab exactly K number of times. Note that after pressing Alt + Tab key, app opening pointer will move through apps from 0th index towards right, depending upon the number of presses, so the app on which the press ends will shift to 0th index, because that will become the most recently opened app.
Examples:
Input: arr[] = {3, 5, 2, 4, 1}, K = 3
Output: 4 3 5 2 1
User want to switch to the app with id 4, it’ll become the currently active app and the previously active app (with id 3) will be the most recently used app.
Input: arr[] = {5, 7, 2, 3, 4, 1, 6}, K = 10
Output: 3 5 7 2 4 1 6
Explanation:
4 applications are open .holding the ALT key , the user presses TAB key 3 times. this pips up application number 3 .hence, 3 is the most active application in the ALT-TAB panel