-
Brute force solution
twoSumExpensive
. Select every element and find the remainder after that iterate over the array to check if remainder exists in the remaining array or note. -
Better solution using the Hash table. Iterate over all elements and check if the remainder is present in hash table or not if not set the number and it's index using
map[nums[i]] = i
// https://leetcode.com/problems/two-sum/
// https://www.youtube.com/watch?v=dRUpbt8vHpo&list=PLgUwDviBIf0rVwua0kKYlsS_ik_1lyVK_&index=2
#include<iostream>