Skip to content
the poor coder

Home / Topics / #algorithms

#Algorithms

191 posts · page 9 of 10
2020

Hackerrank - Beautiful Pairs Solution

You are given two arrays, and , both containing integers. A pair of indices is beautiful if the element of array is equal to the element of array . In other words, pair is beautiful if and only if . A set containing…

2020

Hackerrank - Cats and a Mouse Solution

Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse doesn't move and the cats travel at…

2020

Hackerrank - Electronics Shop Solution

Monica wants to buy a keyboard and a USB drive from her favorite electronics store. The store has several models of each. Monica wants to spend as much as possible for the items, given her budget. Given the price lists…

2020

Hackerrank - Cut the sticks Solution

You are given a number of sticks of varying lengths. You will iteratively cut the sticks into smaller sticks, discarding the shortest pieces until there are none left. At each iteration you will determine the length of…

2020

Hackerrank - Library Fine Solution

Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows: If the book is returned on or…

2020

Hackerrank - Drawing Book Solution

Brie’s Drawing teacher asks her class to open their books to a page number. Brie can either start turning pages from the front of the book or from the back of the book. She always turns pages one at a time. When she…

2020

Hackerrank - Sock Merchant Solution

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…

2020

Hackerrank - Bon Appétit Solution

Anna and Brian are sharing a meal at a restaurant and they agree to split the bill equally. Brian wants to order something that Anna is allergic to though, and they agree that Anna won't pay for that item. Brian gets…

2020

Hackerrank - Migratory Birds Solution

You have been asked to help study the population of birds migrating across the continent. Each type of bird you are interested in will be identified by an integer value. Each time a particular kind of bird is spotted…

2020

Hackerrank - Birthday Chocolate Solution

Lily has a chocolate bar that she wants to share it with Ron for his birthday. Each of the squares has an integer on it. She decides to share a contiguous segment of the bar selected such that the length of the segment…

2020

Hackerrank - Grading Students Solution

HackerLand University has the following grading policy: Every student receives a in the inclusive range from to . Any less than is a failing grade. Sam is a professor at the university and likes to round each student's…

2020

Hackerrank - Sequence Equation Solution

Given a sequence of integers, where each element is distinct and satisfies . For each where , find any integer such that and print the value of on a new line. For example, assume the sequence . Each value of between and…

2020

Hackerrank - Append and Delete Solution

You have a string of lowercase English alphabetic letters. You can perform two types of operations on the string: Append a lowercase English alphabetic letter to the end of the string. Delete the last character in the…

2020

Hackerank - Save the Prisoner! Solution

A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A…

2020

Hackerrank - Between Two Sets Solution

You will be given two arrays of integers and asked to determine all integers that satisfy the following two conditions: The elements of the first array are all factors of the integer being considered The integer being…

2020

Hackerrank - Encryption Solution

An English text needs to be encrypted using the following encryption scheme. First, the spaces are removed from the text. Let be the length of this text. Then, characters are written into a grid, whose rows and columns…

ESC