title-img


Angry Children 2

Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimize the cumulative difference in the number of candies in the packets he hands out. This is called the unfairness sum. Determine the minimum unfairness sum achievable. For example, he brings n = 7 packets where the number of candies is packets = [

View Solution →

Sherlock's Array Merging Algorithm

Watson gave Sherlock a collection of arrays V. Here each Vi is an array of variable length. It is guaranteed that if you merge the arrays into one single array, you'll get an array, M, of n distinct integers in the range [1,n]. Watson asks Sherlock to merge into a sorted array. Sherlock is new to coding, but he accepts the challenge and writes the following algorithm: M <- [ ] (an empty array). k <- number of arrays in the collection V. While there is at least one non-empty array

View Solution →

Prime Digit Sums

Chloe is fascinated by prime numbers. She came across the number 283002 on a sign and, though the number is not prime, found some primes hiding in it by using the following rules: Every three consecutive digits sum to a prime: 283002 283002 283002 283002 Every four consecutive digits sum to a prime: 283002 283002 283002 Every five consecutive digits sum to a prime: 283002 283002 You must answer q queries, where each query consists of an integer, n. For each n, find and print th

View Solution →

HackerRank City

HackerRank-city is an acyclic connected graph (or tree). Its not an ordinary place, the construction of the whole tree takes place in N steps. The process is described below: It initially has 1 node. At each step, you must create 3 duplicates of the current tree, and create 2 new nodes to connect all 4 copies in the following H shape: At each ith step, the tree becomes 4 times bigger plus 2 new nodes, as well as 5 new edges connecting everything together. The length of the new edges being

View Solution →

Summing Pieces

Consider an array, A, of length n. We can split A into contiguous segments called pieces and store them as another array, B. For example, if A = [1,2,3], we have the following arrays of pieces: B = [(1),(2),(3)] contains three 1-element pieces. B = [(1,2),(3)] contains two pieces, one having 2 elements and the other having 1 element. B = [(1),(2,3)] contains two pieces, one having 1 element and the other having 2 elements. B = [(1,2,3)] contains one 3-element piece. We consider the va

View Solution →