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 âPicking Numbersâ Solution

Short Problem Definition: Given an array of integers, find and print the maximum number of integers you can select from the array such that the absolute difference between any two of the chosen integers is less than or equal to 1. For example, if your array is a = [1, 1, 2, 2, 4, 4, 5, 5, 5], you can create two subarrays meeting the criterion: [1 ,1 ,2 ,2] and [4, 4, 5, 5, 5]. The...

## HackerRank âSong of Piâ Solution

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 âPlus Minusâ Solution

Short Problem Definition: Youâre given an array containing integer values. You need to print the fraction of count of positive numbers, negative numbers and zeroes to the total numbers. Print the value of the fractions correct to 3 decimal places. Link Plus Minus Complexity: time complexity is O(N) space complexity is O(1) Execution: Count the values. Do not forget to force floats instead of...

## HackerRank âPoisonous Plantsâ Solution

Short Problem Definition: There are NN plants in a garden. Each of these plants has been added with some amount of pesticide. After each day, if any plant has more pesticide than the plant at its left, being weaker than the left one, it dies. You are given the initial values of the pesticide in each plant. Print the number of days after which no plant dies, i.e. the time after which there are no...

## HackerRank âRepeated Stringâ Solution

Short Problem Definition: Lilah has a string, s, of lowercase English letters that she repeated infinitely many times. Given an integer, n, find and print the number of letters a in the first n letters of Lilahâs infinite string. For example, if the string s = âabcacâ and n = 10, the substring we consider is abcacabcac, the first 10 characters of her infinite string. There...

## HackerRank âSave the Prisoner!â Solution

Short Problem Definition: A jail has N prisoners, and each prisoner has a unique id number,S , ranging from 1 to N. There are M sweets that must be distributed to the prisoners. But waitâthereâs a catchâthe very last sweet S is poisoned! Can you find and print the ID number of the last prisoner to receive a sweet so he can be warned? Link Save the Prisoner! Complexity: time complexity is O(1)...

## HackerRank âService Laneâ Solution

Short Problem Definition: Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any risks. Luckily, a service lane runs parallel to the highway. The length of the highway and the service lane is N units. The service lane consists of N segments of equal length and different width. Link...