Question
Thanks in advance!! Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals
Thanks in advance!!
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
You may assume that the intervals were initially sorted according to their start times.
Example 1:
Given intervals [1,3],[6,9] insert and merge [2,5] would result in [1,5],[6,9].
Example 2:
Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] would result in [1,2],[3,10],[12,16].
This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
Make sure the returned intervals are also sorted.
Python code for above cp question and mcq questions explanation is must. code will be tested on large test cases
1. Which of the following functions does not accept any argument?
a) re.purge
b) re.compile
c) re.findall
d) re.match
2. Point out the error (if any) in the code shown below if the system date is 18th June, 2017?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
till_bday=bday-tday
print(till_bday)
a) 3 months, 0:00:00
b) 90 days, 0:00:00
c) 3 months 2 days, 0:00:00
d) 92 days, 0:00:00
3. Lambda is a statement.
a) True
b) False
4. The function random.randint(4) can return only one of the following values. Which?
a) 4
b) 3.4
c) error
d) 5
5. How many except statements can a try-except block have?
a) zero
b) one
c) more than one
d) more than zero
6. What will be the output of the following Python code?
class A:
def init(self):
self.multiply(15)
def multiply(self, i):
self.i = 4 * i;
class B(A):
def init(self):
super().init()
print(self.i)
def multiply(self, i):
self.i = 2 * i;
obj = B()
a) 15
b) 30
c) An exception is thrown
d) 60
7. In file handling, what does this terms means "r, a"?
a) read, append
b) append, read
c) write, append
d) none of the mentioned
8. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
a) 1
b) A
c) 4
d) Invalid syntax for get method
9. What does math.sqrt(X, Y) do?
a) calculate the Xth root of Y
b) calculate the Yth root of X
c) error
d) return a tuple with the square root of X and Y
10. What will be the output of the following Python code snippet?
test = {1:'A', 2:'B', 3:'C'}
del test[1]
test[1] = 'D'
del test[2]
print(len(test))
a) 0
b) 2
c) Error as the key-value pair of 1:'A' is already deleted
d) 1
11. What will be the output of the following Python code?
l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
if f(l[i]):
del l[i]
print(i)
a)
True True
1
2
Error
b)
False False
1
2
c)
True False
1
2
Error
d)
False True
1
2
12. What is Instantiation in terms of OOP terminology?
a) Deleting an instance of class
b) Modifying an instance of class
c) Copying an instance of class
d) Creating an instance of class
13. How do you get the current position within the file?
a) fp.seek()
b) fp.tell()
c) fp.loc
d) fp.pos
14. Which is/are the basic I/O connections in file?
a) Standard Input
b) Standard Output
c) Standard Errors
d) All of the mentioned
15. What will be the output of the following Python code?
import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)
a) Error
b) Address of m
c) 1
d) 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started