saveprincess solution for hackerrank