Showing posts with label word count engine. Show all posts
Showing posts with label word count engine. Show all posts

Wednesday, April 25, 2018

Being interviewee: Word count practice

April 25, 2018

Introduction


It is my favorite algorithm but also it is hard to write a complete solution in 30 minutes. The algorithm is to lower the sentence, remove special char \', and then split words by delimiters such as chars in the string " .:;,!", and then save the words to the dictionary, and then sort them by value. From the dictionary, apply the sentence word order, save words in the bucket to apply bucket sort, and then output in descending order of value.

Mock interview


I tried to write the code and pass test cases in 38 minutes, but I could not make it. After the mock interview, I spent over 20 minutes to debug and fix bugs in two places.

Here is C# code written in today's mock interview 8:00 PM. On line 48, I need to remove the statement: if(item.Length == 0), actually the statement: continue is deleted by cleaning process; and on line 106, the word may not be in the dictionary.


And here is C# code written after the mock interview to fix the bugs.

Chatting


It is such a nice experience to practice the algorithm with a software engineer from expedia.com. I was asked if I work for Microsoft since I choose to use C# programming language. I couldn't believe that the peer wrote the optimal solution quick and correctly. I just could not believe that I keep meeting a very talented programmer again, in an ordinary Wednesday. I spent 38 minutes on my algorithm, the peer spent less than 20 minutes on his algorithm meeting planner.

Action items


I need to design some drills for me to work on those algorithms similar to those mock inerview algorithm, play with the error message, so I can think about how to identify issues quickly once I read some error message.

Train myself to read the error message, and also get used to pinpoint the place by interpreting the error message correctly, specially for those error message without line of code information.

My ideal practice is to fix bugs in one minute. I should be able to quickly identify the code's issue.

Wednesday, March 28, 2018

Work count practice

March 28, 2018

Introduction


It is very challenge algorithm to work on in 30 minutes. I have worked on the algorithm more than 6 times, but I never had chance to complete the code and pass all test cases in less than 30 minutes.

Today I also read the problem statement, I need to write code to keep the original order of words in the same bucket.

Code practice


Here is the C# code I wrote in 30 minutes in the mock interview. After the mock interview, I spent at least 30 minutes to complete the code and pass all test cases. Here is the C# code to pass all test cases.

Here are highlights of my work after mock interview:

1. line 18, Punctuation chars: "., !:;?", I missed :, ;, ?
2. line 22, Add function argument totalCount
3. line 22, function argument should be replaced, not orignal string document.
4. line 27 - line 41, I fail to call string.Replace to replace ' using empty char, so replaceChar function is written.
5. comment out line 16
6. Still confuse ToLower() function call, should string.ToLower() or document.ToLower()
Argument: string is class, not an interface, so ToLower is member function of string class, not interface member function.
7, line 57 and line 58, index variable should be used instead of using variable i defined on line 49.

Sunday, February 18, 2018

Word count practice

Feb. 18, 2018


Introduction


It is hard for me to master the algorithm called word count practice.  I have to work on the string manipulations, such as lower case, remove extra chars, and split string using regular expression, and then group by the value and sort by input string order.


One more practice


Here is one more practice I did on Feb. 17, 2018 10:00 PM mock interview, I wrote 20 minutes.

Sunday, January 21, 2018

Word count algorithm practice

January 21, 2018

Introduction


It is another mock interview at 4:00 pm. I had to work on the algorithm called word count in a sentence. The task is to lower the char in sentence, replace ' using empty space, split into words using delimiter string ".!,", and then store words to Dictionary<string, int>, and then apply bucket sort, and then output to array.

30 minutes is the time limit for me to write. I could not finish it.


Please complete the code


Here is the code I wrote in 30 minutes in mock interview. I like to spend time to write today and complete it to pass all test cases on mock interview platform.


Follow up 

January 23, 2018

Here is C# code to pass all test case. I spent over 30 minutes to read Regular.Split and String.Split and figure out how to specify delimiters, how to specify multiple using +, using [ and ] to enclose all delimiters, and understand ( and ) meaning.

C# code is here.


Friday, October 27, 2017

Code review "LINQ and string.Split do it yourself practice" (II)

Oct. 27, 2017


Introduction


It is the first time I understand that the technical strength can only be trained by dedicated practice. Today I had chance to walk through those five lines of C# code, and explained to the peer how to apply those things in C++ code.

Will come back to document more about the experience as an interviewer. My last blog about the code review is here less than one month ago.


Algorithm talk 


The peer likes to write C++ but the complexity of code is beyond his expectation. 30 minutes is too short to come out the workable solution.

Here is the C# code written by code review on stackexchange.com:


Each step in the above C# code can be a small function written in C++ if the peer does not know the regular expression, or similar LINQ method. 3 or 4 years job experience does not help to train yourself to be a good C++ programmer. You need to train carefully.


Actionable Item



Plan to do some research about post vacation syndrome. I need to get out of relationships from the family back in China, less frequent using wechat to communicate family in China anymore, and get back to my normal work day in the city of Vancouver. One thing I choose to do after I overcome jet lag is to practice mock interview every day 10:00 PM. Need to meet new people and learn more about the industry and people.

Give myself a pat on my shoulder. Show my report of first mock interview after a month break.

Thursday, September 28, 2017

Code review "LINQ and string.Split do it yourself practice"

Sept. 28, 2017

Introduction



It is time to review the algorithm again. I posted the question more than 5 month ago, the link is here.


Algorithm Practice


I had a mock interview and the peer chose to use C++ language. I did some research how to translate those four lines of C# code to C++ language.


I just could not believe that one day I can write a product using C# advanced feature like LINQ, write regular expression and groupby clause and where clause. I am so excited to set a small goal for my next project.

Monday, August 7, 2017

String search algorithm practice

August 7, 2017

Introduction



It is the British Columbia holiday and I booked another mocking practice at 12:00 pm. The practice hours is a very happy time to learn how to work on one algorithm.

Algorithm practice


C# practice code is here. I spent over 10 minutes to fix so many compile errors, but I stopped after running into the execution errors.

After the practice, I found the two problems, one is null pointer error (4 lines of code are added from line 44 to 47), second one is missing a loop (a for loop is added on line 58), I fixed them after mocking practice.

Weakness


There are two issues in my writing in mocking interview. First one is null pointer issue. Second one is to separate the collection from one single item. Need to go over each item in collection, and append each of them.

Plan to do some research on common mistakes in C# code. Using strong typing is a good tip to allow the compiler to help, avoid error in run time checking.


Monday, April 3, 2017

Code review: C# LINQ and string.Split do it yourself

April 3, 2017

Introduction

As an old saying in Ecclesisaster 3 - A time for everything, Julia likes to take 5 minutes to celebrate her 8k reached milestone. Show the visual stuff here:


Code Review


Julia spent 45 minutes to write an algorithm to scan the sentence without compiler, and then spent over one hour to make it run using Microsoft visual studio. And then, she asked a question on code review.

Here is the link of code review. She was so surprised to get excellent code review. Sky is the limit, she has to learn so many things through the code review.

She was busy to read those documents of interface and class in order to understand the code review and discussion, IEnumerable, StringComparer, StringSplitOptions, Regex.