Facebook | Phone screen | Count subsets
Company: Facebook
Role: e3, e4
Interview Stage: Phone Screen
Location: Menlo Park, CA
Year: unknown
Original Post Content:
Recruiter contacted me, and asked for availability in next 4 days.
Status: Working as a Software Engineer in New Jersey
Position: Software Engineer
Location: Menlo Park, CA
Technical Phone Screen - I
Subsets
/*question:
Input:
Given an array A of
-positive
-sorted
-no duplicate
-integer
A positive integer k
Output:
Count of all such subsets of A,
Such that for any such subset S,
Min(S) + Max(S) = k
subset should contain at least two elements
1. Backtracking approach to get subsets
2. Get min and max of subset
3. Add min and max and put them in Hashmap (or update the count)
4. repeat this process for all subsets
5. search for k in hashmap and return count of k
input: {1,2,3,4,5}
subsets:
1, 2, 3, 4, 5, {1,2},{1,3}
k = 5
count = 5
{1, 4},{2,3} {1,2,4}, {1,2,3,4} {1,3,4}
*/
(Discuss the time and space complexity)