Phone screens were mostly about prior experience, with two technical questions. Then they sent me a programming assignment, which I apparently got wrong.
I suggest using STL or some other advanced library. Without context of where the code will run and what the constraints are, it is hard to offer the right solutions or "fit".
Here is the actual test:
-------------
Please complete the two programming questions below. You can use any IDE you'd like as long as it is written in C or C++ code.
We are looking for correctness and creativity. Impress us with your ability to optimize for memory usage and/or speed. Please comment on your design choices, any tradeoffs you make, as well as memory requirements and run time complexity.
You will have 2 hours to complete the questions. Good luck!
1.
Permutations of a string are defined to be all possible orderings of the characters within the string. For example, the string "cat" has the following permutations:
{ "cat", "cta","atc","act","tca","tac" }.
Write an efficient C/C++ function, generate_permutations(), that will generate all the permutations of a given string. This program is expected to be invoked with the input string as the only parameter and expected to output the results to the standard output.
Assumption : If the characters in the string are duplicated, some permutations will be identical, however they are still listed out. For example, "all" will generate the following permutations: { "all","all","lal","lal","lla","lla" }.
Function prototype : void generate_permuations(const char* input_string)
Test run : Please generate an output for the word “Eyjafjallajokull” (without the double quotes).
1a.
Without actually coding the changes, explain how you would modify the above program to print out only the unique strings.
For example, "all" would generate only { "all","lal","lla" }.
2.
A game of Tic Tac Toe has just been completed. Write a function that prints whether X's or O's have won. The game board is passed in as an array of integers in row-column order. The Number 2 represents X and the number 1 represents O. A zero represents that the space is empty.
For example the gameboard below would be represented as int* gameboard = [2,0,1,1,1,0,2,2,2]
x - - o
------------------
o - o -
------------------
x - x - x
Function Prototype: void tic_tac_toe(int* gameboard)