1)Transmit a message:
Professor X has developed a new machine to transmit messages.The machine accepts a
message in the form of a string of characters and transmits it to another machine of the same type of
some other location. However the machine has a certain bug.It can transmit only one type of
characters.As soon as it encounters a different type of character, the message recorded till that point
is erased and the machine starts recording a new message beginning from that character.
Professor X wants to send the longest message possible to his friend.To do this, he can stop
the machine at any point and transmit the message by pressing the send button.However he can do
this only when the machine is in the recording mode and not the erasing mode.He wants your help.
Given the input string, your task is to find the longest possible message that can be delivered
by the machine.If there is more that one longest possible message, find the message which is nearer
to the end of the string.
Input : Input string S contains only characters with no spaces
I/P -1 : aabbcc I/P-2 : aabbddd
O/P : cc O/P : ddd
2)Max Contiquous Sequences:
Given an array of “n” integer numbers A(1)…..A(n), determine all contiguous subsequences
A(i)……A(j) of positive numbers.Write a function to find the sum of elements in each sub sequence and
output the maximum sum value.
Input1: Length of integer array input2[]
Input2: An integer array where elements range between {-10000 <= A(i) <= 10000}
Output:
Return the max sum of contiguous sub sequence of positive numbers
Example 1:
Input1 : 5
Input2 : [1,2,4,-2,3]
Output : 7
Explanation:
Here the contiguous sub sequences are {1,2,4} and {3}. The max sum of these sequences is 7.
Example 2:
Input1:5
Input2: [1,2,-3,4,-5]
Output: 4
Explanation:
Here the contiguous sub sequences are {1,2} and {4}. The max sum of these sequences is 4.
3)Bit reverse:
Given a 32 bit signed integers, write a function to return the integer formed by reversing its
bits.
Input:
A 32 bit signed integer value
Output:
Returns the signed value formed by reversing the bits of input
Example 1:
Input1: 2
Output: 1073741824
Explanation:
The 32 bit equivalent of 2 is 00000000 00000000 00000000 00000010. On reversing its bits we
get 01000000 00000000 00000000 00000000 which is the binary quivalent of 1073741824.
Example 2:
Input1 : 1
Output: -2147483648
Explanation:
The 32 bit equivalent of 1 is 00000000 00000000 00000000 0000001. On reversing its bits we
get 10000000 00000000 00000000 00000000 which is the binary quivalent of -2147483648.