Disclaimer
As a senior software engineer, here is my egoistic view of this. I do claim it is correct or what I say are facts. You have free will to interpret this as any way you want.
Preamble
A typical candidate has an inadequate set of skills for any available position. Therefore usually for first several months, he/she is put on tasks to develop themselves and might be producing company net loss. You have to make an estimation how long would it take for this person to acquire required set of skills.
This is a simple brain teaser, you could ask from an entry level candidate. It gives an estimation of what their cognitive dissonance is like. The basic idea is if you are good/great at processing problems your knowledge base inadequacy can be overlooked.
What would I look for when asking this question
- did (s)he consider problems "solved" after finding a first working solution
- did (s)he consider that "add" can have different meanings
- did (s)he consider that "numbers" can have different contexts
I mentioned "good/great at processing problems", it is not the same as solving the problem. If the person failed you want to see how did (s)he respond to failure.
Introduction
+80% of software solution cost comes from maintenance after its development has ended. A typical enterprise code is read x10 times more than it is written. The best way to reduce the total cost is to write "clean code".
One aspect of writing "clean code" is to name things correctly. One of the simplest cases to demonstrate wording ambiguity is "add". Here are few different meanings of add (there are a lot more):
(you add 2 values)
1 + 1 = 2
(you add a value to each list value)
{a, b, c} + 1 = {a + 1, b + 1, c + 1}
(you add a value to start of the list)
Prepend[{a, b, c}, 1] = {1, a, b, c}
(you add a value to end of the list)
Append[{a, b, c}, 1] = {a, b, c, 1}
(you add a value to list at specified index position starting from the beginning)
Insert[{a, b, c}, 1, i] ex: {1, a, b, c} if i = 1
(you add a value to list at specified index position starting from the end)
Insert[{a, b, c}, 1, -i] ex: {a, b, c, 1} if i = 1
(you add a set of lists)
Join[{a, b, c}, {x, y}] = {a, b, c, x, y}
(you add a set of lists without duplicates)
Union[{a, b, c}, {c, a, d}] = {a, b, c, d}
In c# .net a list has a method Add for adding a single element and AddRange to add multiple elements. A single method would cause ambiguous meaning and would not be as clean.
When you implement a code on a 32bit architecture computer, there is a hardware support for bit 32-bit sequences and their basic arithmetics and logics. An integer of type int32 is implemented with 32 bits, it represents a discrete number having max value 2^31-1 and min value -2^31.
Solutions
Code examples in c# .net.
Contains spoilers.
Octo
I am not sure why his answer is voted down - it is correct.
1 baker's dozen = 13
2 baker's dozen = 26 (22 + 4)
Code :
const int BakersDozen = 13;
Value : Shows domain knowledge
manshu
Code :
public static int operator +(Manshu firstNumber, Manshu secondNumber)
=> (firstNumber + secondNumber).ToString().Count();
Value : Knows basic data types
CodeNewbie
Following code example hides (int)(22 / 10 + 4 / 10) to be 22 + 4
Code :
public static int operator +(CodeNewbie firstNumber, CodeNewbie secondNumber)
=> firstNumber / 10 + secondNumber / 10;
Value : Knows data types / operators and maybe some functional programming
Oleg
Code :
public static int operator +(Oleg firstNumber, Oleg secondNumber)
=> firstNumber > secondNumber ? firstNumber + secondNumber : 2;
Value : Knows about default fallbacks
Job
KoA and Menace are just sub cases of Job's general solution.
Code :
public static int operator +(Job firstNumber, Job secondNumber)
=> (firstNumber + secondNumber) % 24;
Value : Shows basic cryptography domain knowledge
Me
List that contains 22 and you add 4, now you have list containing 2 elements.
Code:
var items = new List<int> { 22 };
items.Add(4);
Value: Ability to read the question
Conclusion
A brain teasers during a job interviews can have valid uses. From my experience it is usually just a filler to engage the applicant.