Today I was asked a very simple questions to code for but I couldn't.
None of these, should take more than 20 mins but I couldn't do that in 70 mins even.
Giving here my answers which I was able to write in few minutes after the interview.
Please provide your comments & improvements to be made-
Question 1 : Create own Custom Llinked List class to add items & print those items.
Question 2 : Then I was asked to write a delete method to delete the first element in the list
and later print the contents.
None of these, should take more than 20 mins but I couldn't do that in 70 mins even.
Giving here my answers which I was able to write in few minutes after the interview.
Please provide your comments & improvements to be made-
Question 1 : Create own Custom Llinked List class to add items & print those items.
Question 2 : Then I was asked to write a delete method to delete the first element in the list
and later print the contents.
Linked List
Question 3 : Next question was to find if the given linked list is Palindrome.
Here, I assumed that I need to use my custom Linked List & I was not able to code properly, as I was not able to think about the break condition.
But after interview I did that and wrote below code with changes like you can convert the LinkedList behavior from FIFO to LIFO in single switch-
Here, I assumed that I need to use my custom Linked List & I was not able to code properly, as I was not able to think about the break condition.
But after interview I did that and wrote below code with changes like you can convert the LinkedList behavior from FIFO to LIFO in single switch-
Custom Linked List
Question 4 : Is the above List is thread safe? If not, then make it thread safe.
I made add() & removeFirst() methods as syncronized, but you can decide what fits your case.
I made add() & removeFirst() methods as syncronized, but you can decide what fits your case.