You are on page 1of 4

1) Digital Stream (1.

5)
A Digital Stream is an infinite sequence, where each term is the sum of the previous term and the sum of
the individual digits in it.
The first term is known as the seed.
Tn+1 = Tn + Sum of digits( Tn ) { for n>0 }
and T0 = Seed. { Seed >0 }

For Ex. a digital stream with seed 9 : 9, 18 (=9+9) , 27 (=18+1+8), 36 (=27+2+7), ...

Now given 2 digital streams we would like to know if they intersect or not (within a finite range say 0 -
4294967296).

Input : Seeds of 2 Digital Streams.


Output : Intersection point or -1 if they don’t.

2) Burning Forest (1)

A rectangular grid is laid out over a forest, by the wild life reserve department for easy management.
Some of these grid blocks contain dense population of trees, while others are barren.
If a fire starts in any of the densely forested grid block, it consumes every tree in that block, and spreads
to all adjacent forested block, and continues so forth. The fire dies out once it has consumed all the
forested block it could spread to from the initial block.
Given a grid, and the block from where the fire originated, we would like to see at what state the
fire dies off, and how many times it spread from one forested block to another adjacent forested block.

Input : Dimensions of the Grid, The layout of the grid (0=>forested area, 1=>empty area),
Coordinates of the block from where fire started.
Output : Final Status of the Grid & no. of times the fire spread from one block to another.

3) Paths (2.5)

A traveler is on his way across the city.


He starts from one landmark, and makes his way to another, and then another until he reaches his final
destination. An arbitrary (but finite number) of landmarks lie between the starting landmark and the
destination. Direct routes may not be present between every pair of landmarks. Also the traveler will not
visit a landmark more than once.
Given a layout of landmarks, we would like to know all possible paths the traveler might take from
a specified origin to the destination and the number of such paths.

Input : The number of landmarks, the layout in appropriate format, origin, destination

N (total no. of land marks, 0<N<2^32)

N1 (no. landmarks reachable from 1st land mark)


v1 v2 … v_N1 (the list of reachable land marks)
.
.
Nm
v1 v2 … v_Nm

S D
Output : All possible paths from origin to destination in apt format, and the number of such paths.
4) Bishop’s Reach (1.5)

Consider a 8X8 chess board numbered in the traditional way : A to H in the horizontal axis (from
lt. to rt), and 1 to 8 in the vertical axis (from bottom to top).
A Bishop can move diagonally to any square in the chess board.
Given a source square, we would like to know the number of moves the Bishop needs to move to
the specified destination square, if possible.

Input : T (no. of test cases ), followed by T lines of source and destination pairs (eg. A1 B3).
Output : Number of moves required or -1 if it’s unreachable for each such pair.

5) Ugly Numbers (2.5)

A number is said to be ugly if it’s only prime factors are 2,3, or 5.

For Ex. : 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15 are the first 11 ugly numbers. By convention, 1 is also included.

Now suppose we have a number say 123, which has 2 positions between the 3 digits. In these 2 positions
we can choose to place either a ‘+’, ‘-‘ or nothing to get different arithmetic expressions like 1+2+3 or
12+3 or 12-3. These expressions evaluate to 6,15,9 respectively which are all Ugly numbers. But an
expression like 1-23 (= -22), or 123 itself yield non Ugly numbers.

Given any number, we would like to know how many of the (possible) expressions (generated in the
above fashion) yield an Ugly number, and what are those expressions.

Input : N
Output : Number of ugly numbers generated & the corresponding expressions for N.

6) Alpha Codes (2.5)

Two spies want to communicate secretly. They had hastily designed a code, where a word is converted to
a number by replacing each letter by it’s equivalent numerical value (A takes the value 1 and Z 26).
For ex. “abc” or “ABC” is encrypted to 123.

But this scheme is inherently ambiguous as some encrypted message can be decrypted in multiple ways.
For Ex. : 25114 can be decrypted as “bean”,”beaad”,”yaad”,”yan”,”ykd”,”bekd” (ignoring case).

Given an encrypted message we would like to know how many different decryptions are possible.

Input : An encrypted word.


Output : Number of possible decryptions & the corresponding decryptions or -1 if it’s impossible to
decode.

