Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What makes for a good onsite coding exercise?

Claudio B.
December 12, 2019

What makes for a good onsite coding exercise?

Claudio B.

December 12, 2019
Tweet

More Decks by Claudio B.

Other Decks in Technology

Transcript

  1. 1. Checklist: is your exercise “good”? 2. Example: the Retail

    Round exercise 3. Lessons learned from 80 attempts (10 min) (5 min) (10 min) What makes for a good onsite coding exercise? What makes for a good onsite coding exercise?
  2. • Contextual • Conversational • Impartial Checklist: is your exercise

    “good”? What makes for a good onsite coding exercise?
  3. • Contextual • Conversational • Impartial Checklist: is your exercise

    “good”? What makes for a good onsite coding exercise? Keep it pertinent to the job Don’t copy from online libraries Take notes in your daily routine
  4. • Contextual • Conversational • Impartial Checklist: is your exercise

    “good”? What makes for a good onsite coding exercise? Keep it short Observe the candidate Allow for additional steps
  5. • Contextual • Conversational • Impartial Checklist: is your exercise

    “good”? What makes for a good onsite coding exercise? Keep a scoring rubric Restrict to the same duration Accept any programming language
  6. • Contextual • Conversational • Impartial Checklist: is your exercise

    “good”? What makes for a good onsite coding exercise?
  7. Clutter is considering charging customers for materials. We estimate the

    cost will be 40% of the chosen plan. E.g., for a Garage Plan ($30), the price of materials we intend to charge will be $12. For marketing purposes, we would like to round the price of materials to the closest integer amount that either ends with a 4 or with a 9. In other words, rather than $12 we would charge $14. Here are more examples: How would you implement such a method? You can use any programming language. $8 becomes $9 $9 becomes $9 $10 becomes $9 $11 becomes $9 $12 becomes $14 $13 becomes $14 $14 becomes $14 $15 becomes $14 The Retail Round exercise What makes for a good onsite coding exercise?
  8. Clutter is considering charging customers for materials. We estimate the

    cost will be 40% of the chosen plan. E.g., for a Garage Plan ($30), the price of materials we intend to charge will be $12. For marketing purposes, we would like to round the price of materials to the closest integer amount that either ends with a 4 or with a 9. In other words, rather than $12 we would charge $14. Here are more examples: How would you implement such a method? You can use any programming language. $8 becomes $9 $9 becomes $9 $10 becomes $9 $11 becomes $9 $12 becomes $14 $13 becomes $14 $14 becomes $14 $15 becomes $14 The Retail Round exercise is contextual What makes for a good onsite coding exercise?
  9. Clutter is considering charging customers for materials. We estimate the

    cost will be 40% of the chosen plan. E.g., for a Garage Plan ($30), the price of materials we intend to charge will be $12. For marketing purposes, we would like to round the price of materials to the closest integer amount that either ends with a 4 or with a 9. In other words, rather than $12 we would charge $14. Here are more examples: How would you implement such a method? You can use any programming language. $8 becomes $9 $9 becomes $9 $10 becomes $9 $11 becomes $9 $12 becomes $14 $13 becomes $14 $14 becomes $14 $15 becomes $14 The Retail Round exercise is conversational What makes for a good onsite coding exercise?
  10. Clutter is considering charging customers for materials. We estimate the

    cost will be 40% of the chosen plan. E.g., for a Garage Plan ($30), the price of materials we intend to charge will be $12. For marketing purposes, we would like to round the price of materials to the closest integer amount that either ends with a 4 or with a 9. In other words, rather than $12 we would charge $14. Here is my scoring rubric (out of 10 points): • 5 points for any working solution • 1 point for good data structures • 1 point for additional cases (float input) • 1 point for proving the solution is correct • 1 point for readability (variable names, …) • 1 point for extra coding skills (no copy/paste, fast typing, keyboard shortcuts, finger position) The Retail Round exercise is impartial What makes for a good onsite coding exercise?
  11. Lessons learned from 80 attempts What makes for a good

    onsite coding exercise? • Can be solved • Often in Python • Five major approaches 90% found a working solution [A] [B] [C] [D] [E] 45% Python JS Java Ruby …
  12. public static int round(double price) { int upper = (int)

    (price) + 1; int lower = (int) price; while (upper % 10 != 4 && upper % 10 != 9) upper++; while (lower % 10 != 4 && lower % 10 != 9) lower--; if (Math.abs(price - lower) <= Math.abs(price - upper)) return lower; else return upper; } for (int i = 8; i <= 15; i++) System.out.println(round(i)); Approach A: increment/decrement What makes for a good onsite coding exercise?
  13. const roundMaterialPrice = (price) => { let fourLow = Math.floor(price

    - 10) - (price % 10) + 4; let fourHigh = Number(Math.floor(price / 10) + "0") + 4; let four = (fourHigh - price) > (price - fourLow) ? fourLow : fourHigh; let nineLow = Math.floor(price - 10) - (Math.floor(price) % 10) + 9; let nineHigh = Number(Math.floor(price / 10) + "0") + 9; let nine = (nineHigh - price) > (price - nineLow) ? nineLow : nineHigh; return Math.abs(price - nine) > Math.abs(price - four) ? four : nine; } console.log(roundMaterialPrice(8)) console.log(roundMaterialPrice(9)) […] Approach B: distance to closest 4 or 9 What makes for a good onsite coding exercise?
  14. def charge_price(price): last_digit = price % 10 closest_ten = price

    - last_digit if 1.5 <= last_digit <= 6.5: closest_ten += 4 elif 0 <= last_digit < 1.5: closest_ten -= 1 else: closest_ten += 9 return int(closest_ten) for i in range(8, 16): print(charge_price(i)) assert(charge_price(11.2) == 9) Approach C: range of the last digit What makes for a good onsite coding exercise?
  15. @calculations = { 0 => -1, 1 => -2, 2

    => 2, 3 => 1, 4 => 0, 5 => -1, 6 => -2, 7 => 2, 8 => 1, 9 => 0 } def estimate(price) last_digit = price.round % 10 return price + @calculations[last_digit] end puts estimate(8) assertEquals(estimate(12.2), 14.2) Approach D: hash table for the last digit What makes for a good onsite coding exercise?
  16. def materials_cost(plan_cost) base = plan_cost * 0.4 marketing_round(base) end def

    marketing_round(cost) ((cost + 1) * 2).round(-1) / 2 - 1 end (8..15).each do |i| puts "#{i}\t#{marketing_round(i)}" end puts marketing_round(11.2) Approach E: mathematical round What makes for a good onsite coding exercise?