Lesson Thursday

Whiteboard Practice


When and how whiteboarding practice is implemented will be up to your teacher. Below is a recommended prompt.

Goal

For this course section's whiteboarding lesson, we’ll focus on arrays, looping, and using basic Ruby operators.

As the interviewee:

  • Ask clarifying questions.
  • Keep talking.
  • Explain your plan at the beginning; recap what you’ve done at the end.
  • Make eye contact.
  • Plan your space.

As the interviewer:

  • Answer questions as best as you can.
  • Be encouraging. Whiteboarding is difficult!
  • Be patient. Only offer hints if your partner indicates that they need help.
  • Be engaged. Part of this practice is getting used to having someone evaluate your work as your produce it.
  • Offer constructive feedback. Find at least one thing that your partner did well and one thing they could improve at.

Problem

Prompt: Write a method that takes in two arrays of integers. The method should sum the value of the integers in both arrays and calculate the average (mean) value of the integers. The method should return this value as an integer. The method should handle arrays that contain negative and non-negative integers.

Example:

  • Given: [5, 1, 4,-9,3], [2,4,-2]
  • Output: 1

Additional Information:

  • When division between two integers results in a fraction, the decimal value is truncated, not rounded. For this problem, it’s fine to use this value even though it might not be the exact average. If you would like to make this problem more challenging, try returning the rounded average. Below is a few examples highlighting truncation:

    • 5/2 = 2 // not 2.5
    • 8/3 = 2 // not 2.66666666
    • 5/4 = 1 // not 1.25

Further Exploration

  • Modify your method such that it computes the average of the integers contained in an arbitrary number of integer arrays. Your method should accept an array of integer arrays and should return one integer.
  • Modify your method such that it finds the mode (most common integer in a set of integers) of the integers in the arrays. Your method should return a Dictionary with the strings mean and mode as its two keys, and the appropriate integers as their values.
  • Modify your method such that it finds the median (middle index) of the integers in the arrays. This means that you’ll need to sort the integers. You should create a helper method to do this.

Lesson 36 of 37
Last updated July 28, 2022