Showing posts with label root of a number. Show all posts
Showing posts with label root of a number. Show all posts

Saturday, April 21, 2018

Being an interviwee: Root of a number

April 21, 2018

Introduction


It is 12:00 PM mock interview. I have experience to work on the algorithm root of a number over 10 ten times, 5 for interviewer, 5 for interviewee. The peer has strong talent with 1st place twitter big data hackathon. The peer worked on decrypt the message algorithm first, I rated him top 5 - 10% in all over 200 peers I worked last 12 months.

Mock interview


I like to write a binary search and also apply some technique I saw recently using integer to count the numbers.

The peer challenged me about the termination base case, 0.001 is the error range, how I assert that two values are equal using 0.001?

Here is my C# code.




Wednesday, March 28, 2018

Being an interviewer: Root of a number

March 28, 2018

Introduction


It is a binary search algorithm called root of a number. The hint I gave in the mock interview as an interviewer is to explain how many numbers to search for x = 8, n = 3, it is from 0, incremented by 0.001 to 8, total is 8000 numbers to search.

Binary search algorithm


Here is the binary search algorithm I reviewed written by the peer. The algorithm still has issues to pass a few test cases. I like to look into as well.

I like to get organized and review all my past practice.

Code review


Actually the code should be updated in two places:
1. Line 44 and 45, return (double) m/ 1000;
2. Line 56, return (double) s/ 1000;

The argument is that when s == e on line 37, the return value should be s, not -1 or 0.0.

Incremental value 


It is better to change the design, and use 0.0001 as a different number to apply binary search. Here is C# code.

Given the example x = 8, n = 3, instead of search 8000 numbers, we choose to search 80,000 using binary search. Incremental value is 0.0001 instead of 0.001.

Being an interviewer, it takes some time to figure out how to guide the peer to lead the optimal solution and pass all test cases.

Sunday, January 14, 2018

Root of a number

January 14, 2018

Introduction


It is such a great machine learning algorithm on mock interview platform. I spent 50 minutes with a top ranking university with highest GPA, a master student to work on a problem solving. Quickly in less than 20 minutes the solution was written and also pass almost all test cases. I was amazed by the peer the engineering power, the way he tested the code, and the quick he applied to small increment value from 0.001 to 0.0009 to 0.0001, and also the answer he gave to me why it is good idea to always increment or decrement one value.

I have worked on the algorithm through mock interview near 10 times, I never came cross this idea to apply increment/ decrement the middle value one but just simply apply the value from 0.001 to 0.0001.


Code review


Here is the code written by the peer using C++. I like to code review later on.


Tuesday, December 12, 2017

Binary search practice

Dec. 12, 2017


Introduction


Binary search algorithm is getting easy to write and I wrote one more time on Dec. 11 10:00 PM mock interview. I wrote the algorithm using C# language and the code passes all test cases.

Code review


Here is C# code.

Line 50: return binarySearch(x, n start, end);

I forgot to write a recursive call as line 50 shows. After the whiteboard testing, I wrote the test case Root(7, 3) and then I found out the bug.


Follow up 

Dec. 19, 2017  10:14 PM

Binary search range should be discussed based on x value, if x > 1, then the search range is [0, x]. But if x < 1, then search range is [x, 1] instead.

The mock interview practice has a bug related to range to search.



Tuesday, November 21, 2017

Leetcode 69. Sqrt(x)

Nov. 21, 2017


Introduction


It is the algorithm to apply binary search and also relate to math round of a number given the error range, the algorithm is similar to easy level algorithm called Leetcode 69, Sqrt(x).


Algorithm review 


Julia spent first 30 minutes to work on the algorithm analysis and wrote code. Afterwards, the peer helped Julia to find bugs to make sure all test cases are passed.

Here is C# code submission with bugs.

Here is C# code submission after discussion of issues causing bugs. The code passes all test cases.


Highlights of discussion


It took almost three hours for Julia to discuss with the peer how to solve the algorithm and data structure problems. The mock interview had some technical issue, so the additional tools are used. One is for vidoe, https://appear.in and the other one is for editing, http://collabedit.com/. The mock interview started from 10:05 PM and ended around 1:15 am next morning.







Tuesday, May 30, 2017

Leetcode 69. Sqrt(x)

May 30, 2017

Plan to review Leetcode 69. Sqrt(x).

Past practice

69 sqrt(x)

Blogs to study, yocoding blog is here. 


codganker blog is here.


C# implementation:

Leetcode 69 C# practice is here. 


Mocking practice

May 3, practice is here. 
May 30, C# practice is here. Root a number by power of n, for example, 0.001 - n = 3, root number is 0.1. 
June 26, C# practice is here. 

Julia did white boarding test on her own code, and then she found a bug on line 29 on test case 0.001, n = 3, search value 0.1. Learn to test your own code very carefully, and then find a bug on line 29. But Julia missed the bug on line 74. The peer asked the question to point out the bug on line 75, return integerValue/ 1000.0; not integerValue/ 1.0.