Evaluating Hackerrank for Tech Hiring

We were looking at Hackerrank to see if they can help us with alleviating some of the interview and review load on our senior developers.

Some observations:

I tried the questions for myself, with the time limit and all, to find out what kind of experiences the possible applicants would have. I was not able to finish all 4 questions within 30 minutes as I was doing TDD, and had to figure out that I had to send my output to STDOUT for the checker to confirm my answers. I did eventually find out that the last two questions were actually SQL questions, which would have probably taken me around 10 to 15 minutes tops.

I’m not allowed to reproduce the questions, so I’m just pasting here my answers :P

def lastLetter(word)
  word = word.strip
  last_two_letters = get_last_two_letters(word)
  reversed = last_two_letters.reverse
  result = reversed.split("").join(" ")
  puts result
  result
end

def get_last_two_letters(word)
  word[word.length - 2, word.length]
end

# require "rspec"
# require "rspec-given"

# describe "lastLetter" do
#   Given(:word) { "APPLE" }
#   context "getting the last two letters" do
#     When(:last_two_letters) { get_last_two_letters(word) }
#     Then { last_two_letters == "LE" }
#   end
  
#   context "getting the result" do
#     When(:result) { lastLetter(word) }
#     Then { result == "E L"}
#   end

#   context "edge cases" do
#     context "1 character long" do
#       Given(:word) { "a" }
#       When(:result) { lastLetter(word) }
#       Then { result == "a"}
#     end

#     context "last character is a space" do
#       Given(:word) { "a " }
#       When(:result) { lastLetter(word) }
#       Then { result == "a"}
#     end
#   end

# end
def solvePuzzle(num)
  num = num.to_s
  result = num.split("").reduce(0) { |sum, num| sum + get_num_holes(num.to_i) }
  puts result
  result
end

def get_num_holes(num)
  return 0 if [1, 2, 3, 5, 7].include?(num)
  return 1 if [0, 4, 6, 9].include?(num)
  return 2 if [8].include?(num)
end

# require "rspec"
# require "rspec-given"

# describe "number of holes" do
#   context "solution" do
#     Given(:num) { "9899" }
#     When(:result) { solvePuzzle(num) }
#     Then { result == 5 }
#   end

#   context "zero hole" do
#     context do
#       Given(:number) { 1 }
#       When(:num_holes) { get_num_holes(number) }
#       Then { num_holes == 0 }
#     end
#     context do
#       Given(:number) { 2 }
#       When(:num_holes) { get_num_holes(number) }
#       Then { num_holes == 0 }
#     end
#   end

#   context "one hole" do
#     context do
#       Given(:number) { 0 }
#       When(:num_holes) { get_num_holes(number) }
#       Then { num_holes == 1 }
#     end
#     context do
#       Given(:number) { 4 }
#       When(:num_holes) { get_num_holes(number) }
#       Then { num_holes == 1 }
#     end
#   end
# end

Comments

comments powered by Disqus