/**
 * This exercise requires finding the intersection of elements
 * in a list with a specified number of repetitions.
 *
 * @param elements a list of elements
 * @param repetitions an integer specifying the number of repetitions
 * @return a list containing the elements that occur exactly 'repetitions' number of times
 */
fun intersectionOfRepetitionAndAccessingElements(elements: List<Int>, repetitions: Int): List<Int> {

    val result = mutableListOf<Int>()

    // Count the occurrences of each element in the list
    val counts = elements.groupingBy { it }.eachCount()

    // Get the elements that occur exactly 'repetitions' number of times
    for ((element, count) in counts) {
        if (count == repetitions) {
            result.add(element)
        }
    }

    return result
}

// Example usage
/**
 * This exercise requires finding the intersection of elements
 * in a list with a specified number of repetitions.
 *
 * @param elements a list of elements
 * @param repetitions an integer specifying the number of repetitions
 * @return a list containing the elements that occur exactly 'repetitions' number of times
 */
fun intersectionOfRepetitionAndAccessingElements(elements: List<Int>, repetitions: Int): List<Int> {
/**
 * This exercise requires finding the intersection of elements
 * in a list with a specified number of repetitions.
 *
 * @param elements a list of elements
 * @param repetitions an integer specifying the number of repetitions
 * @return a list containing the elements that occur exactly 'repetitions' number of times
 */
fun intersectionOfRepetitionAndAccessingElements(elements: List<Int>, repetitions: Int): List<Int> {

    val result = mutableListOf<Int>()

    // Count the occurrences of each element in the list
    val counts = elements.groupingBy { it }.eachCount()

    // Get the elements that occur exactly 'repetitions' number of times
    for ((element, count) in counts) {
        if (count == repetitions) {
            result.add(element)
        }
    }

    return result
}

// Example usage