/**
 * Given a list of samples, where each sample is represented as a dictionary with keys 'name', 'composition', and 'source',
 * calculate the total number of unique chemical elements present in the samples.
 *
 * @param samples A list of dictionaries containing information about the samples.
 * @return A list of chemical elements present in the samples.
 */
fun calculateChemicalElements(samples: List<Map<String, List<String>>>): List<String> {

    val chemicalElements = mutableSetOf<String>()

    for (sample in samples) {
        val composition = sample["composition"] ?: emptyList()
        chemicalElements.addAll(composition)
    }

    return chemicalElements.toList()
}

// Sample Usage
val samples = listOf(
    mapOf("name" to "Sample 1", "composition" to listOf("H", "O", "C", "N"), "source" to "River"),
    mapOf("name" to "Sample 2", "composition" to listOf("C", "O", "N"), "source" to "Lake"),
    mapOf("name" to "Sample 3", "composition" to listOf("H", "C", "N"), "source" to "Ocean"),
    mapOf("name" to "Sample 4", "composition" to listOf("H", "O"), "source" to "Rain")
)
/**
 * Given a list of samples, where each sample is represented as a dictionary with keys 'name', 'composition', and 'source',
 * calculate the total number of unique chemical elements present in the samples.
 *
 * @param samples A list of dictionaries containing information about the samples.
 * @return A list of chemical elements present in the samples.
 */
fun calculateChemicalElements(samples: List<Map<String, List<String>>>): List<String> {
/**
 * Given a list of samples, where each sample is represented as a dictionary with keys 'name', 'composition', and 'source',
 * calculate the total number of unique chemical elements present in the samples.
 *
 * @param samples A list of dictionaries containing information about the samples.
 * @return A list of chemical elements present in the samples.
 */
fun calculateChemicalElements(samples: List<Map<String, List<String>>>): List<String> {

    val chemicalElements = mutableSetOf<String>()

    for (sample in samples) {
        val composition = sample["composition"] ?: emptyList()
        chemicalElements.addAll(composition)
    }

    return chemicalElements.toList()
}

// Sample Usage
val samples = listOf(
    mapOf("name" to "Sample 1", "composition" to listOf("H", "O", "C", "N"), "source" to "River"),
    mapOf("name" to "Sample 2", "composition" to listOf("C", "O", "N"), "source" to "Lake"),
    mapOf("name" to "Sample 3", "composition" to listOf("H", "C", "N"), "source" to "Ocean"),
    mapOf("name" to "Sample 4", "composition" to listOf("H", "O"), "source" to "Rain")
)