Skip to content

Instantly share code, notes, and snippets.

📡
contacting aliens

Anthony Attard anthonyattard

📡
contacting aliens
Block or report user

Report or block anthonyattard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@anthonyattard
anthonyattard / two-pointer-container-with-most-water.md
Last active Aug 13, 2019
Two Pointer - Container with Most Water
View two-pointer-container-with-most-water.md

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 line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. From https://leetcode.com/problems/container-with-most-water/

Algorithm

The intuition behind this approach is that the area formed between the lines will always be limited by the height of the shorter line. Further, the farther the lines, the more will be the area obtained.

We take two pointers, one at the beginning and one at the end of the array constituting the length of the lines. Futher, we maintain a variable maxarea to store the maximum area obtained till now. At every step, we find out the area formed between them, update maxarea and move the pointer pointing to the shorter line towards the other end by one step.

How this approach works?

View Keeping a fork up to date.md

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
View shoemagoo-quiz.md
function greeting($hello = false) {
  if($hello === true) {
    echo("hello");
  } else {
    echo("bye");
  }
}
@anthonyattard
anthonyattard / README-Template.md
Last active Aug 13, 2019 — forked from PurpleBooth/README-Template.md
Good README/Markdown Template
View README-Template.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You can’t perform that action at this time.