firstRecurringCharacter

Not run yet
93 runs
This repl has no cover image
Details
Created on Oct 12, 2018
2 Reactions
1comment
to comment
joeanddaneil51 week ago
thinking like this:use extra space to store the recurring indexrecur_index = []for i loop len(array)-1: ; for j loop (i+1, len(array));if array[i] == array[j]: append:jreturn array[min(recur_index = [])]brute solution in python

def firstRecurringCharacter(arr): recur_index = [] for i in range(len(arr)-1): for j in range(i+1, len(arr)): if arr[i] == arr[j]: recur_index.append(j) return arr[min(recur_index)] if recur_index else Nonerepl_link: https://replit.com/@joeanddaneil5/7-84-Exercise-First-Recurring-Characterpy#main.py

solve [2,5,5,2,3,5,1,2,4] this case return 5// brute solution in javascriptfunction firstRecurringCharacter(arr){ const recurIdex = []; for (let i =0; i < arr.length - 1; i++){ for (let j = i+1; j < arr.length; j++){ if (arr[i] === arr[j]){ recurIdex.push(j); } } } // console.log(recurIdex) // console.log([Math.min(...recurIdex)]); return arr[Math.min(...recurIdex)];repl_link: https://replit.com/@joeanddaneil5/7-84-Exercise-First-Recurring-Characterjs#index.js