Answered step by step
Verified Expert Solution
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:
If the index i of the string is divisible by then they can change the ith character to underscore and jump to the ith index, or they can simply skip that character and jump to the i th character in that string.
Similarly, if the index i of the string is divisible by then they can change the ith character to hash # and can skip all the characters in between by jumping straight to the i th index or they can simply skip that character and jump to the i th character in that string.
Similarly, if the index i of the string is neither divisible by or then you can simply skip that character and jump to i t character.
In case the ith index is divisible by both and and the total number of changes required to get to the starting index of the string are same for both and then divisibility by is to be prioritized.
The task is to return the manipulated message string.
NateTraversing an index of string counts as a step and indexing of string starts from
Input Specification:
input: An integer denoting the size of the message string
input: 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 :
input:
Input: abcdefghijk
Output: ab#defgh#jk
Explanation:
The last index of the string is which is not divisible by or so we can slop to the i index and stepCount
Now, the ith index is divisible by so we can skip to either the ith or ith index, We will skop to the ith index because this will require minimal changes in the string and stepCount
Now, the ith index is divisible by so we can skip to either the ith or i index. We will skip to i index because these will require minimal changes in the shing and stepCount also the i th character of the string is replaced by #
Now the ith index is divisible by so we can skip to either the i or i index. We will skip to the i index which is the st index, a and the stepCount and replace the i index by #
Example
input:
input: aabbcc output:aa#bc
write ccode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started