Edited with solution for assignment