Monthly Archives: August 2013

Utopian Identification Number: Hackerrank

Problem link: https://www.hackerrank.com/challenges/utopian-identification-number

Problem Statement:
A new identification number is given for every Citizen of the Country Utopia and it has the following format.

1. The string must begin with between 0 and 3 (inclusive) lowercase letters.
2. Immediately following the letters, there must be a sequence of digits. The length of this segment must be between 2 and 8, both inclusive.
3. Immediately following the numbers, there must be at least 3 uppercase letters.

Your task is to find out if a given identification number is valid or not.
Continue reading

Advertisements

Detect HTML Tags: Hackerrank

Problem link: https://www.hackerrank.com/challenges/detect-html-tags

Problem Statement:
In this problem you will use regular expressions to help you detect the various Tags used in an HTML document.

Here are a few examples of tags:

The “p” tag for paragraphs:

<p>This is a paragraph</p>

It is also okay to have one or more spaces before or after the tag name:

<  p >This is also a paragraph</p>

Then, there is also something called a void or an empty tag such as:

<p></p>

Some tags can also have attributes. For example, here we see the “a” tag which is used for adding links to a document.

<a href="http://www.google.com">Google</a> 

There are also tags such as this which haven’t been split into an opening and closing tag:

In the above case, “a” is the tag and “href” is an attribute, the value of which is “http://www.google.com”. Ignore any attributes. Your task is to find out all the tags present in the given document.
Continue reading

String Similarity: Hackerrank

Problem link: https://www.hackerrank.com/challenges/string-similarity

Problem Statement:
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings “abc” and “abd” is 2, while the similarity of strings “aaa” and “aaab” is 3.

Calculate the sum of similarities of a string S with each of it’s suffixes.
Continue reading