Stack algorithm should work perfectly now