title-img


Roads and Libraries

Determine the minimum cost to provide library access to all citizens of HackerLand. There are n cities numbered from 1 to n. Currently there are no libraries and the cities are not connected. Bidirectional roads may be built between any city pair listed in cities. A citizen has access to a library if: 1. Their city contains a library. 2. They can travel by road from their city to a city containing a library. unction Description Complete the function roadsAndLibraries in the editor be

View Solution →

Journey to the Moon

The member states of the UN are planning to send people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut ID's. Each pair is made of astronauts from the same country. Determine how many pairs of astronauts from different countries they can choose from. Function Description Complete the journeyToMoon function in the editor below. journeyToMoon has the following parameter(s): int n: the number of astronauts int astronaut[p][2

View Solution →

Is It a Snake

One day I was visiting a temple in which snakes were worshiped. I happened to find a golden plate of dimension 2 * n in it. It had 2 rows of n cells each, and so the total number of cells is 2 * n. Each cell of the plate was either white or black, denoted by '.' and '#' respectively. Legend says that a snake was lying on this plate for many years and prayed. So, the cells that were covered by its body have turned black, the rest of the cells were white. Its entire body was supposedly on this pla

View Solution →

Sum of Digits

You're given an integer N. Write a program to calculate the sum of all the digits of N. Input The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N. Output For each test case, calculate the sum of digits of N, and display it in a new line. Constraints 1 ≤ T ≤ 1000 1 ≤ N ≤ 1000000 Example Input 3 12345 31203 2123 Output 15 9 8

View Solution →

Bytelandian gold coins

In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit). You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. You have one gold coin. What is the maximum amount of American dollars you can get for it? Input T

View Solution →