Added advanced Java solution