Ruby Algorithm Questions For Beginners

3 algorithm questions you may be asked in Ruby interviews

GreekDataGuy
Ruby Daily
Published in
4 min readOct 28, 2020

--

Photo by Christina Morillo from Pexels

I previously wrote about beginner algorithm questions in Python. This article converts those questions to Ruby.

Developers hate algorithm questions.

But they’re a reality. Even for those of us who’ve been shipping production code for years.

If you’re just beginning, they can be overwhelming. So it’s best to start easy and build your confidence.

Let’s do a few beginner questions.

Question 1: FizzBuzz

The classic FizzBuzz question. Though I’ve never been asked it in an actual interview, it’s about as easy as algorithm questions get.

Instructions:

  1. Given n, return a list of all integers from 1 through n.
  2. If an integer is divisible by 3, return “Fizz” instead of the integer.
  3. If an integer is divisible by 5, return “Buzz” instead of the integer.
  4. If an integer is divisible by 3 and 5, return “FizzBuzz” instead of the integer.

Code:

Copy/paste this into your favorite code editor, and fill in the method to return the desired solution.

--

--

GreekDataGuy
Ruby Daily

Just a developer. Contact: greek.data.guy “at” gmail.com