Saturday 26 November 2016

Microsoft Interview Questions (part 1)

Microsoft Interview Question 


Q1. The interviewer first discussed about my projects ?

 especially what your role in every project , what are you use from technologies to implement ?
 team size in every project  

Q2. Convert a Binary Tree to Doubly Link List (DLL) in place?

 first the order of DLL must be in the same inorder of  binary tree left most in BT see pic 1

                                                                     pic 1
in-order method go to deep left at first from the head 10 then go left treat it as tree head 12 go left a gain then 25 the end leaf no left and right come back take 12 move right take 30 go to parent of 12 has 10 take if and i has leaf right  15 head of sub tree then go to 36 take it and last take 15

secondly using recursive to fill doubly linked list from tree by in-order predecessor that is 
find in-order predecessor of root in left sub-tree (in-order predecessor is rightmost node in left sub-tree). then  
Make in-order predecessor as previous of root and root as next of in-order predecessor. and so on 
this code describe that written in java 

  
class Node 
{
    int data;
    Node left, right;
  
    Node(int item) 
    {
        data = item;
        left = right = null;
    }
}
  
class BinaryTree 
{
    Node root;
    /* This is the core function to convert Tree to list. This function
       follows steps 1 and 2 of the above algorithm */
  
    Node bintree2listUtil(Node node) 
    {
        // Base case
        if (node == null)
            return node;
  
        // Convert the left subtree and link to root
        if (node.left != null) 
        {
            // Convert the left subtree
            Node left = bintree2listUtil(node.left);
  
            // Find inorder predecessor. After this loop, left
            // will point to the inorder predecessor
            for (; left.right != null; left = left.right);
  
            // Make root as next of the predecessor
            left.right = node;
  
            // Make predecssor as previous of root
            node.left = left;
        }
  
        // Convert the right subtree and link to root
        if (node.right != null) 
        {
            // Convert the right subtree
            Node right = bintree2listUtil(node.right);
  
            // Find inorder successor. After this loop, right
            // will point to the inorder successor
            for (; right.left != null; right = right.left);
  
            // Make root as previous of successor
            right.left = node;
  
            // Make successor as next of root
            node.right = right;
        }
  
        return node;
    }
  
    // The main function that first calls bintree2listUtil(), then follows
    // step 3 of the above algorithm
      
    Node bintree2list(Node node) 
    {
        // Base case
        if (node == null)
            return node;
  
        // Convert to DLL using bintree2listUtil()
        node = bintree2listUtil(node);
  
        // bintree2listUtil() returns root node of the converted
        // DLL.  We need pointer to the leftmost node which is
        // head of the constructed DLL, so move to the leftmost node
        while (node.left != null)
            node = node.left;
  
        return node;
    }
  
    /* Function to print nodes in a given doubly linked list */
    void printList(Node node) 
    {
        while (node != null) 
        {
            System.out.print(node.data + " ");
            node = node.right;
        }
    }
  
    /* Driver program to test above functions*/
    public static void main(String[] args) 
    {
        BinaryTree tree = new BinaryTree();
  
        // Let us create the tree shown in above diagram
        tree.root = new Node(10);
        tree.root.left = new Node(12);
        tree.root.right = new Node(15);
        tree.root.left.left = new Node(25);
        tree.root.left.right = new Node(30);
        tree.root.right.left = new Node(36);
  
        // Convert to DLL
        Node head = tree.bintree2list(tree.root);
  
        // Print the converted list
        tree.printList(head);
    }
}


Q3. One DBMS query select 2nd max salary from table,
 SELECT MAX(Salary) FROM Employee
  WHERE Salary != (SELECT MAX(Salary) FROM Employee )
or 
 SELECT MAX(Salary) FROM Employee
  WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )
Q4. OS questions from deadlock, synchronization, scheduling, diff between process and thread.
Q5. What happens when you type URL in browser and hit enter? Explain in detail.
Q4 and Q5 and others will answered in next part follow to get latest update 
written by 

Friday 25 November 2016

Crazy Code (Part 2)

Decode String Problem

If a=1, b=2, c=3,….z=26. Given a string, find all possible codes that string
can generate. Give a count as well as print the strings.
For example:
Input: “1123″. You need to general all valid alphabet codes from this string.
what will be ?
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testCodes
{
    class Program
    {
        static void Main(string[] args)
        {
          Console.WriteLine("Enter number :");
          string nums  = Console.ReadLine();
          Program prog = new Program();
            prog.ProcessString(nums,"");
          
 
        }
      public  void ProcessString(string number,string code)
{
    if (number == null ||
        number.Length == 0)
    {
        if (code != null && code.Length > 0)
        {
            Console.WriteLine(code);
        }
        return;
    }
    ProcessString(number.Substring(1), code +
        (Convert.ToChar('a' + (number[0] - '0') - 1)).ToString());
    if (number.Length > 1)
    {
        int n = Convert.ToInt32(number.Substring(0, 2));
        if (n <= 26)
        {
            ProcessString(number.Substring(2), code +
                (Convert.ToChar('a' + n - 1)).ToString());
        }
    }
}
 
}
    }

this program work correctly but what you notice on output is it complete or not ?
if any one has question on code or misunderstand  i will answer in his comment
written by

Oracle requires a subscription to use Java SE NOW

May be licenses won’t be available for Java SE 8 or later, but separate support contracts also go away after Microsoft acquire G ithub...