title-img


Morgan and a String

Jack and Daniel are friends. Both of them like letters, especially uppercase ones. They are cutting uppercase letters from newspapers, and each one of them has his collection of letters stored in a stack. One beautiful day, Morgan visited Jack and Daniel. He saw their collections. He wondered what is the lexicographically minimal string made of those two collections. He can take a letter from a collection only when it is on the top of the stack. Morgan wants to use all of the letters in thei

View Solution →

Build a String

Greg wants to build a string, S of length N. Starting with an empty string, he can perform 2 operations: 1. Add a character to the end of S for A dollars. 2. Copy any substring of S, and then add it to the end of S for B dollars. Calculate minimum amount of money Greg needs to build S. Input Format The first line contains number of testcases T. The 2 x T subsequent lines each describe a test case over 2 lines: The first contains 3 space-separated integers, , N , A and B, respec

View Solution →

Pseudo-Isomorphic Substrings

wo strings A and B, consisting of small English alphabet letters are called pseudo-isomorphic if Their lengths are equal For every pair (i,j), where 1 <= i < j <= |A|, B[i] = B[j], iff A[i] = A[j] For every pair (i,j), where 1 <= i < j <= |A|, B[i] != B[j] iff A[i] != A[j] Naturally, we use 1-indexation in these definitions and |A| denotes the length of the string A. You are given a string S, consisting of no more than 105 lowercase alphabetical characters. For every prefix of S denot

View Solution →

The Coin Change Problem

Given an amount and the denominations of coins available, determine how many ways change can be made for amount. There is a limitless supply of each coin type. Example n = 3 c = [8,3,1,2] There are 3 ways to make change for n=3: {1,1,1}, {1,2}, and {3}. Function Description Complete the getWays function in the editor below. getWays has the following parameter(s): int n: the amount to make change for int c[m]: the available coin denominations Returns int: the num

View Solution →

Equal

Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure everyone gets the same number. To make things difficult, she must equalize the number of chocolates in a series of operations. For each operation, she can give 1, 2 or 5 pieces to all but one colleague. Everyone who gets a piece in a round receives

View Solution →