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.
In this approach we are iterating array with two loops where we are checking sum of first and next element with target if it matches then we are returning index of element. But in this case Time complexity will be O(N²)
2.Map based Approach
In Nutshell, We can utilize a HashTable to search for the required elements with pair.
Top comments (0)