/**
 * Given two strings, return a new string consisting of the common characters
 * present in both strings. The order of characters in the output string should
 * be the same as the order of their first occurrence in the first string.
 *
 * @param str1 The first string
 * @param str2 The second string
 * @return The string consisting of common characters
 *
 * Example:
 * commonCharacters("hello", "world") => "lo"
 * commonCharacters("python", "java") => ""
 * commonCharacters("apple", "pineapple") => "apple"
 */
fun commonCharacters(str1: String, str2: String): String {

    var result = ""
    var i = 0

    while (i < str1.length) {
        val char = str1[i]

        if (char in str2 && char !in result) {
            result += char
        }

        i++
    }

    return result
}
/**
 * Given two strings, return a new string consisting of the common characters
 * present in both strings. The order of characters in the output string should
 * be the same as the order of their first occurrence in the first string.
 *
 * @param str1 The first string
 * @param str2 The second string
 * @return The string consisting of common characters
 *
 * Example:
 * commonCharacters("hello", "world") => "lo"
 * commonCharacters("python", "java") => ""
 * commonCharacters("apple", "pineapple") => "apple"
 */
fun commonCharacters(str1: String, str2: String): String {
/**
 * Given two strings, return a new string consisting of the common characters
 * present in both strings. The order of characters in the output string should
 * be the same as the order of their first occurrence in the first string.
 *
 * @param str1 The first string
 * @param str2 The second string
 * @return The string consisting of common characters
 *
 * Example:
 * commonCharacters("hello", "world") => "lo"
 * commonCharacters("python", "java") => ""
 * commonCharacters("apple", "pineapple") => "apple"
 */
fun commonCharacters(str1: String, str2: String): String {

    var result = ""
    var i = 0

    while (i < str1.length) {
        val char = str1[i]

        if (char in str2 && char !in result) {
            result += char
        }

        i++
    }

    return result
}