Wayfair Interview Questions

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-11-08Added By Anonymous
Source: Link

There were 3 questions in the interview, basic, intermediate and advanced


1) Basic

This one was to find pairs with target difference in an array.

[1, 2, 3, 4, 5]

target = 2

output = 3

I solved it by making a dictionary of counts of numbers and then added the target to each element of array to check if it exists in the dictionary and returned the result of the summation of counts of exisiting arrays


2) Intermediate

It was a subsequence question in which we had to find minimum sum subsequence such that

sub[0] < sub[1] > sub[2] in all len = 3 subsequences

I could not find the optimal solution for this, I tried creating an array of all subsequences of length 3 and traverese through them to find the one with the minimum sum but kept reaching recursion depth passed like half the test cases


3) Advanced

We are given 3 integers n, m and totalCost

totalCost is the number of swaps that happen during linear search of maximum number in array\

1x = arr[0] 2totalCost = 0 3for i in range(len(arr)): 4 if arr[i] > x: 5 x = arr[i] 6 totalCost += 1

we had to find number of arrays of totalCost equal to the given totalCost such that

each array is of length n

and arr[i] <= m where i is from 0 to n

arr[i] ∈ ℕ


I tried creating all possibilites and then storing in an array to calculate total cost and return answer but I couldnt even pass a single test case as I didnt leave myself enought time for the last test case.

I dont think I will be selected this time but if someone could help me solve these so that I wont mess up like this again it would be really nice.

Comments