Logic Building
Logic Building
Write a function that takes two numbers in string format and forms a string containing the sum (addition) of
these two numbers
Assumption(s):
The lengths of the two input string need not be the same
For example -
If input strings are "1234" and "56" the output string should be "1290-
If input strings are '56" and "1234" the output string should be "1290
If input strings are 123456732128989543219" and "987612673489652" the output string should be
"123457719741663032871
NOTE: in Java & C#, this logic can be easily implemented using Biginteger However for the sake of
enhancing your programming skills, you are recommended to solve this question without using BigInteger
i.e. arr[i] = original value of arr[i] + original value of arr[i+1] e.g. value in arr[0] = original value of arr[0] +
original value of arr[1] Also note that value of last elemint i.e. arr[last index] remains unchanged.
For example,
If the encoded array is (7,6,8,16,12,3) The original array should have been (2,5,1,7,9,3)
Provided the encoded array, you are expected to find the - a. First number (value in index 0) in the original
array
STEP1. In each word, find the Sum of the Difference between the first letter and the last letter, second letter
and the penultimate letter, and so on fill the center of the word.
For example
STEP1. In each word, find the Sum of the Difference between the first letter and the
last letter, second letter and the penultimate letter, and so on till the center of the word. WORLD [W-
DJ+JOL+R) [23-4-15-12)+[18][199+3)+(18)[40] WIDE [W-E]+[1-DJ-123-5-19-41-118)-(5)-(21
WEB [W-B]+[E][23-2)+(5)-121]+5)+(26)
[402326]
NOTE1: The value of each letter is its position in the English alphabet system Le a=A=1, b=B=2, c=C-3,
and so on till 2-2-26 So, the result will be the same for "WORLD WIDE WEB" or "World Wide Web" or
"world wide web or any other combination of uppercase and lowercase letters
IMPORTANT Note: In Step1, after subtracting the alphabets, we should use the absolute values for
calculating the sum. For instance, in the below example, both [H-O] and [E-L] result in negative number -7,
but the positive number 7 (absolute value of -7) is used for calculating the sum of the differences
Hello
[H-O]+[E-L]+[L]=[8-15]+[5-12]+[12][7]+[7]+[12] = [26]
Assumptions: The given string (sentence) will contain only alphabet characters and there will be only one
space character between any two consecutive words.
You are expected to help Zak, by writing a function that takes a string (sentence) as input, performs the
above mentioned processing on the sentence and returns the result (number),
4 ) Decreasing sequence:
Given an integer array, find the number of decreasing sequences in the array and the length of its longest
decreasing sequence.
You are expected to complete the logic within the given function, where,
input1 represents the integer array and, input2 represents the number of elements in the integer array
The function should set the output1 variable to the number of decreasing sequences in the array, and set the
output2 variable to the length of the longest decreasing sequence in the array.
If the given number is 582109, the Sum of Powers of Digits will be calculated as = = (5 raised to the power
of 8) + (8 raised to the power of 2) + (2 raised to the power of 1) (1 raised to the power of 0) + (0 raised to
the power of 9) + (9 raised to the power of 0)
Let each digit of the number is raised to the power of the next digit on its right-side Note that the right-most
digit has to be raised to the power of 0. The sum of all of these powers is the expected result to be calculated.
Example If the given number is 582109, the Sum of Powers of Digits = = (5 raised to the power of 8) + (8
raised to the power of 2) + (2 raised to the power of 1)+ (1 raised to the power of 0) (0 raised to the power of
9) + (9 raised to the power of 0)
39062564+2+1+0+1=390693
Alex contacts you to help him write a program for finding the Sum of Powers of Digits for any given
number, using the above method.
Write the logic in the given function sumOfPowerOfDigits where input1 represents the given number.
Assumptions: For this assignment, let us assume that the given number will always contain more than 1
digit, ie the given number will always be >9
If the given number is 582109, the Sum of Sums of Digits will be calculated as =
(5+8+2+1+0+9)+(8+2+1+0+9)+(2+1+0+9)+(1+0+ 9)+(0+9)+(9) 25+20+12+10+9+9 = 85
Alex contacts you to help him write a program for finding the Sum of Sums of Digits for any given number,
using the above method.
Help Alex by completing the logic in the given function sumOfSumsOfDigits which takes as input an
integer input1 representing the given number. The function is expected to return the "Sum of Sums of
Digits" of input1.
Assumptions: For this assignment, let us assume that the given number will always contain more than 1
digit, i.e. the given number will always be >9.
You are expected to write a function to identify the set of possible words. The function identify Possible
Words takes two strings as input where,
input1 contains the incomplete word, and input2 is the string containing a set of words separated by colons.
The function is expected to find all the possible words from input2 that can replace the incomplete word
input1, and return the result in the format suggested below.
Example1 -
input1 = "Fi_er"
input2 = "Fever:filer:Filter:Fixer:fiber:fibre:tailor.offer
Note that -
• The output string should contain the set of all possible words that can replace the incomplete word in
input1
• While searching for input1 in input2, the case of the letters are ignored, i.e "Fi_er" matches with "filer" as
well as "Fixer" as well as "fiber".
• IMPORTANT: If none of the words in input2 are possible candidates to replace input1, the output string
should contain the string "ERROR-009"
Assumption(s):
• Input1 will contain only a single word with only 1 character replaced by an underscore""
• Input2 will contain a series of words separated by colons and NO space character in between
• Input2 will NOT contain any other special character other than underscore and alphabetic characters.
STEP ONE: Given any three strings, break each string into 3 parts each. For example - If the three strings
are as below
Input1 = "John"
Input2= "Johny"
Input3= "Janardhan"
"John" should be split into "J", "oh", "n" as the FRONT, MIDDLE and END parts
respectively. "Johny" should be split into "Jo", "h", "ny" as the FRONT, MIDDLE and END parts
respectively.
"Janardhan" should be split into "Jan", "ard", "han" as the FRONT, MIDDLE and END
parts respectively. i.e. if the no. of characters in the string are in multiples of 3, then each split-part will
If the no. of characters in the string are NOT in multiples of 3, and if there is one character more than
multiple of 3, then the middle part will get the extra character, as seen in the example of "John"
If the no. of characters in the string are NOT in multiples of 3, and if there are two characters more than
multiple of 3, then the FRONT and END parts will get one extra character each, as seen in the example of
"Johny"
STEP TWO: Concatenate (join) the FRONT, MIDDLE and END parts of the strings as per the below
specified concatenation-rule to form three Output strings. Output1 = FRONT part of Input1 + FRONT part
of Input2 + FRONT part of Input3 Output2 = MIDDLE part of Input1 + MIDDLE part of Input2 +
MIDDLE part of Input3 Output3 = END part of Input1 + END part of Input2 + END part of Input3 For
example, for the above specified example input strings. Output1 = "J" + "Jo" + "Jan" = "JJojan" Output2=
"oh" + "h" + "ard" = "ohhard"
Step THREE: After the first two steps, we will have three output strings. Further
processing is required only for the third output string as per below rule "Toggle the case of each character in
the string", i.e. in the third output string, all lower-case characters should be made upper-case and vice versa.
For example, for the above example strings, Output3 is "nnyhan", so after applying the toggle rule, Output3
should become "NNYHAN".
Final Result - The three output strings after applying the above three steps is the final result. i.e. for the
above example,
Output1 = "Dolan"
Output2 = "ohnard
Output3NNYHAN"
Anand approaches you to help him write a program that would do the above mentioned prosessing on any
given three strings and generate the resulting three output strings
Note that the three output strings should be returned as members of a "Result" object/struct