# CategoryHackerRank

## 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 âPlus Minusâ Solution

H

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

H

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

H

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

H

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

H

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

## HackerRank âSherlock and Arrayâ Solution

H

Short Problem Definition: Watson gives Sherlock an array A of length N. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its right. If there are no elements to the left/right, then the sum is considered to be zero.Formally, find an i, such that, A1+A2âŚAi-1 =Ai+1+Ai+2âŚAN Link Sherlock and...

## HackerRank âSherlock and GCDâ Solution

H

Short Problem Definition: Sherlock is stuck while solving a problem: Given an array A={a1,a2,..aN}, he wants to know if there exists a subset, B={ai1,ai2,âŚaik} where 1â¤i1<i2<âŚ<ikâ¤NâŚ Link Sherlock and GCD Complexity: time complexity is O(N); space complexity is O(1) Execution: A subset has no common divisor if the GCD equals 1. There is an interesting fact that leads to my solution: If...

## HackerRank âSherlock and Pairsâ Solution

H

Short Problem Definition: Sherlock is given an array of N integers A0, A1 âŚ AN-1 by Watson. Now Watson asks Sherlock how many different pairs of indices i and j exist such that i is not equal to j but Ai is equal to Aj. That is, Sherlock has to count total number of pairs of indices (i, j) where Ai = Aj AND i â  j. Link Sherlock and Pairs Complexity: time complexity is O(n) space complexity is...

## HackerRank âSherlock and Squaresâ Solution

H

Short Problem Definition: Watson gives two integers A & B to Sherlock and asks if he can count the number of square integers between A and B (both inclusive). A square integer is an integer which is the square of any integer. For example, 1, 4, 9, 16 are some of the square integers as they are squares of 1, 2, 3, 4 respectively. Link Sherlock and Squares Complexity: time complexity is O(sqrt(N));...