Select the correct option to test your answer:
Computer
Arrays In Data Structures
Difficulty: Medium
What will be the output of the following code? #include <bits/stdc++.h> using namespace std; void func(int arr[], int n) { int count[n]; memset(count, 0, sizeof(count)); for (int i=n-2; i>=0; i--) { if (arr[i] >= n - i - 1) count[i]++; for (int j=i+1; j < n-1 && j <= arr[i] + i; j++) if (count[j] != -1) count[i] += count[j]; if (count[i] == 0) count[i] = -1; } for (int i=0; i<n; i++) cout << count[i] << " "; } int main() { int arr[] = {1, 3, 5, 8, 9}; int n = sizeof(arr) / sizeof(arr[0]); func(arr, n); return 0; }
More Computer Questions
In Hive, what is the role of the STORED BY clause in a CREATE TABLE statement?
Which function will return the quotient and remainder on division of numerator with denominator?
How many types of storage loops exist in magnetic bubble memory?
Which one of the following keywords is used to define an abstract class?
What will be the output of the following Python code? x = 50 def func(x): print('x is', x) x = 2 print('Changed local x to', x) func(x) print('x is now', x)