0% found this document useful (0 votes)
5 views4 pages

Itp-Lab 05

Good file

Uploaded by

anilpython7877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Itp-Lab 05

Good file

Uploaded by

anilpython7877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

INTRODUCTION TO PROGRAMMING

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.

🙃 WE ARE HERE FOR YOU 🙃


Q1:- You Given an array of distinct integers and a target value, return the index if the
target is found. If not, return the index where it would be if it were inserted in order

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.

Return the number of hills and valleys in nums.


You can take the size of the array as input first.

Input1: Array= [2,4,1,1,6,5]


Output: 3

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.

Input2 : nums = [6,6,5,5,4,1]


Output2: 0

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

You might also like