Itp-Lab 05
Itp-Lab 05
LAB-5
1. Submit one code file FOR EACH QUESTION.
2. The naming convention for the code file is as follows:
AD23B10XX_pZ.c
e.g.- AD23B1001_p2.c (for a student who has the roll number 01, and has made the 2nd
program using C).
3. Any deviation from the convention will result in you losing 10% marks.
4. You must submit the file(s) on the classroom page for this lab.
5. Submissions must be made before the deadline.
6. You will be heavily penalized for any delay.
7.Copying code and sharing it with others is strictly prohibited otherwise directly 0.
8. Be careful about input and output format also , you will be penalized for it also..
—-------------------------------------------ALL_THE_BESTT–---------------------------------------------
Instead of resorting to copying from your friends or the internet, it's better to
seek guidance or hints from your TA.
Sample input 1 :-
Enter the input = nums = [7,3,5,1], target = 5
Sample output 1 :- 2
Sample input 2 :-
Enter the input = nums = [1,3,5,56,9,20,10], target = 2
Sample output 2 :- 1
Sample input 3 :-
Enter the input = nums = [10,3,15,6], target = 20
Sample output 3 :- 4
Q2:- You are given a 0-indexed integer array nums. An index i is part of a
hill in nums if the closest non-equal neighbors of i are smaller than Array[i].
Similarly, an index i is part of a valley in nums if the closest non-equal
neighbors of i are larger than Array[i]. Adjacent indices i and j are part of
the same hill or valley if Array[i] == Array[j].
Note that for an index to be part of a hill or valley, it must have a non-equal
neighbor on both the left and right of the index.
Explanation:
At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill
nor a valley.
At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1,
index 1 is a hill.
At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6,
index 2 is a valley.
At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6,
index 3 is a valley, but note that it is part of the same valley as index 2.
At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5,
index 4 is a hill.
At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill
nor a valley.
There are 3 hills and valleys so we return 3.
Explanation:
At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill
nor a valley.
At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill
nor a valley.
At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4,
index 2 is neither a hill nor a valley.
At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4,
index 3 is neither a hill nor a valley.
At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1,
index 4 is neither a hill nor a valley.
At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill
nor a valley.
There are 0 hills and valleys so we return 0.
Q3:- You have given an array, you have to print all the subset of it.
Input : abcd {here array -> character array}
Output :
a
b
c
d
ab
bc
cd
abc
bcd
abcd