import [Link].
Arrays;
import [Link];
public class ArrayStats {
private int[] array; // Declare the array as an instance variable
// Constructor to initialize the array
public ArrayStats(int[] arr) {
[Link] = arr;
}
// Method to count the number of groups of size "size"
public int getNumGroupsOfSize(int size) {
int cnt = 0; // To count groups of the specified size
int currentCount = 1; // To count consecutive same elements
// Iterate through the array starting from the second element
for (int i = 1; i < [Link]; i++) {
if (array[i] == array[i - 1]) {
currentCount++; // Increase the count if the current element is
the same as the previous one
} else {
// Check if the group size is exactly "size"
if (currentCount == size) {
cnt++; // Increment the count of groups of the given size
}
currentCount = 1; // Reset count for a new value
}
}
// After the loop, check the last group
if (currentCount == size) {
cnt++;
}
return cnt;
}
// Method to return the string representation of the array
public String toString() {
return [Link](array);
}
}