Count islands and distinct shapes | LinkedIn Coding Question