Saturday, May 18, 2019

Mongodb 1067 error : Service not starting

The Mongo DB service is starting.
The Mongo DB service could not be started.

A system error has occurred.

System error 1067 has occurred.

The process terminated unexpectedly.

Some blog suggest this error occure due to limitation disk space.

The Solution :- 

The error came from an unclean shutdown detected.

Below steps will fix it
1) Remove the file /data/db/mongod.lock
2) Run mongod.exe --repair
3) Start the mongod service net start MongoDB

Please visit http://dochub.mongodb.org/core/repair for complete recovery instructions.

Saturday, August 25, 2018

Sherlock and Anagrams

Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string, find the number of pairs of substrings of the string that are anagrams of each other.
For example , the list of all anagrammatic pairs is  at positions  respectively.
Function Description
Complete the function sherlockAndAnagrams in the editor below. It must return an integer that represents the number of anagrammatic pairs of substrings in .
sherlockAndAnagrams has the following parameter(s):
  • s: a string .
Input Format
The first line contains an integer , the number of queries.
Each of the next  lines contains a string  to analyze.
Constraints


String  contains only lowercase letters  ascii[a-z].
Output Format
For each query, return the number of unordered anagrammatic pairs.
Solution :- 

  static int sherlockAndAnagrams(string s)
        {            
            int count = 0;
            var dictStr = new Dictionary<string, int>();
            for (int i = 0; i < s.Length; i++)
            {
                for (int j=i+1; j <= s.Length; j++)
                {
                    var str = s.Substring(i, j-i);
                    var chars = str.ToCharArray();
                    Array.Sort(chars);
                    var word = new string(chars);
                    if (dictStr.ContainsKey(word))
                    {
                        var value = dictStr[word];
                        count = count + value;
                        dictStr[word] = value + 1;
                    }
                    else
                        dictStr.Add(word, 1);                    
                }
            }
            return count;
        }


Thursday, August 23, 2018

Linked Lists: Detect a Cycle

Check out the resources on the page's right side to learn more about linked lists. The video tutorial is by Gayle Laakmann McDowell, author of the best-selling interview book Cracking the Coding Interview.
A linked list is said to contain a cycle if any node is visited more than once while traversing the list. For example, in the following graph there is a cycle formed when node  points back to node .
image
Function Description
Complete the function has_cycle in the editor below. It must return a boolean true if the graph contains a cycle, or false.
has_cycle has the following parameter(s):
  • : a pointer to a Node object that points to the head of a linked list.
Note: If the list is empty,  will be null.
Input Format
There is no input for this challenge. A random linked list is generated at runtime and passed to your function.
Constraints
Output Format
If the list contains a cycle, your function must return true. If the list does not contain a cycle, it must return false. The binary integer corresponding to the boolean value returned by your function is printed to stdout by our hidden code checker.
Solution :-
boolean hasCycle(Node head) {

    HashSet<Node> strObjMap = new HashSet<Node>();
    while(head != null)
    {
        if(!strObjMap.contains(head))
        {
            strObjMap.add(head);
        }
        else
        {
            return true;
        }
        head = head.next;
    }
    return false;
}


Part 7 — Enterprise RAG Reference Architecture

  "Architecture is not about connecting components. It is about defining responsibilities that can evolve independently." Welcome ...