0% found this document useful (0 votes)
64 views

Spider Algos Task 1

The document provides details of four algorithmic tasks: 1) Decomposing binary strings into the average of two equal length strings with minimum difference. 2) Determining the degree of symmetry in a string by counting how many times it can be evenly divided. 3) Calculating the final amount of money for a team over multiple days depending on whether their workshops are successful or not. 4) Printing patterns of spaces and asterisks of a given size based on sample inputs and outputs. The document also provides input/output formats, constraints, and sample test cases for each task. Guidelines and evaluation metrics for solving the tasks are mentioned at the end.

Uploaded by

Shubham Kaushal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Spider Algos Task 1

The document provides details of four algorithmic tasks: 1) Decomposing binary strings into the average of two equal length strings with minimum difference. 2) Determining the degree of symmetry in a string by counting how many times it can be evenly divided. 3) Calculating the final amount of money for a team over multiple days depending on whether their workshops are successful or not. 4) Printing patterns of spaces and asterisks of a given size based on sample inputs and outputs. The document also provides input/output formats, constraints, and sample test cases for each task. Guidelines and evaluation metrics for solving the tasks are mentioned at the end.

Uploaded by

Shubham Kaushal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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

The first line is the length of the string.


The second line is the string.

Constraints

Length of the string<=100000


The string is composed of zeroes or ones.

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

The strings should obey the conditions prescribed above.

Sample Input 0

4
1101
Sample Output 0
1100 1110

TASK 1(B) - Symmetry ?


Degree of symmetry is defined as the numbers of times you can divide (if can divide) a string such
that both the remaining half are equal to each other.

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

The First line contains an integer n denoting the length of string


The Second line contains a String of length n.

Constraints

1 <= Length of the String <= 1000000.


The Length of the String is always a Power of 2. (Note: 1 is a power of 2 (2^0))
The String consists of lowercase Alphabets Only.

Output Format

Print an Integer denoting the Degree of Symmetry.

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

TASK 1(C) – Determine the final amount


The SPIDER ALGO TEAM members have a strange connection with pizzas and the success of the
workshop on that day. We consider a duration of workshop be n days each numbered from 1 to n.
You are given following information about each day:

Whether they have a successful workshop on day i or not.

whether they eat pizza on day i or not.

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

TASK 1(D) – Complete the task


Priya likes to play with numbers. One day Priya decides to assign a task to her mentee Tanya. You
have to help Tanya to complete this task. Task is as follows - Priya gives sanya an integer N which is
always a odd number. Priya wants Tanya to make a pattern which consists of N rows and N
columns .Priya being Priya asked her to make pattern which will consist of ' '(space) and
*(character) only. For making Tanya understand the type of pattern she wants Priya gave her a
sample input and output.Your task is to Help tanya print the pattern.

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

For each test case, print the pattern.

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/

You might also like