1. Two Sum
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
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Solution
Step 01: I simply iterate the array using for loops, and inside the for loops I iterate the array again but this time start the index with the next position(compare to the first iteration)
Step 02: In this way, I got pair of numbers from the array and check if the total of the pair is equal to the target number or not.
Step 03: If the total value is equal to the target, I simply return the index numbers.
If you want me to publish more posts like this, Buy me a coffee.
π YouTube Channel Link: https://www.youtube.com/channel/UCW_09Nbobf4URLkAlEo84sw
π PlayList Link: https://youtube.com/playlist?list=PLUnklBXn8NSefCpBaLe39mds6dQx-tDDD
π Connect with me (LinkedIn): https://www.linkedin.com/in/abusalehfaysal
π Follow our LinkedIn Page:
π Like our Facebook page: https://www.facebook.com/thebacklogprogrammer/
π Join our community (Facebook group): https://www.facebook.com/groups/5500588936676942/
π Follow me at: https://www.facebook.com/AbuSalehFaysal10
π Twitter: https://twitter.com/AbuSalehFaysal
π Abu Saleh Faysalβs Blog: https://abusalehfaysal.hashnode.dev/
π Hasnode: https://hashnode.com/@AbuSalehFaysal
π Dev Community: https://dev.to/abusalehfaysal
π freeCodeCamp: https://www.freecodecamp.org/abusalehfaysal
π Medium: https://abusalehfaysal.medium.com/
π GitHub: https://github.com/AbuSalehFaysal
π GitLab: https://gitlab.com/AbuSalehFaysal
Top comments (0)