Question
Given a read only array of n + 1 integers between 1 and n, find one number that repeats in linear time using less than
Given a read only array of n + 1 integers between 1 and n, find one number that repeats in linear time using less than O(n) space and traversing the stream sequentially O(1) times.
Sample Input:
[3 4 1 4 1]
Sample Output:
1
If there are multiple possible answers ( like in the sample case above ), output any one.
If there is no duplicate, output -1
Python code for above cp question and mcq questions explanation is must. code will be tested on large test cases
1. To open a file c:\scores.txt for reading, we use _____________
a) infile = open("c:\scores.txt", "r")
b) infile = open("c:\\scores.txt", "r")
c) infile = open(file = "c:\scores.txt", "r")
d) infile = open(file = "c:\\scores.txt", "r")
2. 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,
3. Method issubclass() checks if a class is a subclass of another class.
a) True
b) False
4. What is a variable defined inside a function referred to as?
a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable
5. Which of the following functions clears the regular expression cache?
a) re.sub()
b) re.pos()
c) re.purge()
d) re.subn()
6. What will be the output of the following Python code?
e="butter"
def f(a): print(a)+e
f("bitter")
a) error
b)
butter
error
c)
bitter
error
d) bitterbutter
7. What will be the output of the following Python code?
import turtle
t=turtle.Pen()
t.color(0,0,1)
t.begin_fill()
t.circle(15)
t.end_fill()
a) Error
b) A circle filled in with the colour red
c) A circle filled in with the colour blue
d) A circle filled in with the colour green
8. Which type of elements are accepted by random.shuffle()?
a) strings
b) lists
c) tuples
d) integers
9. What will be the output of the following Python code?
def f(p, q, r):
global s
p = 10
q = 20
r = 30
s = 40
print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)
a) 1 2 3 4
b) 5 10 15 4
c) 10 20 30 40
d) 5 10 15 40
10. The output of the following two Python codes is exactly the same.
object
'a'
CODE 1
>>> pickle.dumps('a', 3)
CODE 2
>>> pickle.dumps(object, 3)
a) True
b) False
11. What will be the output of the following Python function if the random module has already been imported?
random.randint(3.5,7)
a) Error
b) Any integer between 3.5 and 7, including 7
c) Any integer between 3.5 and 7, excluding 7
d) The integer closest to the mean of 3.5 and 7
12. What is returned by math.ceil(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
13. What will be the output of the following Python code, if the time module has already been imported?
def num(m):
t1 = time.time()
for i in range(0,m):
print(i)
t2 = time.time()
print(str(t2-t1))
num(3)
a)
1
2
3
The time taken for the execution of the code
b)
3
The time taken for the execution of the code
c)
1
2
3
UTC time
d)
3
UTC time
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