Exercise Wednesday

Whiteboard Practice


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

Goal

For this section's whiteboarding lesson, we’ll continue to practice with arrays, looping, and using C#'s basic 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

1st Prompt: Write a method that returns a boolean indicating whether a number is prime. Recall that a number is prime if it is greater than 1 and is not evenly divisible by any other numbers excepting 1 and itself.

Examples:

  • Given: 7, Output: true

  • Given: 2, Output: true

  • Given: 8, Output: false

2nd Prompt: Write a method that returns an array of all of the multiples for a given number. A multiple of a given number is a number that can be multiplied by a second number to make the given number.

Examples:

  • Given: 7, Output: [ 1, 7 ]

  • Given: 24, Output: [ 1, 2, 3, 4, 6, 8, 12, 24 ]

Further Exploration

  • Write a method that returns an array of all the prime numbers that are less than a given number.

    • Examples:
      • Given: 7, Output: [ 2, 3, 5 ]
      • Given: 2, Output: [ ]
  • Write a method that returns the greatest common multiple (GCM) for two given numbers. The GCM is the largest number that both given numbers are evenly divisible by.

    • Examples:
      • Given: 24, 18, Output: 6
      • Given: 50, 8, Output: 2
      • Given: 25, 5, Output: 5

Lesson 4 of 6
Last updated more than 3 months ago.