# CategoryHackerRank

## 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 âMini-Max Sumâ Solution

H

Short Problem Definition: Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. Link Mini-Max Sum Complexity: time complexity is O(N) space complexity is O(1) Execution: Rather than recalculating the sum every...

## HackerRank âMinimum Time Requiredâ Solution

H

Short Problem Definition: You are planning production for an order. You have a number of machines that each have a fixed number of days to produce an item. Given that all the machines operate simultaneously, determine the minimum number of days to produce the required order. Link Minimum Time Required Complexity: time complexity is O(N*log(10*9)) space complexity is O(1) Execution: This problem...

## HackerRank âMissing Numbersâ Solution

H

Short Problem Definition: Numeros, the Artist, had two lists A and B, such that B was a permutation of A. Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers from A got left out. Can you find the numbers missing? Link Sherlock and Array Complexity: time complexity is O(n) space complexity is O(n) Execution: The problem...

## HackerRank âLargest Rectangleâ Solution

H

Short Problem Definition: There are NN buildings in a certain two-dimensional landscape. Each building has a height given by hi,iâ[1,N]hi,iâ[1,N]. If you join KK adjacent buildings, they will form a solid rectangle of area KĂmin(hi,hi+1,âŚ,hi+kâ1)KĂmin(hi,hi+1,âŚ,hi+kâ1). Given NN buildings, find the greatest such solid area formed by consecutive buildings. Link Largest Rectangle Complexity: time...

## HackerRank âNew Year Chaosâ Solution

H

Short Problem Definition: Itâs New Yearâs Day and everyoneâs in line for the Wonderland rollercoaster ride! There are a number of people queued up, and each person wears a sticker indicating their initial position in the queue. Initial positions increment by 1 from 1 at the front of the line to N at the back. Any person in the queue can bribe the person directly in front of them to...

## HackerRank âLeft Rotationâ Solution

H

Short Problem Definition: A left rotation operation on an array shifts each of the arrayâs elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]. Link Arrays: Left Rotation Complexity: time complexity is O(N) space complexity is O(N) Execution: Solutions like this is where python really shines. Simple and...

## HackerRank âNon-Divisible Subsetâ Solution

H

Short Problem Definition: Given a set S of n distinct integers, print the size of a maximal subset Sâ of S where the sum of any 2 numbers in Sâ are not evenly divisible by k. Link Non-Divisible Subset Complexity: time complexity is O(N) space complexity is O(N) Execution: This is by all means not an easy task and is also reflected by the high failure ratio of the participants. For a sum...