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.

Python code and mcq explanation needed. Please don't copy from anywhere

1. 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

2. What will be the output of the following Python code?

def f1(a,b=[]):

b.append(a)

return b

print(f1(2,[3,4]))

a) [3,2,4]

b) [2,3,4]

c) Error

d) [3,4,2]

3. Which of the following Python code creates an empty class?

a)

class A:

return

b)

class A:

pass

c)

class A:

d) It is not possible to create an empty class

4. What will be the output of the following Python code?

x = ['ab', 'cd']

print(map(len, x))

a) ['ab', 'cd']

b) [2, 2]

c) ['2', '2']

d) none of the mentioned

5. What will be the output of the following Python code?

x=10

y=8

assert x>y, 'X too small'

a) Assertion Error

b) 10 8

c) No output

d) 108

6. What will be the output of the following Python code?

import turtle

t=turtle.Pen()

t.goto(300,9)

t.position()

a) 300.00, 9.00

b) 9, 300

c) 300, 9

d) 9.00, 300.00

7. Which function overloads the + operator?

a) add()

b) plus()

c) sum()

d) none of the mentioned

8. What will be the output of the following Python functions?

float('1e-003')

float('2e+003')

a)

3.00

300

b)

0.001

2000.0

c)

0.001

200

d)

Error

2003

9. What will be the output of the following Python code?

class Test:

def init(self):

self.x = 0

class Derived_Test(Test):

def init(self):

Test.init(self)

self.y = 1

def main():

b = Derived_Test()

print(b.x,b.y)

main()

a) Error because class B inherits A but variable x isn't inherited

b) 0 0

c) 0 1

d) Error, the syntax of the invoking method is wrong

10. What will be the output of the following Python code?

sentence = 'we are humans'

matched = re.match(r'(.*) (.*?) (.*)', sentence)

print(matched.group(2))

a) 'are'

b) 'we'

c) 'humans'

d) 'we are humans'

11. Which module in the python standard library parses options received from the command line?

a) getopt

b) os

c) getarg

d) main

12. What will be the output of the following Python code?

import time

t=(2010, 9, 20, 8, 45, 12, 6, 0, 0)

time.asctime(t)

a) 'Sep 20 2010 08:45:12 Sun'

b) 'Sun Sep 20 08:45:12 2010'

c) '20 Sep 08:45:12 Sun 2010'

d) '2010 20 Sep 08:45:12 Sun'

13. Which of the following is not a type of inheritance?

a) Double-level

b) Multi-level

c) Single-level

d) Multiple

14. What will be the output of the following Python code?

import time

t=(2010, 9, 20, 8, 15, 12, 6)

time.asctime(t)

a) '20 Sep 2010 8:15:12 Sun'

b) '2010 20 Sept 08:15:12 Sun'

c) 'Sun Sept 20 8:15:12 2010'

d) Error

15. What is delattr(obj,name) used for?

a) To print deleted attribute

b) To delete an attribute

c) To check if an attribute is deleted or not

d) To set an attribute

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!