Вот быстрые функции, чтобы ответить на ваш вопрос относительно целочисленного массива.
int count_occur(string arr2[], int arr1[], string repeated) {
int sum = 0;
for (int i = 0; i < arr1.length; i++) {
if (arr2[i] == repeated) sum += arr1[i];
}
return count;
}
void repeated_sum() {
int[] arr1 = new int[]{1,2,1,1,2,1}; //given array
string arr2[] = {"a","b","c","b","b","a"}
string repeat = "a"; //number to count repeats
int result = count_occur(arr2, arr1, repeat); //count repeats and multiply to get the summation
System.out.println(result);
}