7) Word Ring (3.5)

You want to figure out the combination to an archive your kid brother has left in your PC. Knowing
him you can probably guess the password. You know he likes to play with different anagrams of words
and line up the words such that they form a ring where the last character of each word is the first one of
the next.
Given a list of (your brother’s favorite words) and the number of words he will (probably) use as the
password , generate all possible anagram rings as mentioned above.
INPUT: N (total no.of words)
M (no. of words to use in password)
List of N words (1 per line)
OUTPUT:All possible password sequences (1 per line) and the number of such possible passwords
formed as mentioned above.

8) Bridge (3.5)

A group of n people wish to cross a bridge at night. At most two people may cross at
any time, and each group must have a flashlight. Only one flashlight is available among
the n people, so some sort of shuttle arrangement must be arranged in order to return
the flashlight so that more people may cross.
Each person has a different crossing speed; the speed of a group is determined by the
speed of the slower member. Your job is to determine a strategy that gets all n people
across the bridge in the minimum time.

INPUT :The input begins with a single positive integer on a line by itself indicating the number
of test cases, followed by a blank line. There is also a blank line between each two
consecutive test suite.
The first line of each case contains n, followed by n lines giving the crossing times
for each of the people. There are not more than 1,000 people and nobody takes more
than 100 seconds to cross the bridge.

OUTPUT :For each test case, the first line of output must report the total number of seconds
required for all n people to cross the bridge. Subsequent lines give a strategy for achieving
this time. Each line contains either one or two integers, indicating which person
or people form the next group to cross. Each person is indicated by the crossing time
specified in the input.
Note that the crossings alternate directions, as it is necessary to return the flashlight
so that more may cross. If more than one strategy yields the minimal time, any one
will do.
The output of two consecutive cases must be separated by a blank line.

9) Ones (2.5)

Given any integer 0 ≤ n ≤ 10, 000 not divisible by 2 or 5, some multiple of n is a number which in decimal
notation is a sequence of 1’s. How many digits are in the smallest such multiple of n?

INPUT :Multiple lines of integers at one integer per line.

OUTPUT :Each output line gives the smallest integer x > 0 such that p is a number consisting of only ‘1’s,
such that p = a × b, and b is an integer greater than zero, where a is the corresponding input integer.
Sample Input
3
7
Sample Output
3
6
10) Factovisors (2)

The factorial function, n! is defined as follows for all non-negative integers n:


0! = 1 and n! = n × (n − 1)! (n > 0)
We say that a divides b if there exists an integer k such that k × a = b

INPUT: The input to your program consists of several lines, each containing two non-negative
integers, n and m, both less than 2^32.

OUTPUT: For each input line, output a line stating whether or not m divides n!, in the format
shown below.

10000 divides 20!


100000 does not divide 20!
1009 does not divide 1000!

11) Stern-Brocot Numbers (2)

The Stern-Brocot tree is a beautiful way for constructing the set of all non-negative fractions m/n
where m and n are relatively prime. The idea is to start with two fractions 0/1 & 1/0
and then repeat the following operation as many times as desired:
Insert (m1+m2)/(n1+n2) between two adjacent fractions m1/n1 and m2/n2.
For example, the first step gives us one new entry between 0/1 and 1/0 :0/1, 1/1, 1/0
and the next gives two more:0/1,1/2,1/1,2/1,1/0, The next gives four more:
0/1, 1/3, 1/2, 2/3, 1/1, 3/2, 2/1, 3/1, 1/0
The entire array can be regarded as an infinite binary tree structure whose top levels
look like this–

We can regard the Stern-Brocot tree as a number system for representing


rational numbers, because each positive, reduced fraction occurs exactly once. Let us
use the letters “L” and “R” to stand for going down the left or right branch as we
proceed from the root of the tree to a particular fraction; then a string of L’s and R’s
uniquely identifies a place in the tree. For example, LRRL means that we go left from 1/1
down to 1/2, then right to 2/3, then right to 3/4, then left to 5/7.
1/1 is denoted by ‘I’

INPUT: T (no. of test cases); followed by fractions of the form m/n


OUTPUT : The Stern Brocot representation for each input fraction in a new line.

You might also like