You want it to be composed of two smaller staves of equal length so that you can either use it as a single staff or as two smaller ones.
You want the full sized staff's center of gravity to be exactly in the middle of the staff.
You have a very, very long branch from which you can cut the pieces for your
staff. The mass of the branch varies significantly throughout it, so you use
just any two pieces of the same length. Given a description of the mass
throughout the branch, determine the longest staff you can make, then return
three integers on a single line, the first two indicatin...
Facebook interview question
Two players are plaing a game. There is number n written on a black board. The game is played as following:
Each time a player chooses an integer number (0 <= k) so that 2^k is less than n and (n-2^k) has as beautiful as n. Next he removes n from blackboard and writes n-2^k instead. The player that can not continue the game (there is no such k that satisfies the constrains) looses the game.
The First player starts the game and they play in turns alternatively. Knowing that both two players play optimally you have to specify the winner.
First line of the Input contains an integer T, the number of testcase. 0 <= T &...
Game playing problem
You want to know the count all possible numbers that the game administrator can shout.
First line of the input contain an integer T, the number of testcases. Then
follow T testcases. For each test case the input is of the following format.
In the first line there are two numbers N and K. In each of next N lines there
is an integer a_i followed by a_i integers, ith line describes the list for
ith person. All the numbers in all the lists are uniq...
Decode messages encoded with Substitution Cipher
The exact character mappings that are used in the substitution ciphers will not be known to you. However, the dictionary of words that were used will be given. You will be given multiple encoded messages to decode (one per line) and they may use different substitution ciphers. The same substitution cipher is used on all of the words in a particular message.
For each scrambled message in the input, your program should output a line
with the input line, f...
You are the ruler of an enemy kingdom and have devised a plan to destroy Byteland. Your plan is to destroy all the roads in Byteland disrupting all communication. If you attack any road, the armies from both the cities that the road connects comes for its defense. You realize that your attack will fail if there are soldiers from both armies A and B defending any road.
So you decide that before carrying out this plan, you will attack some of the
cities and defeat the army located in the city to make ...
Sort array of 3 distinct integers
For example input: 121221123323
Find a matrix of 3x3 such that each row, column and diagonal forms a valid word in the dictionary
How can you implement regex matching?
The regular expression supports only * and .
_ means the character can come any number of times
. means single occurrence of any character
So an expression like a_abb_ should be able to match strings such as
ab, aaab, abbb, aabbbb and so on.
And an expression like ._ab.* should be matched with any string containing at least one occurrence of 'ab'
How to find the kth largest element of an array