#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d", &n); int arr[n];…
Jump to turn (9)
- 1#include #include int main() { int n; scanf("%d", &n); int arr[n]; for (int i =
- 2it is giving only 5 6 7
- 3You are given a number n and an array book representing the numbers on each book
- 4it is zero based
- 5so the output for length should be 4 and the indices should be 1 2 3 5 or 0 4 6
- 6so the output for length should be 4 and the indices should be 1 2 3 5 which cor
- 7#include #include int main() { int n; scanf("%d", &n); if (n maxlength) { maxlen
- 81 <= n <= 2 ⋅ 10^5 1 <= book[i] <= 10^9
- 9dont use macros
- User
#include <stdio.h> #include <stdlib.h>
int main() { int n; scanf("%d", &n); int arr[n];
codefor (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int max = 0; int maxIndex = 0; int length = 1; int startIndex = 0; int freq[n]; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1] + 1) { length++; } else { if (length > max) { max = length; maxIndex = startIndex; } startIndex = i; length = 1; } } if (length > max) { max = length; maxIndex = startIndex; } if (max > 1) { printf("%d\n", max); for (int i = 0; i < max; i++) { freq[i] = i + arr[maxIndex]; printf("%d ", freq[i]); } printf("\n"); } else { printf("No subset found.\n"); } return 0;}
output for 9 1 5 6 7 2 8 3 4 10 should be 5 6 7 8