/**
 * Given a list of minerals and a list of rocks, find the common minerals present in all rocks.
 *
 * @param minerals A list of minerals.
 * @param rocks A list of rocks.
 * @return A list of common minerals found in all rocks.
 */
fun findCommonMinerals(minerals: List<String>, rocks: List<String>): List<String> {

    var commonMinerals = mutableListOf<String>()
    for (rock in rocks) {
        val intersectingMinerals = mutableListOf<String>()
        for (mineral in minerals) {
            if (rock.contains(mineral)) {
                intersectingMinerals.add(mineral)
            }
        }
        if (commonMinerals.isEmpty()) {
            commonMinerals = intersectingMinerals.toMutableList()
        } else {
            commonMinerals.retainAll(intersectingMinerals)
        }
    }
    return commonMinerals
}
/**
 * Given a list of minerals and a list of rocks, find the common minerals present in all rocks.
 *
 * @param minerals A list of minerals.
 * @param rocks A list of rocks.
 * @return A list of common minerals found in all rocks.
 */
fun findCommonMinerals(minerals: List<String>, rocks: List<String>): List<String> {
/**
 * Given a list of minerals and a list of rocks, find the common minerals present in all rocks.
 *
 * @param minerals A list of minerals.
 * @param rocks A list of rocks.
 * @return A list of common minerals found in all rocks.
 */
fun findCommonMinerals(minerals: List<String>, rocks: List<String>): List<String> {

    var commonMinerals = mutableListOf<String>()
    for (rock in rocks) {
        val intersectingMinerals = mutableListOf<String>()
        for (mineral in minerals) {
            if (rock.contains(mineral)) {
                intersectingMinerals.add(mineral)
            }
        }
        if (commonMinerals.isEmpty()) {
            commonMinerals = intersectingMinerals.toMutableList()
        } else {
            commonMinerals.retainAll(intersectingMinerals)
        }
    }
    return commonMinerals
}