What Will Be The Output Of The Following Codep Pre Langc #422
What will be the output of the following code?</p> <pre><code class="language-c"> #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; } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Array Types - Number of Jumps to Reach End-array Operation - Quiz No.1.
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes