Tuesday, November 7, 2017

Divide to n small linked list with length difference at most one

Nov. 7, 2017

Introduction


It is the first time I went through a friend met in mock interview, we both worked on the same algorithm together. I wrote two version of code, one is recursive function, one is iterative one.

Problem statement can be written in the following:

Given a Linked list, split it into x number of smaller linked list where the size difference between any two list should be at most 1


Algorithm practice


It is so interesting to have discussion with the peer outside mock interview platform. I always think like a math major graduate student, the first 5 minutes I will go over anything including mathematics, and then I rested all time. Since I went through the linked list practice in 2016, here is one of linked list practice blog to document my practice. 

I like to observe how the peer picked up the analysis and worked hard on the coding. For me, it is just another routine and I do not need to think about too much. 

C# code is written here, and later on I will compile and add some test cases. 

First, I wrote a recursive solution. The link is here. And then I wrote an iterative solution, the link is here

Also, I like to give the code review for the peer's code. The code is here


Statistics


Time spent in discussion 7:15 pm - 9:18 pm 



No comments:

Post a Comment