Ackermann Queries

For each query (m, n), compute the Ackermann function value A(m, n) using these rules:

  • A(0, n) = n + 1
  • A(m, 0) = A(m - 1, 1) for m > 0
  • A(m, n) = A(m - 1, A(m, n - 1)) for m > 0 and n > 0

Return one result for each query, in the same order as the input.

Implement ackermannQueries(vector<vector<int>>& queries).

Example 1:

Input: queries = [[0, 4], [1, 2]]

Output: [5, 4]

Explanation: A(0, 4) = 5 and A(1, 2) = 4.

Example 2:

Input: queries = [[2, 0], [2, 3]]

Output: [3, 9]

Explanation: A(2, 0) = A(1, 1) = 3, and applying the recurrence gives A(2, 3) = 9.

Now Your Turn!

Pick the correct output for the given input

Input: queries = [[3, 1], [2, 2]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= queries.size() <= 100
  • Each query contains exactly two integers, m and n.
  • 0 <= m <= 3
  • 0 <= n <= 4
  • The result for every query fits in a signed 64-bit integer.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
vector<long long> ackermannQueries(vector<vector<int>>& queries) {
// Write your code here.
 
}
};
Test Case

Input:

Queries