General algorithm solutions