My first tech interview is a DISASTER but I learned…

My face after the interview☝

QUESTION

   def movie_time_equals_flight_time(movies, flight_length)       movies.each_with_index do |m1, i|          movies.each_with_index do |m2, j|           target = flight_length - m1

# looking for the target in the rest of the array
if m2 == target && i != j
return true end
end
false end
  1. Start from movie[0]
  2. Get the total of movie[0]+movie[1]
  3. Compare the total to flight_length
  4. If they are equal, return true, if not, get the total of movie[0]+movie[2], and compare that with flight_length and decide if it should return true or do the loop again.
  5. Leave the inner loop when there is no element in the movie array adding movie[0] equal the flight_length.
  6. Start from movie[1] and go back to step 2 to find out if any element adding movie[1] will equal to flight_length.
def movie_time_equals_flight_time(movies, flight_length)   movie_hash = {}   movies.each_with_index do |m, i|     movie_hash[m] = i   end
movies.each_with_index do |m, i| target = flight_length - m # looking for the target in the rest of the array if movie_hash[target] && movie_hash[target] != i return true end end falseend

My Future Plan

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store