Implemented the algo logic with Lmax