ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
def merge(a, b):
i = j = 0
out = []
while i < len(a) and j < len(b):
if a[i] <= b[j]:
out.append(a[i])
i += 1
else:
out.append(b[j])
j += 1
out += a[i:] + b[j:]
return out
print(merge([1, 4, 4, 9], [2, 4, 10]))- A. [1, 2, 4, 4, 9, 10]
- B. [1, 2, 4, 4, 4, 10, 9]
- C. [1, 2, 4, 4, 4, 9, 10]
- D. [1, 2, 4, 9, 4, 4, 10]
Correct answer: C. [1, 2, 4, 4, 4, 9, 10]
With <= the a-side copy of 4 goes first. Together the inputs hold three 4s, so all three appear, and the leftover 10 from b is appended last.
More Python Programming questions
- What is printed? python from collections import deque def maxdist(g): R, C = len(g), len(g[0]) d = [[-1] C for in range(R)] q = deque()…
- What is printed? python from collections import Counter c = Counter('mississippi') print(c.mostcommon(2))
- What is printed? python def maxprod(a): best = curmax = curmin = a[0] for x in a[1:]: cands = (x, curmax x, curmin x) curmax, curmin =…
- What is printed? python def jumps(a): j = cur = far = 0 for i in range(len(a) - 1): far = max(far, i + a[i]) if i == cur: j += 1 cur = far…
- What is printed? python def profit(p): lo, best = float('inf'), 0 for x in p: lo = min(lo, x) best = max(best, x - lo) return best…
- What is the time complexity of building a binary heap from n unordered items with heapq.heapify?