Two Sum (C)
Topics: arrays, search
Problem
bool two_sum(const int *nums, size_t n, int target, int *i_out, int *j_out);
Find two distinct indices i < j with nums[i] + nums[j] == target; write them out and return true,
else false. The O(n^2) scan shown here is the simplest; the classic O(n) approach trades space for a
hash map of value->index.
Run: cc -std=c11 -O2 -Wall tests.c -o /tmp/t && /tmp/t
Sign in to submit your solution.