# Codility: MaxProfit Solution

*Lesson 9 Maximum Slice Problem*

## Approach

Keep track of the min day

## Implementation

1function solution(A) {2 let max = -Infinity3 let min = A[0]4 for (let i = 1; i < A.length; i++) {5 max = Math.max(max, A[i] - min)6 if (min > A[i]) {7 min = A[i]8 }9 }10 return max > 0 ? max : 011}

## Comments

Loading comments...

## Tags

codility

## Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

**Fact corner:** Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

**Still hesitate?** Read HoningJS author's guide on dealing with Toptal interview process.

## Next Post

Hackerrank: 2D Array - DS

Jan 26, 2021