Question: You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and
You are given a read only array of n integers from 1 to n.
Each integer appears exactly once except A which appears twice and B which is missing.
Return A and B.
Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Note that in your output A should precede B.
Example:
Input:[3 1 2 5 3]
Output:[3, 4]
A = 3, B = 4
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?
class A:
def init(self, x= 1):
self.x = x
class der(A):
def init(self,y = 2):
super().init()
self.y = y
def main():
obj = der()
print(obj.x, obj.y)
main()
a) Error, the syntax of the invoking method is wrong
b) The program runs fine but nothing is printed
c) 1 0
d) 1 2
2. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
a) 1 2 3
b) 'A' 'B' 'C'
c) 1 'A' 2 'B' 3 'C'
d) Error, it should be: for i in a.items():
3. Does Lambda contains return statements?
a) True
b) False
4. The output of the following codes are the same.
[x**2 for x in range(10)]
list(map((lambda x:x**2), range(10)))
a) True
b) False
5. Which of the following functions accepts only integers as arguments?
a) ord()
b) min()
c) chr()
d) any()
6. What will be the output of the following Python code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
a) 4
b) 5
c) 1
d) An exception is thrown
7. How are required arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (")
c) identifier followed by the default value within square brackets ([])
d) identifier
8. What are the methods which begin and end with two underscore characters called?
a) Special methods
b) In-built methods
c) User-defined methods
d) Additional methods
9. Which of the following will result in an error?
a)
>>> p = re.compile("d")
>>> p.search("door")
b) >>> p = re.escape('hello')
c) >>> p = re.subn()
d) >>> p = re.purge()
10. The randrange function returns only an integer value.
a) True
b) False
11. 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
12. What will be the output of the following Python code?
a={1:5,2:3,3:4}
print(a.pop(4,9))
a) 9
b) 3
c) Too many arguments for pop() method
d) 4
13. What will be the output of the following Python code?
re.split('[a-c]', '0a3B6', re.I)
a) Error
b) ['a', 'B']
c) ['0', '3B6']
d) ['a']
14. 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,
15. What is the type of each element in sys.argv?
a) set
b) list
c) tuple
d) string
16. What will be the output of the following Python code?
l=[1, 2, 3, 4, 5]
m=map(lambda x:2**x, l)
print(list(m))
a) [1, 4, 9, 16, 25 ]
b) [2, 4, 8, 16, 32 ]
c) [1, 0, 1, 0, 1]
d) Error
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
