Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is a security department in country ABC. When they transfer information to another department, the information is sent by manipulating the original message. Manipulation

There is a security department in country ABC. When they transfer information to another department, the information is sent by manipulating the original message. Manipulation is done in such a way that there are very few changes in the original message and the number of steps is minimum.
They start their manipulation from the last index and continue till they reach the start of the string while checking for the following conditions:-
1. If the index (i) of the string is divisible by 2, then they can change the (i)th character to underscore (_) and jump to the (i/2)th index, or they can simply skip that character and jump to the (i -1)^(th) character in that string.
2. Similarly, if the index (i) of the string is divisible by 3, then they can change the (i)^(th) character to hash (#) and can skip all the characters in between by jumping straight to the (i /3)^(th) index or they can simply skip that character and jump to the (i -1)^(th) character in that string.
3. Similarly, if the index (i) of the string is neither divisible by 2 or 3 then you can simply skip that character and jump to (i -1)^ t character.
4. In case the (i)^(th) index is divisible by both 2 and 3, and the total number of changes required to get to the starting index of the string are same for both 2 and 3, then divisibility by 2 is to be prioritized.
The task is to return the manipulated message string.
Nate-Traversing an index of string counts as a step and indexing of string starts from
Input Specification:
input1: An integer denoting the size of the message string
input2: A string denoting the original message.
Output Specification:
Your function must return the manipulated message string with a minimum number of changes in the original message.
Example 1:
input1: 11
Input2: abcdefghijk
Output: ab#defgh#jk
Explanation:
1. The last index of the string is 11 which is not divisible by 2 or 3. so we can slop to the (i-1) index and stepCount=1
2. Now, the i^th index 10, is divisible by 2 so we can skip to either the (i-1)th or (i/2)th index, We will skop to the (i-1)th index because this will require minimal changes in the string and stepCount=2
3. Now, the (i)th index 9, is divisible by 3 so we can skip to either the (i-1)th or (i/3) index. We will skip to (i/3) index because these will require minimal changes in the shing and stepCount=3 also the (i) th character of the string is replaced by #
4. Now the (i)th index 3, is divisible by 3 so we can skip to either the (i-1) or (i/3) index. We will skip to the (i/3) index which is the 1st index, 'a', and the stepCount=4 and replace the (i) index by #
Example 2
input1:6
input2: aabbcc output:aa#bc_
write c++code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

Graph inequality. y -2

Answered: 1 week ago

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago

Question

Define indirect financial compensation (employee benefits).

Answered: 1 week ago

Question

Describe the selection decision.

Answered: 1 week ago