The Startup
Published in

The Startup

Understanding Leetcode: The Two Sum Problem

The problem: Given an array of integers, return indices of the two numbers such that they add up to specific target. Assume that there exists exactly one solution, and that you may not use the same element twice.

The Naive Approach

Before starting to program a solution, we always want to think about what the problem is asking, and how we would solve it on paper. This will reveal the algorithm used to solve the problem.

So, let’s start with an example instance of the problem. Suppose you are given the…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store