Question: Anyone could help me write this python program, I kinda need help understanding recursion. Write a recursive function printFlag(A) that takes an array of integers
Write a recursive function printFlag(A) that takes an array of integers as input, prints a flag-shape numbers from it such that the first level has all array elements. From then, at each level the number of elements is half less than the previous level and each element at the current level at position i is the sum of two elements in the previous level, where the first element is at the same position i and the second one is at position n-i, assuming n is the number of elements in the previous level. See the following example. Please also write a simple code to test this function. Example: Input: A = {1, 2, 3, 4, 5, 6, 7} Output: [1,2,3,4,5,6,7) [8, 8, 8] [16] Explanation: [1, 2, 3, 4, 5, 6, 7] --> (1 + 7 = 8,2 + 6 = 8, 3 + 5 = 8) --> [8, 8, 8] --> (8 + 8 = 16) --> [16]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
