Question
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
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.
Please doanswer all the questions with proper explanation, I need code for above cp question and it should pass all large and corner test cases, I need explanation for each mcq below. Please don't copy
1. What will be the output of the following Python code?
x = [12.1, 34.0]
print(len(' '.join(list(map(str, x)))))
a) 6
b) 8
c) 9
d) error
2. To read the remaining lines of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
3. What is math.factorial(4.0)?
a) 24
b) 1
c) error
d) none of the mentioned
4. What is the value of x if x = math.ldexp(0.5, 1)?
a) 1
b) 2.0
c) 0.5
d) none of the mentioned
5. What will be the output of the following Python code?
min = (lambda x, y: x if x < y else y)
min(101*99, 102*98)
a) 9997
b) 9999
c) 9996
d) None of the mentioned
6. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
a) {1: 'A', 2: 'B', 3: 'C'}
b) Method update() doesn't exist for dictionaries
c) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
d) {4: 'D', 5: 'E'}
7. The module _______________ is a comparatively faster implementation of the pickle module.
a) cPickle
b) nPickle
c) gPickle
d) tPickle
8. What will be the output of the following Python code?
class A:
def repr(self):
return "1"
class B(A):
def repr(self):
return "2"
class C(B):
def repr(self):
return "3"
o1 = A()
o2 = B()
o3 = C()
print(obj1, obj2, obj3)
a) 1 1 1
b) 1 2 3
c) '1' '1' '1'
d) An exception is thrown
9. What will be the output of the following Python function?
import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0
10. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a) True
b) False
c) None
d) Error
11. The readlines() method returns ____________
a) str
b) a list of lines
c) a list of single characters
d) a list of integers
12. What will be the output of the following Python code?
x = ['ab', 'cd']
print(list(map(len, x)))
a) ['ab', 'cd']
b) [2, 2]
c) ['2', '2']
d) none of the mentioned
13. What will be the output of the following Python code?
import random
random.choice([10.4, 56.99, 76])
a) Error
b) Either 10.4, 56.99 or 76
c) Any number other than 10.4, 56.99 and 76
d) 56.99 only
14. What will be the output of the following Python code?
re.findall('good', 'good is good')
re.findall('good', 'bad is good')
a)
['good', 'good']
['good']
b)
('good', 'good')
(good)
c)
('good')
('good')
d)
['good']
['good']
15. Which of the following is false about "import modulename" form of import?
a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier
16. What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?
tday=datetime.date.today()
print(tday.isoweekday())
a) Wed
b) Wednesday
c) 2
d) 3
17. What will be the output of the following Python code?
def sum(*args):
'''Function returns the sum
of all values'''
r = 0
for i in args:
r += i
return r
print sum.doc
print sum(1, 2, 3)
print sum(1, 2, 3, 4, 5)
a)
6
15
b)
6
100
c)
123
12345
d) None of the mentioned
18. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
19. The value returned when we use the function isoweekday() is ______ and that for the function weekday() is ________ if the system date is 19th June, 2017 (Monday).
a) 0,0
b) 0,1
c) 1,0
d) 1,1
20. What will be the output of the following Python function?
list(enumerate([2, 3]))
a) Error
b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)]
d) [(2, 3)]
21. Which of these is a private data field?
def Demo:
def init(self):
a = 1
self.__b = 1
self.__c = 1
d= 1
a) a
b) __b
c) __c
d) d
22. Which of the following functions is not defined under the sys module?
a) sys.platform
b) sys.path
c) sys.readline
d) sys.argv
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