export function duplicateEncode(word: string) {
  let res = "";
  let i = 0;

  while (i < word.length) {
    const char = word[i];

    const firstIndex = word.indexOf(char)
    const lastIndex = word.lastIndexOf(char)

    if (firstIndex !== lastIndex) {
      res += ")"
    } else {
      res += "("
    }

    i++
  }

  return res;
}

export function duplicateEncode1(word: string) {
  return word
    .toLowerCase()
    .split('')
    .map((a, _, w) => {
      return w.indexOf(a) == w.lastIndexOf(a) ? '(' : ')'
    })
    .join('')
}

console.log(
  duplicateEncode("din"), "((("
)
console.log(
  duplicateEncode("recede"), "()()()"
)
console.log(
  duplicateEncode("Success"), ")())())"
)
console.log(
  duplicateEncode("(( @"), "))(("
)
