!"#$$%#&'$(
)*+,-./(012/(3((
45.2,*67#(!&8(/*75,-9:(2(;<69-+(=66>(;<69-+(76,-(-12/?((
!"#($%&'(&')*+&,-#(37(,@-(<-; ,5.-:(A-(+*9; 5 99 - +( 𝑂(𝑁
$
log 𝑁)(2<B6.*,@/(=C(
*7,.6+5;*7B(=*72.C(9-2.;@(,6(2(=.5,-DE6.;-(F-.9*67?(3(/-7 ,*67 -+ (,@2,(A -(
;65<+(2;@*-F-(𝑂(𝑁
$
)(59*7B(@29@(,2=<-:(A@*;@(A*<<(=-(;6 F- . -+(*7(<2,-.(G2. ,(
6E(,@-(;65.9-?(H6A-F-.:(A-(;27(+-F-<6G(276,@-.(F-.9*67(6E(𝑂(𝑁
$
)(
2<B6.*,@/(E6.($D95/(G.6=<-/:(A*,@65,(59*7B(@29@(,2=<-:(=C(;2.-E5<<C(
,-9,*7B(2<<(G699*=<-(G2*.9?(I65.( 7-A(2<B6.*,@/(/2C(7-*,@-.(59-(@29@(,2=<-(
76.(=*72.C(9-2.;@?(4-F-<6G(95;@(27(2<B6.*,@/:(A.*,-(2(G9-5+6;6+-:(27+(
=.*-E<C(272<CJ-(,@-(2<B6.*,@/:(*?-?:(A@C(*,(*9(𝑂(𝑁
$
):(-,;?(K%8G,L(
(
./01))
S := an input array of length n.
sort(S);
for i=0 to n-3 do
a = S[i];
start = i+1;
end = n-1;
while (start < end) do
b = S[start]
c = S[end];
if (a+b+c == 0) then
output a, b, c;
// Continue search for all triplet combinations summing to zero.
end = end - 1
else if (a+b+c > 0) then
end = end - 1;
else