LeetCode-Solutions icon indicating copy to clipboard operation
LeetCode-Solutions copied to clipboard

Add JavaScript solution to Container With Most Water Problem

Open macnick opened this issue 4 years ago • 1 comments

Pull Request Template

Description

Given n non - negative integers a1, a2, ..., an, where each represents a point at coordinate(i, ai).n vertical lines are drawn such that the two endpoints of the line i is at(i, ai) and(i, 0). Find two lines, which, together with the x - axis forms a container, such that the container contains the most water.

Logic:

We use two pointers, one at the start (left) and one at the end (right) of the array. We calculate the maximum water that can be contained between these two. If the left barrier is smaller than the right, we advance the left pointer otherwise the right. We calculate again the quantity and update the max. Continue this procedure until the pointers meet.

Put check marks:

Have you made changes in README file ?

  • [x] Added problem & solution under correct topic.
  • [x] Specified Space & Time complexity.
  • [x] Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • [x] Test A: Passes all test on the website
  • [x] Test B: Checked on custom corner cases as well

Make sure all below guidelines are followed else PR will get Reject:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code so that it is easy to understand
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] Any dependent changes have been merged and published in downstream modules

macnick avatar Oct 11 '21 07:10 macnick

I can tell this is your first pull request! Thank you I'm so honored. :tada::tada::tada: I'll take a look at it ASAP!

welcome[bot] avatar Oct 11 '21 07:10 welcome[bot]