FDSA Assignment-2
FDSA Assignment-2
Q.2. There are n people standing in a row, with non-negative heights. Sam can deal with exactly k people at a
time. Starting from the first person, help Sam find the height of the tallest person amongst every k people
standing consecutively.
SAMPLE INPUT 1:
2
52
51234
73
512639
SAMPLE OUTPUT 1:
5234
5669
Q.3 Sumyash has n elements represented in the form of an array. For every element a[i] (i>=0 and i<n), you are
required to find the nearest element which appears after a[i] and is greater than it in O(n).
SAMPLE INPUT 1:
2
5
14295
7
5362591
SAMPLE OUTPUT 1:
4 9 9 -1 -1
6 6 9 5 9 -1 -1
Explanation- In 1st case, for 1 next greater element is 4 and not 9. Rest all is self-explanatory.
Q4. Sahil’s favorite data structure is queue. He has first n natural numbers in a random order in a queue. His
friend, Rohit made a bet with Sahil for a Jain pizza if he can sort the elements. In order to do it, he can use an
extra queue and stack.
Determine whether he will be able to get Jain pizza on Thursday’s night.
SAMPLE INPUT 1:
2
5
51234
7
512634
SAMPLE OUTPUT 1:
YES
NO
Explanation-
For the 1st test case:
Pop the first element of the given Queue i.e 5, then push 5 into the stack. Now, pop all the elements of the given
Queue and push them to second Queue. Now, pop element 5 in the stack and push it to the second Queue.
Submission Instructions:
You should retain the same group (of assignment1). This grouping is allowed only for allowing peer
learning. However, you need to solve yourself all the questions. There will be a demo or viva for these
assignments at a later date. You should submit your exe file, and source files putting all of those into a
tar file/ zip file, and upload it into google class before the submission deadline i.e. midnight of
15/10/2022. Your code should also run on Ubuntu systems (that are there in the lab) for evaluation
purposes. You should also keep a copy of your code. Any doubts or queries regarding the questions can
be emailed to f20200065@hyderabad.bits-pilani.ac.in or h20211030070@hyderabad.bits-pilani.ac.in.
I/C
(C R Hota)
-----------------------------