Spider Algos Task 1
Spider Algos Task 1
ALGORITHMS
PROBLEM STATEMENT:
TASK 1(A) –
Decomposing binary strings
Sri Harsha is a very curious fellow. He started to wonder about binary numbers and how you can
represent them as strings. But, due to his exceptional nature, this was not enough for him. He
wondered if a binary string could be decomposed into the average of two different binary strings of
equal length as the original string.
If there are multiple answers, you need to print the strings that make the difference of 2 numbers
minimum.
Example: 1101 (13) can be expressed as the average of 1011 (11) and 1111 (15), or 1100 (12)
and 1110 (14), So the answer will be 1110 and 1100.
Note: length of both strings should be same and don’t use leading zeros until required.
Input Format
Constraints
Output Format
If it is not possible to print two strings pertaining to the conditions prescribed the print –1 on one
line.
Otherwise, output 2 space-separated strings with the first string being the lesser string and a string
here may start with one or more '0's.
https://inductions.spider.nitt.edu/
SPIDER INDUCTIONS 2021
Sample Input 0
4
1101
Sample Output 0
1100 1110
Examples:
A: The degree of symmetry is 0 as it cannot be divided.
ABAB : The degree of symmetry is 1. It can be divided only once into AB - AB which can’t be divided
further into equal strings.
AAAA: The degree of symmetry is 2.It can be divided into AA - AA, each AA can be further divided into
A-A which cannot be divided any further.
Input Format
Constraints
Output Format
Sample Input 0
1
a
Sample Output 0
0
Sample Input 1
https://inductions.spider.nitt.edu/
SPIDER INDUCTIONS 2021
4
aaaa
Sample Output 1
2
Sample Input 2
16
abcdefghhgfedcba
Sample Output 2
0
Sample Input 3
16
abababababababab
Sample Output 3
3
The team members become happy and hence the workshop turns out to be successful when the
head of the team make eat pizza on the same day.The initial money which the spider Algo team has
is Rs r. For every successful workshop their money increases by Rs x.For every unsuccessful
workshop their total decrease by Rs y. You have to determine the total money at the end of n days.
Input Format
The first line contains a positive integer n, r, x, y – the number of days under consideration, his
initial amount, increase after each Successful workshop , and the decrease in their total after each
unsuccessful workshop respectively . The second line contains the sequence of integers c 1 , c
2 , ..., c n separated by space, where: · c i equals 1 if a contest takes place on the i- th day; 0
otherwise. The third line contains the sequence of integers s 1 , s 2 , ..., s n separated by space,
where: · s i equals 1 if the team eats pizza on the i- th day; 0 otherwise.
Constraints
1 ≤ n ≤ 1000000
https://inductions.spider.nitt.edu/
SPIDER INDUCTIONS 2021
1 ≤ r ≤ 3000
1 ≤ x, y ≤ 100
0 ≤ c[i] ≤ 1
0 ≤ s[i] ≤ 1
Output Format
Print a single line containing the string “promoted”(without quotes) if the money the team earns is
greater than their initial amount. · Print a single line containing the string “demoted”(without
quotes) if the money is lesser than their initial amount. · Print “no change” otherwise.
Sample Input 0
5 426 75 22
01000
01001
Sample Output 0
promoted
Sample Input 1
4 1500 20 5
1001
1101
Sample Output 1
promoted
Input Format
The first line of input contains an integer 'T' representing the number of test cases.
Then each test case contains a single integer ‘N’ denoting the size of the pattern.
Constraints
1 <= T <= 5
3 <= N <= 500
https://inductions.spider.nitt.edu/
SPIDER INDUCTIONS 2021
Where ‘T’ is the number of test cases, ‘N’ is the size of the pattern. ‘N’ will be odd for all test cases.
Output Format
Sample Input 0
4
5
3
7
9
Sample Output 0
*****
** **
* *
** **
*****
***
**
***
*******
*** ***
** **
* *
** **
*** ***
*******
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
GUIDELINES:
The best practice anyone could do is solving question. We have complied few
questions. We want you to explore each topic and solve these questions while doing so. If you
are stuck or have any doubts you can always ping your mentor. Happy Coding :)
https://inductions.spider.nitt.edu/
SPIDER INDUCTIONS 2021
EVALUATION METRICS:
• Plagiarism of any sort will result in elimination
• These tasks will be followed by personal interviews and if candidates fail to
explain their concept and code, they will be eliminated
• Novel approaches will be rewarded
• Time Complexity and Space complexity for each solution will be considered for
evaluation.
SUBMISSION:
Submit your codes on hackerrank, you can find link here :contest
https://inductions.spider.nitt.edu/