Got these tests from recent interviews and thought it to share with everyone to once in a while measure your PHP skill level.
1. Check if Parentheses, Brackets and Braces Are Balanced. It's better to use Stacks method but use your own if you must.
'{{}}' = Pass
'[]}{{}}' = Fail
'[[{]{{}}' = Fail
'[]()(' = 1x open parenthesis/bracket/curly brace
'[]({{{{{{{{{{{{{{{{{}}}}}}}}}})' = Too many open
2. Unique names
$names = unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']);
// should print Emma, Olivia, Ava, Sophia
function unique_names(array $array1, array $array2) : array
{
//todo: your code here
}
3. Find the roots in any order
For example: findRoots(4, 12, 8); //[-1,-2] or [-2,-1]
root formula
@return array An array of two elements containing roots in any order
function findRoots($a, $b, $c)
{
//todo: your code here
}
4. Fibonacci Sequence
Write a code that will get the Fibonacci sequence number starting from #1 up to n numbers.
should print:
1 1 2 3 5 8 13....n
Post your code in the comments.
Top comments (0)