Hackerrank - Pairs Solution
You will be given an array of integers and a target value. Determine the number of pairs of array elements that have a difference equal to a target value. For example, given an array of [1, 2, 3, 4] and a target value…
You will be given an array of integers and a target value. Determine the number of pairs of array elements that have a difference equal to a target value. For example, given an array of [1, 2, 3, 4] and a target value…
Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss…
Given the time in numerals we may convert it into words, as shown below: At , use o' clock. For , use past, and for use to. Note the space between the apostrophe and clock in o' clock. Write a program which prints the…
Given a set of distinct integers, print the size of a maximal subset of where the sum of any numbers in is not evenly divisible by . For example, the array and . One of the arrays that can be created is . Another is…
Given an array of stick lengths, use of them to construct a non-degenerate triangle with the maximum possible perimeter. Print the lengths of its sides as space-separated integers in non-decreasing order. If there are…
In this challenge, you will be given a string. You must remove characters until the string is made up of any two alternating characters. When you choose a character to remove, all instances of that character must be…
You will be given a list of 32 bit unsigned integers. Flip all the bits ( and ) and print the result as an unsigned integer. For example, your decimal input . We're working with 32 bits, so: Function Description…
Consider two -element arrays of integers, and . You want to permute them into some and such that the relation holds for all where . For example, if , , and , a valid satisfying our relation would be and , and . You are…
Jim's Burgers has a line of hungry customers. Orders vary in the time it takes to prepare them. Determine the order the customers receive their orders. Start by numbering each of the customers from to , front of the…
Mark and Jane are very happy after having their first child. Their son loves toys, so Mark wants to buy some. There are a number of different toys lying in front of him, tagged with their prices. Mark has only a certain…
Lena is preparing for an important coding competition that is preceded by a number of sequential preliminary contests. Initially, her luck balance is 0. She believes in "saving luck", and wants to check her theory. Each…
Given a square grid of characters in the range ascii[a-z], rearrange elements of each row alphabetically, ascending. Determine if the columns are also in ascending alphabetical order, top to bottom. Return YES if they…
Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie count, and Marc can walk a distance to expend those calories. If Marc has eaten cupcakes so far, after eating a cupcake with calories he…
Consider an array of integers, . We define the absolute difference between two elements, and (where ), to be the absolute value of . Given an array of integers, find and print the minimum absolute difference between any…
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 : Append…
Given two strings, determine if they share a common substring. A substring may be as small as one character. For example, the words "a", "and", "art" share the common substring . The words "be" and "cat" do not share a…
We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact…
Two words are anagrams of one another if their letters can be rearranged to form the other word. In this challenge, you will be given a string. You must split it into two contiguous substrings, then determine the…
Given a string of lowercase letters in the range ascii[a-z], determine a character that can be removed to make the string a palindrome. There may be more than one solution, but any will do. For example, if your string…
James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes. To do this, he…