Queue Questions
Queue Questions
[email protected]
Question 1 :
Generate Binary Numbers
Given a number N. The task is to generate and print all binary numbers with decimal values from
1 to N.
Sample Input 1 : N =2
Sample Output 1 : 1 10
Sample Input 2 : 5.
Sample Output 2 : 1 10 11 100 101
Question 2 :
Connect n ropes with minimum cost
Given are N ropes of different lengths, the task is to connect these ropes into one rope with
minimum cost, such that the cost to connect two ropes is equal to the sum of their lengths.
Question 3 :
Job Sequencing Problem
We have an array of jobs where every job has a deadline and associated profit if the job is
finished before the deadline. It is also given that every job takes a single unit of time, so the
minimum possible deadline for any job is 1. Maximize the total profit if only one job can be
scheduled at a time.
Sample Input 1 :
JobID Deadline Profit
a 4 20
b 1 10
c 1 40
d 1 30
Sample Output 1 : c, a
Question 4 :
[email protected]
Reversing the first K elements of a Queue
We have an integer k and a queue of integers, we need to reverse the order of the first k
elements of the queue, leaving the other elements in the same relative order.
Sample Input 1 : Q = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] ,k=5
Sample Output 1 : Q = [50, 40, 30, 20, 10, 60, 70, 80, 90, 100]
Question 5 :
Maximum of all subarrays of size k
We have an array arr[] of size N and an integer K. Find the maximum for each and every
contiguous subarray of size K.