I'm trying to type an algorithm in Latex while using Algorithm2e. I have defined a function, but on compiling I am running into missing dollar inserted error frequently. Here is my script;
\begin{algorithm}[H]
\SetAlgoLined
\DontPrintSemicolon
\KwIn{$ arr$,$result$}
\KwOut{$ result$ }
\SetKwFunction{FMain}{nonoverlap}
\SetKwProg{Fn}{Function}{:}{}
\Fn{\FMain{$x$,$result$}}{
temp=x[0] \;
\ForEach{$idx$, $element$ \in enumerate($x[1:,],1$)}{
\uIf{\text{element}[0] $>$ temp[1]}{
$temp.append(element)$ \;
}
\uElseIf{
nonoverlap($x[idx:]$,$[]$)
}
}
result.append(temp) \;
\textbf{return} result \;
}
\textbf{End Function}
\caption{Algorithm for Identifying Non-Overlapping subarrays}
\label{NagetionAlgo}
\end{algorithm}
The error is being pointed at this line;
\textbf{End Function}
Kindly advise if I'm missing something here. Help is appreciated.