Latest stories

HackerRank ‘The Grid Search’ Solution

H

Short Problem Definition: Given a 2D array of digits, try to find the location of a given 2D pattern of digits Link The Grid Search Complexity: time complexity is O(n^2 * m^2) space complexity is O(1) Execution: There are many sophisticated 2d pattern matching algorithms out there. Just think of computer vision, robotics, gaming… The issue with most of them is, that they are rather heuristics...

HackerRank ‘Taum and B’day’ Solution

H

Short Problem Definition: Taum is planning to celebrate the birthday of his friend Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buy B number of black gifts and W number of white gifts. Link Taum and B’day Complexity: time complexity is O(1) space complexity is O(1) Execution: The cost for each present is...

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 ‘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 ‘String Construction’ Solution

H

Short Problem Definition: Amanda has a string of lowercase letters that she wants to copy to a new string. She can perform the following operations with the given costs. She can perform them any number of times to construct a new string p: Append a character to the end of string p at a cost of 1 dollar. Choose any substring of p and append it to the end of  at...

HackerRank ‘Strange Counter’ Solution

H

Short Problem Definition: Bob has a strange counter. At the first second, it displays the number 3. Each second, the number displayed by the counter decrements by 1 until it reaches 1. The counter counts down in cycles. In next second, the timer resets to 2x the initial number for the prior cycle and continues counting down. Link Strange Counter Complexity: time complexity is O(log(N)) space...

HackerRank ‘Staircase’ Solution

H

Short Problem Definition: Your teacher has given you the task to draw the structure of a staircase. Being an expert programmer, you decided to make a program for the same. You are given the height of the staircase. Link Staircase Complexity: time complexity is O(N^2) space complexity is O(1) Execution: Either fill each level with N-i empty spaces or adjust to the right. Solution: 1 2 3 4 5 6 7 8...

HackerRank ‘Song of Pi’ Solution

H

Short Problem Definition: That’s the value of pi! (Ignoring the floating point) A song is a pi song if the length of its words represent the value of pi. Link Song of Pi Complexity: time complexity is O(N*T) space complexity is O(N) Execution:   This problem is straight forward. Solution: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #!/usr/bin/py   PI = map(int...

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

Archives

Categories