1.
Joseph is learning digital logic subject which will be for his next semester. He usually tries to
solve unit assignment problems before the lecture. Today he got one tricky question. The
problem statement is “A positive integer has been given as an input. Convert decimal value to
binary representation. Toggle all bits of it after the most significant bit including the most
significant bit. Print the positive integer value after toggling all bits”.
Constraints :
1<=N<=100
Example 1:
Input :
10 -> Integer
Output :
5 -> result- Integer
Explanation:
Binary representation of 10 is 1010. After toggling the bits(1010), will get 0101 which represents
“5”. Hence output will print “5”.
__________________________________
2.
Airport security officials have confiscated several item of the passengers at the security check
point. All the items have been dumped into a huge box (array). Each item possesses a certain
amount of risk[0,1,2]. Here, the risk severity of the items represent an array[] of N number of
integer values. The task here is to sort the items based on their levels of risk in the array. The
risk values range from 0 to 2.
Example :
Input :
7 -> Value of N
[1,0,2,0,1,0,2]-> Element of arr[0] to arr[N-1], while input each element is separated by new line.
Output :
0 0 0 1 1 2 2 -> Element after sorting based on risk severity
Example 2:
input : 10 -> Value of N
[2,1,0,2,1,0,0,1,2,0] -> Element of arr[0] to arr[N-1], while input each element is separated by a
new line.
__________________________________
Question 3
Problem Description -: In this 3 Palindrome, Given an input string word, split the string into
exactly 3 palindromic substrings. Working from left to right, choose the smallest split for the first
substring that still allows the remaining word to be split into 2 palindromes.
Similarly, choose the smallest second palindromic substring that leaves a third palindromic
substring.
If there is no way to split the word into exactly three palindromic substrings, print “Impossible”
(without quotes). Every character of the string needs to be consumed.
Cases not allowed –
After finding 3 palindromes using above instructions, if any character of the original string
remains unconsumed.
No character may be shared in forming 3 palindromes.
Constraints
1 <= the length of input sting <= 1000
Input
First line contains the input string consisting of characters between [a-z].
Output
Print 3 substrings one on each line.
Time Limit
1
Examples
Example 1
Input
nayannamantenet
Output
nayan
naman
tenet
Explanation
The original string can be split into 3 palindromes as mentioned in the output.
However, if the input was nayanamantenet, then the answer would be “Impossible”.
Example 2
Input
aaaaa
Output
aaa
Explanation
The other ways to split the given string into 3 palindromes are as follows –
[a, aaa, a], [aaa, a, a], [aa, aa, a], etc.
Since we want to minimize the length of the first palindromic substring using left to right
processing, the correct way to split is [a, a, aaa].
Example 3
Input
aaaabaaaa
Output
aaabaaa
Explanation
The other ways to split the given string into 3 palindromes are as follows –
[aaaa, b, aaaa], [aa, aabaa, aa], etc.
Since we want to minimize the length of the first palindromic substring using left to right
processing, the correct way to split is [a, aaabaaa, a].
__________________________________
Problem Statement:-
Compute the nearest larger number by interchanging its digits [Link] 2 numbers a and
b find the smallest number greater than b by interchanging the digits of a and if not possible
print -1.
Input Format
2 numbers a and b, separated by space.
Output Format
A single number greater than b.
If not possible, print -1
Constraints
1 <= a,b <= 10000000
Example 1:
Sample Input:
459 500
Sample Output:
549
Example 2:
Sample Input:
645757 457765
Sample Output:
465577