This was an OA on HackerRank. I'm writing up the question types for everyone's reference.
There were 5 questions in total, a mix of algorithms, React debugging, prompt writing and basic multiple choice.
1. Minimum number of operations on an array
You get a permutation of 1 to n and need to turn it into ascending order. You can rotate it left by one position, or swap any two elements, but once you start swapping you can't rotate anymore.
My approach was to enumerate the number of left rotations, then use permutation cycles to compute the minimum number of swaps needed for the rest, and take the smallest total number of operations. n is at most 1000, so an O(n²) solution works.
2. React contact book debugging
They give you three existing components, App, AddPerson and ListPeople, and you have to fix the add-contact and live-display features.
Name, phone and email can't be empty, the phone has to be 10 digits, and the input types are text, number and email respectively. It mainly tests form submission, passing parameters through parent-child callbacks, state updates and passing props. The task says to keep the existing attributes such as data-testid.
3. Writing a prompt
Extract the name, transaction amount, last four digits of the credit card and transaction date from a customer email, and output one line of comma-separated results, with the date normalized to YYYY-MM-DD.
Some inputs are a whole chain of emails where the information is spread across the original email and the later replies, so you have to merge it, and you also have to tell the customer's name apart from the support agent's name. The
{testcase input}
in the editor has to be kept.
4. Time complexity multiple choice
Three nested loops: the outer i goes from 1 to n, the middle j increases by i each time, and the inner k increases by 2 each time. Working it out with the harmonic series, the answer is O(n² log n).
5. Hash table multiple choice
A hash table of size 7 with hash function (3x + 4) % 7, inserting 1, 3, 8, 10 in that order, with collisions resolved by linear probing. The final result is
[1, 8, 10, empty, empty, empty, 3]
.
Overall the question types are pretty mixed. Besides algorithms, they also test front-end debugging and basic prompt writing. Good luck with your OA, everyone!
Discussion
Loading comments…