Pergunta de entrevista da empresa Motive

There was a coding problem where I had to calculate maximum profit in a array by comparing the adjacent values.