Final solutions for pseudocode and c++/java implementation