Technical interview test
In this test we want to have a conversation with the potential hire around code. This is a live coding test. We have 60 minutes scheduled, 30-45 minutes should be coding and the rest will be general conversation about the test or anything else that might arise.
struct Person {
let name: String
var children: [Person] = []
}
let peoples = [
Person(name: "Mary",
children: [Person(name: "Roi",
children: [
Person(name: "Ali", children: [Person(name: "Chip")]),
Person(name: "Rudolf", children: [Person(name: "Judith"), Person(name: "Christine")])
]
),
Person(name: "Aaron", children: [Person(name: "Mohamed")])
]),
Person(name: "Eve", children: [Person(name: "Ryan")])
]
let expectedString =
"""
|--Mary
| |--Roi
| | |--Ali
| | | |--Chip
| | |--Rudolf
| | | |--Judith
| | | |--Christine
| |--Aaron
| | |--Mohamed
|--Eve
| |--Ryan
"""
if result == expectedString {
print("Perfect")
} else {
print(result)
}
What to look for in the interview process in general:
- The planning phase before writing code
- Does the candidate verbalize the thinking process
- The time is takes to complete. It needs to be under 30 minutes.
- The code quality
- If the thinking process clear?
- Does the candidate ask questions?
- Does the candidate have a good understanding of the problem?
- Does the candidate get stuck? This is not a good sign.
We should not influence the candidate in any way, we want to leave him/her to think and code on their own. We should not give hints or help. If we need to help it’s a weakness sign
This is the Kotlin equivalent:
fun main(args: Array<String>) {
val persons = listOf(
Person("Mary", children = listOf(
Person("Roi", children = listOf(
Person("Ali", children = listOf(Person("Chip"))),
Person("Rudolf", children = listOf(Person("Judith"), Person("Christine")))
)),
Person("Aaron", children = listOf(Person("Mohammed")))
)),
Person("Eve", children = listOf(Person("Michael")))
)
val expectedString = """|--Mary
| |--Roi
| | |--Ali
| | | |--Chip
| | |--Rudolf
| | | |--Judith
| | | |--Christine
| |--Aaron
| | |--Mohammed
|--Eve
| |--Michael"""
val result = printPersonTree(persons)
if (result == expectedString) {
println("Perfect")
} else {
println(result)
}
}
data class Person(val name: String, val children: List<Person> = emptyList())
fun printPersonTree(persons: List<Person>, level: Int = 0, first: Boolean = true) : String {
val sb = StringBuilder()
for ((index, person) in persons.withIndex()) {
if(!first || index > 0){
sb.append("\n")
}
sb.append("| ".repeat(level))
.append("|--")
.append(person.name)
sb.append(printPersonTree(person.children, level + 1, false))
}
return sb.toString()
}