Wayfair Interview Question

Given an option between writing a SQL query and a general coding challenge. Chose general coding challenge which was to write a function where given an array of integers representing coin flips (0 or 1 for Heads or Tails), return the fewest number of coins that would have to be flipped for all coins to show the same (all heads or all tails).

Interview Answer

Anonymous

Apr 19, 2019

Wrote a for loop counting total heads and total tails, and returned the smaller number as the number of coins to be flipped over. For instance, if there were 10 coins flipped, with 7 heads and 3 tails, the function would return 3, since the 3 tails would need to be flipped to heads for all 10 coins to be the same.

3