Latest stories

HackerRank ‘Weighted Uniform Strings’ Solution

H

Short Problem Definition: A weighted string is a string of lowercase English letters where each letter has a weight. Character weights are 1 to  26 from a to z… Link Weighted Uniform String Complexity: time complexity is O(N) space complexity is O(N) Execution: Parsing the string for every query is suboptimal, so I first preprocess the string. Now we know that uniform...

HackerRank ‘Strong Password’ Solution

H

Short Problem Definition: Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria: Its length is at least 6. It contains at least one digit. It contains at least one...

HackerRank ‘Two Strings’ Solution

H

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 ‘Time Conversion’ Solution

H

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...

HackerRank ‘Super Reduced String’ Solution

H

Short Problem Definition: Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one operation. Steve’s task is to...

HackerRank ‘The Time In Words’ Solution

H

Short Problem Definition: Given the time in numerals we may convert it into words. Link The Time In Words Complexity: time complexity is O(?) space complexity is O(?) Execution: I might have hinted at my opinion in the past: Why do “challenges” like this even exist? It requires 0 brain power, but you will spend an hour figuring out the fine details of English and fixing bugs. Solution: 1 2 3 4 5...

HackerRank ‘Sherlock and Watson’ Solution

H

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 ‘Sherlock and The Beast’ Solution

H

Short Problem Definition: Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diabolical. Sherlock’s companion, Dr. Watson, suggests Moriarty may be responsible for MI6’s recent issues with their supercomputer, The Beast. Shortly after resolving to investigate, Sherlock receives a note from Moriarty boasting about infecting The Beastwith a virus; however...

HackerRank ‘Sock Merchant’ Solution

H

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...

HackerRank ‘Simple Text Editor’ Solution

H

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...

Mailchaimp

About Me

I like to Code and Love to share the codes.