Interview Questions

  • View all interview questions
  • blank
  • Lucky sevens
    A user who was applying to App Academy posted this question on Coderbyte:
    Write a function called lucky_sevens which takes an array of integers and returns true if any three consecutive elements sum to 7.
    To solve this challenge we'll simply loop through the array starting at the 3rd position, and checking if the number at this index plus the two previous elements sums to 7. We continue doing this as we loop through the entire array. Once we find three elements that sum to 7, we simply return true. If we reach the end of the array without finding elements that sum to 7, we return false. Below is some code in JavaScript and Python with step-by-step comments.

    Sources

    https://coderbyte.com/question/app-academy-practice-questions-help http://prepwork.appacademy.io/coding-test-1/practice-coding-exercise/


    You need to be a premium member to see the rest of this question and code.

    Become a Premium Member

    With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

    “I have my final coding interview with Fullstack Academy tomorrow, and Coderbyte has been an invaluable tool to help me progress as a
    developer.” ― Josh Aharonoff
    • 200+ Coding Challenges
    • Mock Interview Questions
    • 500,000+ Code Solutions
    • Algorithm Tutorials
    • Interview Prep Courses
    mrdaniel published this on 12/4/15 | javascript, bootcamp, array, App Academy, Fullstack Academy, Hack Reactor
    Comments
  • +
  • 6
  • -
  • don't listen to Anhtaihuman... we're not talking about whether three consecutive integers are 7, we are talking about whether they sum to 7. Your function should have returned true since 1 + 5 + 1 === 7
  • +
  • 0
  • -
  • nvm i got it
  • +
  • 0
  • -
  • I'm running the same code as mrdaniel and everything but i get false when calling 1,5,1 even with your code. What am i doing wrong? This is on Atom.
  • +
  • -14
  • -
  • A simpler way to do this would be to use RegEx.
    function lucky_sevens(arr) {
      return /777/g.test(arr.join(''));
    }
    
    lucky_sevens([2, 1, 5, 1, 0, 7, 7, 0, 7]);
    Login to submit a comment