5

Algolia Coding Challenge: Find out the solutions 🔎

 2 years ago
source link: https://www.algolia.com/blog/engineering/algolia-coding-challenge-find-out-the-solutions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Thanks to all of those that helped Santa by participating in our ❄️  2021 Coding Challenge ❄️  for the Holiday season!

Congratulations to everyone who submitted answers, but especially to our prize winner – Ruben Quintero! 🥳

For the rest of this post, I’ll be walking through solutions for each of the challenges using Ruben’s repositories as examples.

Let’s get started!

Challenge #1 🎤

Santa is a huge Star Trek fan. He remembers his favorite Star Trek actor once gave a Ted talk with an inspiring rating between 800 and 900 that was tagged storytelling.

What is the name of the speaker, (who is also a famous Star Trek actor), that Santa is going to visit?

The Ted Talks data set has several interesting attributes for faceting. The trick here is choosing which ones to facet (tags and inspiring_rating).

For this solution, Ruben uses the InstantSearch library for vanilla JS. A searchable RefinementList allows Santa to find the “storyteller” tag while a RangeInput filter allows him to set the appropriate range for the insipiring_rating.

We narrow the search down to two records, one of which is George Takei, who was an actor on the original Star Trek series (hurray for Sulu!).

Bonus Question

What is the most viewed TED Talk tagged for both collaboration and society?

 “How to spot a liar”

Challenge #2 📽

As he prepares for his trip Santa remembers that little Bryan, one of the children on his “nice” list, has asked for a movie that stars both the actor he plans to visit and the actress Amy Poehler. Santa needs another search interface to find the title of this movie (and when it was released).

What is the title and release year of the movie that Bryan wants for Christmas? (Submit via Form)

The Movies data set is too large for the Algolia free tier, so we need to use a hosted version. It’s important to remember that much of the configuration around faceting and relevance occurs within the index itself, not in the query. Since we don’t manage this index, we need to use the facets and searchable attributes as configured.

For this solution, Ruben again uses a searchable RefinementList for actors. This makes it very easy to find the movie “Free Birds” released in 2013. Ruben adds a RefinementList for genres and a Menu of release years to solve the bonus question.

Bonus Question

What is the title and score of the highest rated movie with the genre Crime released in 2008? 

7.88854034451496 for “The Dark Knight”

Challenge #3 🍷

What is the name of the Bordeaux wine from the Fronsac domain released in the same year as the movie in Challenge #2?

We start with the Wine data set, which suffers from some duplicate record issues. Each wine is in the data set 16 times! As Bryan and I discovered doing this challenge live, we need to de-dupe the data as we import it into the index.

Once the data is normalized, we just need to add a couple of RefinementLists for year and domain to discover the only wine from the Fronsac region bottled in 2013 is Chateau Vrai Canon Bouche.

Bonus Question

What was the highest rated wine under $30 from 2010?

Chateau Ferran

Challenge #4 🛩

Wine in hand, Santa is ready to start his journey. But where? He knows his favorite Star Trek actor recently made the following flights:

  • ATL → SEA
  • AHN → LGA
  • JFK → MCN

What is the major US city closest to all three flights listed above?

For this challenge, we use the Airports data set, but we need to combine it with map data to answer the question. Ruben chose to use the InstantSearch geoSearch widget. This widget uses the Google Maps APIs to render map data. But we can also use a custom connector for other mapping APIs.

Filtering on the airport codes above, we discover that although there are two well-known airports near New York City (LGA and JFK), there are actually three airports near Atlanta, GA (ATL, AHN, and MCN) making that the best answer.

Bonus Question

What is the closest airport to Carson National Forest in the United States?

Los Alamos Airport (LAM)

Challenge #5 🎸

Santa remembers another gift he still needs to pick up for a girl on his “nice” list. All little Julie wanted for Christmas were tickets to see the musician that played in that same city sometime between August 14 and August 18, 2019.

What was the name of the artist Julie wants to see for Christmas?

The Concert data set is again too large for the Algolia free tier, so we need to use the hosted version. This challenge is all about dates. As Bryan and I discovered in our live coding session, dates are hard.

Algolia indices store dates as Unix timestamps for filtering and ranking. We need to build an interface that makes it easier for humans to deal with these dates. We chose to use a date range picker from the Algolia Code Exchange. From there, it was just a few filters to find out the artist was Grimes playing at Cellairis Amphitheatre at Lakewood, Atlanta, GA.

Bonus Question

What was the last city where the band Coldplay performed in 2018?

Paris, France

Conclusion 🎄

Thanks to all of the amazing participants in the winter Coding Challenge. We’ll be keeping the Discord server up, so let us know if you want access. Even though the contest is over, these are still fun challenges to try to build on your own.

Happy holidays from all of us at Algolia and we’ll see you in the New Year! 🎊

Check out related solutions on our open source code exchange platform.

CodeX@2x.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK