Warmup: Two-sum

Try to write a Python function to do the following:

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

Example 1:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]

Setup instructions

Open your terminal (or WSL for PC users), and run the following: https://github.com/jomart-gsu/lect4-materials-sp22.git <-- clone down this Git repo

sudo apt install python3-pip <-- install pip, the Python package manager (this command may vary slightly for WSL users)

pip3 install pylint <-- if pip3 isn't recognize, try just "pip"

pip3 install flask <-- this is really just to be ready for future lectures, but while we’re here, might as well!

For an easier time with linting, open VSCode and install the Python extension. (The link works, but you can do the same from inside the app.)

Extra time?

Try one of the unused problems from last week's interview practice session!