Short Problem Definition: You are given time in AM/PM format. Convert this into a 24 hour format. Link Time Â Conversion Complexity: time complexity is O(?) space complexity is O(?) Execution: Transforming date formats without the use of the proper libraries is a disaster waiting to happen. Date formats are ever changing and a waste of engineering effort. Just use whatever package comes with your...

## HackerRank âTwo Stringsâ Solution

Short Problem Definition:

You are given two strings, A and B. Find if there is a substring that appears in both A and B.

Link

Two Strings

Complexity:

time complexity is O(N+M);

space complexity is O(1)

Execution:

At first sight this seems like a longest common substring problem. It is actually much easier. You just need to find out if there are two equal letters in both strings A and B.

Solution:

## HackerRank âUtopian Treeâ Solution

Short Problem Definition: The Utopian Tree goes through 2 cycles of growth every year. The first growth cycle occurs during the spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter. Â Now, a new Utopian Tree sapling is planted at the onset of spring. Its height is 1 meter. Can you find the height of the tree after N growth cycles...

## HackerRank âSherlock and Valid Stringâ Solution

Short Problem Definition: Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just 1 character at 1 index in the string, and the remaining characters will occur the same number of times. Given a string , determine if it is valid. If so, return YES, otherwise...

## HackerRank âPairsâ Solution

Short Problem Definition: Given N integers, count the number of pairs of integers whose difference is K. Link Pairs Complexity: time complexity is O(N*log(N)) space complexity is O(N) Execution: The solution is pretty straight-forward, just read the code :). The runtime complexity is calculated with log(N) access times for tree-based sets (not the case in Python). Solution: 1 2 3 4 5 6 7 8 9...

## HackerRank âSherlock and Watsonâ Solution

Short Problem Definition: John Watson performs an operation called Right Circular Rotation on an integer array [a0, a1, âŚ an-1]. Right Circular Rotation transforms the array from [a0, a1, âŚ aN-1] to [aN-1, a0,âŚ aN-2]. He performs the operation K times and tests Sherlockâs ability to identify the element at a particular position in the array. He asks Q queries. Each query consists of one integer...

## HackerRank âPalindrome Indexâ Solution

Short Problem Definition: You are given a string of lower case letters. Your task is to figure out the index of the character on whose removal it will make the string a palindrome. There will always be a valid solution. Link Palindrome Index Complexity: time complexity is O(N) space complexity is O(N) Execution: The solution seems n^2 but isPalindrome is executed only once. Due to the problem...

## HackerRank âSimple Text Editorâ Solution

Short Problem Definition: In this problem, your task is to implement a simple text editor. Initially, a file contains an empty string S. Your task is to perform Q operations consisting of the following 4 types: append(W) â Appends the string W at the end of S. erase(k) â Erase the last k character of S. get(k) â Returns the kth character of S. undo() â Undo the last not previously undone...

## HackerRank âPangramsâ Solution

Short Problem Definition: Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence âThe quick brown fox jumps over the lazy dogâ repeatedly, because it is a pangram. (Pangrams are sentences constructed by using every letter of the alphabet at least once.) Link Pangrams Complexity: time complexity is O(N) space complexity is O(N) Execution:...

## HackerRank âSock Merchantâ Solution

Short Problem Definition: John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. Link Sock Merchant Complexity: time complexity is O(N) space complexity is O(N) Execution: Group the same color together. Look out for the...