Basic algorithm problem and their solutions
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
- Time Complexity: O(n). I visit the n elements of the array only once.
- Space Complexity: O(2n). I store at most all the elements of the array and corresponding positions.
g++ source_codes/two_sum.cpp
Count the number of prime numbers less than a non-negative number, n.
SCHEMA A FAIRE
- Time Complexity: O(n log n). I visit each odd below n and remove multiples.
- Space Complexity: O(n). I store at most n elements true/false is a prime number condition.
g++ source_codes/count_primes.cpp