For a given value N, denoting the number of Charters starting from the A, print reverse character bridge pattern.
Examples :
Input : n = 5
Output :
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A
Input : n = 8
Output :
ABCDEFGHGFEDCBA
ABCDEFG GFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
- For a given value N, reflect the number of characters taking part in the pattern, starting from A. For N = 5, Participating character would be A B C D E.
- By using a nested for loop we would compute the logic. Where the outer loop of 'i' would range from 0 to N and the inner loop of 'j' would range from 65(Start) to 64 + 2*N.
- Under which we would check the required condition for the pattern design. For all the values of j which are less than ((64+n)+ i) it would print the (char)((64 + n)-( j % (64+n))) and for all the values of j <= ((64+n) -i) it would print (char)j.
OutputABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
Time Complexity: O(n2)
Auxiliary Space: O(1)