Showing posts with label Flatten dictionary. Show all posts
Showing posts with label Flatten dictionary. Show all posts

Saturday, April 28, 2018

Being an interviewee: Flatten dictionary

April 28, 2018

Introduction


I had 10:00 AM mock interview this morning and I had to work on flatten dictionary algorithm. What I like to do is to avoid memorizing the solution, but I like to learn something from this mock interview.

I cannot believe that I met a peer who had work experience in China, Amazon and Microsoft, :-) I found out after mock interview. But in the mock interview, I still have issues to write down the code, a few of them, I like to work with the talent programmer in 30 minutes. I spent at least 5 minutes to write down the analysis, and then worked on coding around 20 minutes. Last few minutes I worked on bug fixing, code cleaning. I ended my algorithm in 28 minutes.

Mock interview


Let me write down what issues I came cross in the mock interview. Here is my C# practice code with the analysis.

1. I need to look up stackoverflow, and then find C# code:
type check to see if value object is Dictionary<string, object>

2. I need to handle prefix function argument. The definition of prefix is kind of confusing, in algorithm analysis, I did not write down the detail of the design. But in mock interview, I had to play with the code, and then I had a few minutes discussion with the peer. And then I cleaned up the code, wrote three lines of code: line 36 yo line 39.

3. I need to move out the code related to newKey (line 23 to line 27) outside if statement line 29 as the peer advised. I need to remove the redundant code.

Actionable Items


I have 300 mock interview experience, but I still have to learn something each time to work on mock interview. What are those things I have to work on?

I could not believe that I like to practice mock interview, even this Saturday, I have to work on tax return, system design. I still book a few mock interviews to keep myself busy and learn something inside my small home office.

Tuesday, November 28, 2017

One more recursive function

Nov. 28, 2017

Introduction


It is the fifth time I write the recursive function related to C# GetType() in mock interview. I wrote a blog about past practice. One of blogs is here.

This time I came cross two issues in mock interview on Nov. 28, 2017, one is to write String.IsEmptyOrNull, I did not know that the API is static function of String class. In other words, String.IsEmptyOrNull(string s) is the prototype of API.

The second one is to write value.GetType() == Dictionary, which should be value.GetType() == Dictionary<string, object>. It is time to learn more about C# strong typing.

Here is C# code.

Actionable Items


Plan to read C# source code of string class, and then write down study notes.
Look into C# strong typing related topic as well.



Monday, August 28, 2017

Recursive solution - Julia's most favorite game

August 28, 2017

Introduction



Recursive function is my most favorite game as a software developer starting from 8/28/2017 10:00 pm. I think that I reach the threshold of number of failures, and then today I had great experience to write a recursive function. 

It is hard for me to find the time to practice mocking interview in August. I was busy to catch up so many things in August, vacation, outdoor activities like tennis, walking after dinner, so in August 2017, I only practice six mocking interviews so far. Today I like to go back to mocking interview and choose 10:00 pm instead of 8:00 pm. I only had two mocking experiences using 10:00 pm.


Algorithm practice 


Here is my C# practice code, the code passes all test cases, in 30 minutes limit. The peer type two wow to express the surprise, excellent performance. The only thing was last 10 minutes the peer lost video connection, the peer typed the text to continue the process.

My last practice is documented here, and the C# code is here.

Highlights of issues:

1. How to handle edge case?
case 1: "a.b.c", last key should not be followed by the dot char
case 2: if the key is empty string, then dot char should be skipped.

line 36: design of variable newPrefix, first writing is newPrefix = key + ".".  The design has flaw, if the key is the last one, the dot char should not be concatenated.

It is 11:50 pm. I turned on the computer and then added some notes about the compile errors in my writing. Write down the compile error, and then work on type issue, in the next practice, I should not write any code on this algorithm with type compiler errors. I am really tired and sleepy.

The corrections are in three places:
1. Line 38, add Dictionary<string, object>
2. Line 45, add (string)

The advice I got from the peer:
1. Move static variable into the function, line 9;
2. Empty key should not be concatenated by dot char '.' by observing the last test case.


Actionable Item




It is very important skills to learn how to work with various levels of software programmer, I decide to reserve 10:00 pm as my mocking interview time every day. I believe that 10:00 pm is hard choice, too late and it takes extra work to get focus. It will be good choice to simulate tough situations in the work place.

Bible verse encourages me to work hard, specially when I am tired.

Wednesday, April 19, 2017

Recursive function small talk

April 19, 2017

Introduction


It is a good practice to write down a simple test case, and go over the test case and explain the algorithm, write down every step and every detail to show how you are serious about the talk; show some good analysis by writing down some notes, like mathematical expression, some terms about computer algorithm, and things like pseudo code will be perfect because a person knows recursive function, her writing will terminate because one iteration is enough.

Julia recalled her only experience in 2016 and then she knew that she should write down more transcript instead of code. Try to put 10 minutes in coding writing, first 10 minutes to write down the problem, and everything to ensure the problem is communicated properly, and also the idea will help to lead a bug-free solution.

Julia learned in April after 5 or 6 mocking experience, suddenly she did not scare at all. She likes to play free and use this non-algorithm approach.

Recursive function or DFS algorithm is the most popular algorithm Julia learned to master in 2017.

Recursive function 


Transcript is here to review.

Transcript is being compiled to a new version. Here is the C# code.