Bravura Solutions interview question

Question from Java , some algorithm and some SQL queries