Two sum problem
Hello! Today I will explain how to solve the Two Sum problem. I believe most developers have seen this problem before—either when they first started practicing coding or when preparing for job inte...

Source: DEV Community
Hello! Today I will explain how to solve the Two Sum problem. I believe most developers have seen this problem before—either when they first started practicing coding or when preparing for job interviews. For those in the software industry who haven’t solved this problem yet, I’ll show you how to approach it step by step. Let’s get started. Question Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to target. You may assume that each input has exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example Input: nums = [2,11,15,7], target = 9 Output: [0,3] Explanation: Because nums[0] + nums[3] == 9, we return [0, 3]. Solution function twoSum(nums, target) { for (let i = 0; i < nums.length ; i++) { for (let j = i + 1; j < nums.length ; j++) { if (nums[i] + nums[j] === target) { return [i, j] } } } return [] }; const nums = [2, 11, 15, 7] const target = 9 console.log