ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
def ack(m, n):
if m == 0:
return n + 1
if n == 0:
return ack(m - 1, 1)
return ack(m - 1, ack(m, n - 1))
print(ack(2, 2))- A. 7
- B. 9
- C. 4
- D. 29
Correct answer: A. 7
ack(1, n) = n + 2 and ack(2, n) = 2n + 3, so ack(2, 2) = 7. 9 is ack(2, 3), 4 is ack(1, 2), and 29 applies the m = 3 formula 2^(n+3) − 3.
More Python Programming questions
- What is printed? python print(list(range(-3, 3)), list(zip(range(3), 'ab')))
- Why is del a[0] on a Python list O(n), while a.pop() is O(1)?
- For a sliding-window maximum over an array of n = 2 10^5 values, which Python structure gives an O(n) total algorithm?
- What is the usual fastest way to read n = 10^6 integers from one input line in Python for a judge?
- What is printed? python import heapq print(heapq.nsmallest(2, [5, 1, 4, 1]), list(reversed(range(3))), list(reversed('ab')))
- What is printed? python print(any(map(str.isdigit, 'ab1')), all(map(str.isalpha, 'ab1')))