We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
readNread-aarr# We create the variable found to help us iteratefound=0while[[${#arr[@]}-gt1]];do# We create an array with the existent indexesidx=()foriin${!arr[@]};doidx+=("$i")done# We pick the first valuecheck=${arr[${idx[$found]}]}# We start the counter of matchescount=0# We check the array counting matchesforiin${!arr[@]};doif[["${arr[$i]}"-eq"$check"]];then((count++))fidone# We check how many matches we haveif[[$count-eq2]];then# If we have 2 matcher, we delete ALL matchesforiin${!arr[@]};doif[["${arr[$i]}"-eq"$check"]];thenunsetarr[$i]fidoneelse# Else, we have 1 match, aka the lonely integer# We increase the found, so the check value skips the one((found++))fidoneecho"${arr[@]}"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer - Bash!
You are viewing a single comment's thread. Return to all comments →