Saturday, May 13, 2017

Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.

public class Solution {
    public int minDistance(String word1, String word2) {
        if (word1.equals(word2)) {
        return 0;
    }
    if (word1.length() == 0 || word2.length() == 0) {
        return Math.abs(word1.length() - word2.length());
    }
    int[][] dp = new int[word1.length() + 1][word2.length() + 1];
    for (int i = 0; i <= word1.length(); i++) {
        dp[i][0] = i;
    }
    for (int i = 0; i <= word2.length(); i++) {
        dp[0][i] = i;
    }
    for (int i = 1; i <= word1.length(); i++) {
        for (int j = 1; j <= word2.length(); j++) {
            if (word1.charAt(i - 1) == word2.charAt(j - 1)) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                dp[i][j] =Math.min(dp[i-1][j], dp[i][j-1]) + 1;
            }
        }
    }
    return dp[word1.length()][word2.length()];
    }
}

Output:
"sea"
"eat"

Answer:
2

Friday, May 12, 2017

express module node.js

Express module is one of the most installed module in Node.js.  Express is a flexible Node.js web application framework which provides a robust set of features for web as well as mobile applications.
Using express we can create robust API's very easily and quickly .

Thursday, May 11, 2017

NPM (Node.js package manager)

NPM comes with node.js installation. It is node.js package manager, as the name suggests it is used to install node programs/modules. We can also easily specify and link dependencies.

npm install express                                installs express module

npm install express --save                     installs express and updates the dependencies in package.json


Modules get installed into the "node_modules" folder .

Wednesday, May 10, 2017

package.json in Node.js

This file goes in the root of our package or application and it tells how our package is structured and what to do to install it.

"npm init" command will create a package.json file and it will ask for details as shown below



Tuesday, May 9, 2017

Partial Classes

Partial classes concept was introduced in .NET 2.0 which allows us to split business logic in multiple files with same class name but with a "partial" keyword.

Monday, May 8, 2017

Explain the differences between TCP and UDP?

Tcp is connection oriented service which means every time you send a message you get an acknowledgment from the receiver stating the message has been received.
This is a reliable way of communication, but is slow. Think of it as a telephonic call. Only when the other side picks up the call, you can talk.

UDP is connectionless service. Like the one we use in online streaming. There is no acknowledgement in this case so the data might not be perfect at the receiver but the transmission is fast. So a few packet loss doesn't really matters. It is like an email. You can send but you wont know if it has been read or not. Like you wont know which packets reached and which were dropped.

Call a function in child component from parent component in React

Consider the following parent component class Parent extends React.Component { constructor(props) { super(props);         thi...