A question a Hackerrank "Lonely Integer" has the following requirements. Given a set of integer with size N, find integers that are not repeated.
I am a Bash noob. I am finding a lot of trouble with bash, for example, when do I use while (( )) vs while [[ ]], vs while [ ]?
I have been debugging this code for the past 1 hour.... Its taking way too long, this question is not hard at all. I did the question using the most naive way possible which has a run time of O(n^2)
The compiler is complaining
"solution.sh: line 7: [: 1: integer expression expected"
I have tried to change my while loop to while(()), while[[]], while[ ], none of them work!!
My main question is, can someone please point out to me why my code does not work?!
Solutions are not available on hackerrank
Thanks!
read N
read line
declare -a array=( $line )
i=0
k=0
while [ $i -lt $N ]
do
isunique=1
j=0
while [ $j -lt $N ]
do
if [[ ${array[$i]} -eq ${array[$j]} ]] && [[ $i -ne $j ]]
then
isunique=0
break
fi
j=$((j+1))
done
if [ $isunique -eq 1 ]
then
unique[$k]=${array[$i]}
k=$((k+1))
fi
i=$((i+1))
done
echo ${unique[@]}
exit 0