Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALGORITHM


  Gcd Algorithm with JavaScript

How to find the greatest common divisor betweentwo integers? We may encounter this problem frequently in interviews or otheroccasions.Anefficient metho to find gcd is the Euclideanalgorithm, whichuses the divisionalgorithm incombination with the observation that the gcd of two numbers also divides theirdifference: divide 48 by 18 to get a quotient of 2 and a remainder of 12. Thendivide 18 by 12 to get a quotient of 1 and a remainder of 6. Then divide 12 by6 to get a remainder of 0, which means that 6 is the gcd. Formally, it could bewritten asgcd(a,0)= agcd(a,b)= gcd(b...

10,890 2       JAVASCRIPT ALGORITHM GCD IMPLEMENTATION


  Significance and use of do{...}while(0)

In some Linux kernel and other open source codes, we can see some codes like below:do{ ...}while(0)This code snippet is not a loop, it seems there is no significance of using do...while this way, then why should we use it?In fact, the significance of do{...}while(0) is better than optimizing your code. After some research, we summarize some benefits of it.1. Help define complex macro to avoid error#define DOSOMETHING()\ foo1();\ foo2();The meaning of the macro is when calling DOSOMETHING(), the functions foo1() and foo2() will be called. But if you write it like thi...

9,430 0       DO{...}WHILE(0) OPTIMIZATION


  Algorithm : Delete middle node from singly linked list

Questions about singly linked list are frequently asked during technical interviews. Today we will share with you one algorithm question about singly linked list. Here is the problem description.Assuming the only information you are giving is there is a pointer to a middle node of a singly linked list, no other information about the linked list is given. Please delete this node and don't affect the structure of the linked list.Initially you may think this question is easy if you know the head node of the linked list, but unfortunately we don't know what the head is and hence we cannot know the...

8,410 0       C ALGORITHM LINKED LIST


  Overlap Detection

How does one detect when two strings overlap? In the case below, the four-letter suffix of string 1 matches the four-letter prefix of string 2.1: "Fire at Will"2: "William Riker is number one"Sometimes there are several matches; finding the longest is not always straight forward.1: "Have some CoCo and CoCo"2: "CoCo and CoCo is here."2: "CoCo and CoCo is here."2: "CoCo and CoCo is here."The naïve solution is to take ever smaller substrings of each string, compare them, then bail out when the first match is found. This is quick ...

7,076 0       PYTHON IMPLEMENTATION STRING OVERLAP DETECTION


  A boolean value interview question

Someone asked a question on StackOverflow, he was asked an interview question. The question is : Given 3 boolean variables a, b, c, return true if at least 2 out of the 3 are true. He gave the solution as follows :boolean atLeastTwo(boolean a, boolean b, boolean c) {    if ((a && b) || (b && c) || (a && c)) {        return true;    } else {        return false;    }}Then the interviewer asked him to improve the solution given and ma...

6,626 0       RETURN EXPRESSION BOOL CONDITIONAL


  Dividing any number By 9, 90, 900 and so on

Thetechnique for Dividing any number by 9 mentally is simply to reduce a complex divisionto a very simple addition. The technique can be applied from both ends i.e. from right-most digit or from left-most digit. Dividingby 9 into a mixed number from right-most digit uses the Divisibility Rules for9:1.     First, add all the digitstogether and divide by 9, keeping in mind the whole number and the remainder.2.     Write the remainder over 9, thisis the fraction part of the answer. (Make sure the fraction is in simplestform.)3.     Add a...

6,169 0       ALGORITHM 9 90 DIVISION


  Google search engine algorithm change history

Recently, Google had a major adjustment on its search algorithm: Users can directly see answers to the searched question on the top of the page.There are billion of search requests each day on Google. There is no doubt that the algorithm will become the subject of discussion. Last year, Google did an adjustment to its search algorithm every 17.5 hours in average. We all experience the change of the algorithm. Following information chart summarizes the major changes of Google search algorithm since 1998.From the above table we can see several major search algorithm improvements:March 1998...

6,164 0       GOOGLE HISTORY SEARCH ENGINE GOOGLE+


  Algorithm : Reverse singly linked list

Questions about singly linked list are the lovers of interviewers during interviews given the characteristic that singly linked list is one-directional list and it's difficult to get the previous node of one node without some buffering tricks. In this post, we will demonstrate one of the most frequently asked question about singly linked list -- Reversing the singly list.Given the first node of a singly linked list, reverse the singly linked list. For example :A->B->C->DAfter reverse, it becomes:D->C->B->AThe general idea here is to changing the next node of one to its p...

5,541 0       C ALGORITHM INTERVIEW