Laboratory Test Questions

PROBLEM - 1

PROBLEM DESCRIPTION:
Our friend of CSE G2 has an exam that has quite weird rules. Each question has a difficulty level in the form of an Integer. Now, Monk can only solve the problems that have difficulty level less than X. Now the rules are
  • Score of the student is equal to the maximum number of answers he/she has attempted without skipping a question.
  • Student is allowed to skip just "one" question that will not be counted in the continuity of the questions.
Note- Assume the student knows the solution to the problem he/she attempts and always starts the paper from first question.
Given the number of Questions, N, the maximum difficulty level of the problem Monk can solve, X, and the difficulty level of each question, Ai can you help him determine his maximum score?
Input Format
First Line contains Integer
N, the number of questions and the maximum difficulty X Monk can solve.
Next line contains
N integers, Aidenoting the difficulty level of each question.
Output Format
Maximum score Monk can achieve in the exam.


Sample Input:
7 6
4 3 7 6 7 2 2
 
Sample Output
3



Explanation
In this example, maximum difficulty = 6, Monk solves question 0 and 1, but skips the question 2 as A [2]>6. Monk then solves the question 3, but stops at 4 because A [4]>6 and question 2 was already skipped. As 3 questions (0, 1 and 3) were solved and 2 questions (2 and 4) have been skipped, therefore we print "3".

PROBLEM - 2

PROBLEM DESCRIPTION:
Akash loves to preform different operations on arrays, and so being the principal of School, he assigned a task to his new student Adhil. Adhil will be provided with an integer array A of size N and an integer K , where she needs to rotate the array in the right direction by K steps and then print the resultant array. As she is new to the school, please help her to complete the task.

Input:
The first line will consists of one integer
T denoting the number of test cases.
For each test case:
1) The first line consists of two integers
N and K, N being the number of elements in the array and K denotes the number of steps of rotation.
2) The next line consists of
N space separated integers, denoting the elements of the array A.
Output:
Print the required array.
Sample Input:
1
5 2
1 2 3 4 5
 
Sample Output
4 5 1 2 3

Explanation
Here Tis 1, which means one test case. 
N=5 denoting the number of elements in the array and K=2, denoting the number of steps of rotations.
The initial array is:
1, 2,3,4,5
In first rotation,
5 will come in the first position and all other elements will move to one position ahead from their current position. Now, the resultant array will be 5, 1,2,3,4
In second rotation, 4 will come in the first position and all other elements will move to one position ahead from their current position. Now, the resultant array will be 4, 5,1,2,3

PROBLEM - 3

PROBLEM DESCRIPTION:
Sort first half in ascending and second half in descending order
Given an array of integers, sort the first half of the array in ascending order and second half in descending order.

Input :arr[] = {5, 2, 4, 7, 9, 3, 1, 6, 8}
Output :arr[] = {1, 2, 3, 4, 9, 8, 7, 6, 5}
 
Input :arr[] = {1, 2, 3, 4, 5, 6}
Output :arr[] = {1, 2, 3, 6, 5, 4}.


PROBLEM - 4


PROBLEM DESCRIPTION:
Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest, ..
Given an array of integers, task is to print the array in the order – smallest number, Largest number, 2nd smallest number, 2nd largest number, 3rd smallest number, 3rd largest number and so on….. Examples:
Input :arr[] = [5, 8, 1, 4, 2, 9, 3, 7, 6]
Output :arr[] = {1, 9, 2, 8, 3, 7, 4, 6, 5}
 
Input :arr[] = [1, 2, 3, 4]
Output :arr[] = {1, 4, 2, 3}

PROBLEM - 5

PROBLEM DESCRIPTION:
You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.
Sample Input
1 -> 1 -> 3 -> 3 -> 5 -> 6 -> NULL
NULL
Sample Output
1 -> 3 -> 5 -> 6 -> NULL
NULL
Explanation
1. 1 and 3 are repeated, and are deleted.
2. Empty list remains empty.

PROBLEM - 6

PROBLEM DESCRIPTION:
You’re given the pointer to the head nodes of two sorted linked lists. The data in both lists will be sorted in ascending order. Change the next pointers to obtain a single, merged linked list which also has data in ascending order. Either head pointer given may be null meaning that the corresponding list is empty. Sample Input
1 -> 3 -> 5 -> 6 -> NULL
2 -> 4 -> 7 -> NULL

15 -> NULL
12 -> NULL
 
NULL 
1 -> 2 -> NULL
Sample Output
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> NULL

12 -> 15 -> NULL
1 -> 2 -> NULL
Explanation
We merge elements in both list in sorted order and output.

Comments