Question: Q: Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Example

Q:

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

Try to solve it in linear time/space.

Example :

Input : [1, 10, 5]

Output : 5

Return 0 if the array contains less than 2 elements.

You may assume that all the elements in the array are non-negative integers and fit in the 32-bit signed integer range.

You may also assume that the difference will not overflow.

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 happens if no arguments are passed to the seek function?

a) file position is set to the start of file

b) file position is set to the end of file

c) file position remains unchanged

d) error

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

import turtle

t=turtle.Pen()

t.forward(100)

t.left(90)

t.clear()

t.position()

a) 0.00, 90.00

b) 0.00, 0.00

c) 100.00, 90.00

d) 100.00, 100.00

3. In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to __________

a) Zero

b) None

c) One

d) Error

4. Which function is used to writeall the characters?

a) write()

b) writecharacters()

c) writeall()

d) writechar()

5. Which function is used to close a file in python?

a) Close()

b) Stop()

c) End()

d) Closefile()

6. What is tail recursion?

a) A recursive function that has two base cases

b) A function where the recursive functions leads to an infinite loop

c) A recursive function where the function doesn't return anything and just prints the values

d) A function where the recursive call is the last thing executed by the function

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

x = [[0], [1]]

print((' '.join(list(map(str, x))),))

a) ('[0] [1]',)

b) ('01')

c) [0] [1]

d) 01

8. What does random.shuffle(x) do when x = [1, 2, 3]?

a) error

b) do nothing, it is a placeholder for a function that is yet to be implemented

c) shuffle the elements of the list in-place

d) none of the mentioned

9. What does os.link() do?

a) createa symbolic link

b) createa hard link

c) createa soft link

d) none of the mentioned

10. The module _______________ is a comparatively faster implementation of the pickle module.

a) cPickle

b) nPickle

c) gPickle

d) tPickle

11. Where are the arguments received from the command line stored?

a) sys.argv

b) os.argv

c) argv

d) none of the mentioned

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

class stud:

'Base class for all students'

def init(self, roll_no, grade):

self.roll_no = roll_no

self.grade = grade

def display (self):

print("Roll no : ", self.roll_no,", Grade: ", self.grade)

print(student.doc)

a) Exception is thrown

b) main

c) Nothing is displayed

d) Base class for all students

13. What will be the output of print(math.factorial(4.5))?

a) 24

b) 120

c) error

d) 24.0

14. 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'}

15. What is returned by math.expm1(p)?

a) (math.ep) - 1

b) math.e(p - 1)

c) error

d) none of the mentioned

16. 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()

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

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a) None

b) { None:None, None:None, None:None}

c) {1:None, 2:None, 3:None}

d) { }

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

elements = [0, 1, 2]

def incr(x):

return x+1

print(list(map(elements, incr)))

a) [1, 2, 3]

b) [0, 1, 2]

c) error

d) none of the mentioned

19. An exception is ____________

a) an object

b) a special function

c) a standard module

d) a module

20. Which of the following creates a pattern object?

a) re.create(str)

b) re.regex(str)

c) re.compile(str)

d) re.assemble(str)

21. How are variable length arguments specified in the function heading?

a) one star followed by a valid identifier

b) one underscore followed by a valid identifier

c) two stars followed by a valid identifier

d) two underscores followed by a valid identifier

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

import turtle

t=turtle.Pen()

for i in range(0,5):

t.left(144)

t.forward(100)

a) Trapezium

b) Parallelepiped

c) Tetrahedron

d) Star

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

re.split(r'(n\d)=', 'n1=3.1, n2=5, n3=4.565')

a) Error

b) [", 'n1', '3.1, ', 'n2', '5, ', 'n3', '4.565']

c) ['n1', '3.1, ', 'n2', '5, ', 'n3', '4.565']

d) ['3.1, ', '5, ', '4.565']

24. Which of the following refers to mathematical function?

a) sqrt

b) rhombus

c) add

d) rhombus

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

def C2F(c):

return c * 9/5 + 32

print C2F(100)

print C2F(0)

a)

212

32

b)

314

24

c)

567

98

d) None of the mentioned

26. The number of lines drawn in each case, assuming that the turtle module has been imported:

Case 1:

for i in range(0,10):

turtle.forward(100)

turtle.left(90)

Case 2:

for i in range(1,10):

turtle.forward(100)

turtle.left(90)

a) 10, 9

b) 9, 10

c) 9, 9

d) 10, 10

27. Lambda functions cannot be pickled because:

a) Lambda functions only deal with binary values, that is, 0 and 1

b) Lambda functions cannot be called directly

c) Lambda functions cannot be identified by the functions of the pickle module

d) All lambda functions have the same name, that is,

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

x = ['ab', 'cd']

print(list(map(list, x)))

a) ['a', 'b', 'c', 'd']

b) [['ab'], ['cd']]

c) [['a', 'b'], ['c', 'd']]

d) none of the mentioned

29. Which function overloads the >> operator?

a) more()

b) gt()

c) ge()

d) none of the mentioned

30. What is the output of print(math.trunc('3.1'))?

a) 3

b) 3.0

c) error

d) none of the mentioned

31. Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match='aaaa'>.

a) >>> re.search('aaaa', "alohaaaa", 0)

b) >>> re.match('aaaa', "alohaaaa", 0)

c) >>> re.match('aaa', "alohaaa", 0)

d) >>> re.search('aaa', "alohaaa", 0)

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!