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 âWaiterâ Solution

Short Problem Definition: You are a waiter at a party. There are NN stacked plates. Each plate has a number written on it. You start picking up the plates from the top one by one and check whether the number written on the plate is divisible by a primeâŚ. Link Waiter Complexity: time complexity isÂ O(N*Q) space complexity is O(N) Execution: First of all, generate primes using Sieve, or copy-paste a...

## HackerRank âWeighted Uniform Stringsâ Solution

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 âStaircaseâ Solution

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 âString Constructionâ Solution

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 âStrong Passwordâ Solution

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 âSuper Reduced Stringâ Solution

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 âTaum and Bâdayâ Solution

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 âThe Grid Searchâ Solution

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 âThe Power Sumâ Solution

Short Problem Definition: Find the number of ways that a given integer, XÂ , can be expressed as the sum of the NthÂ powers of unique, natural numbers. For example, if X = 13Â and N = 2, we have to find all combinations of unique squares adding up to 13. The only solution is 2^2 + 3^2. Link The Power Sum Complexity: time complexity is O(N!) space complexity is O(1) Execution: This solution does not...