Python Programs
Python Programs
P1) Given two sorted Lists A and B of size p and q, write a Python
program to merge elements of A with B by maintaining the sorted
order i.e. fill A with first p smallest elements and fill B with remaining
elements.
Example:
Input :
int[] A = { 1, 5, 6, 7, 8, 10 }
int[] B = { 2, 4, 9 }
Output:
Sorted Arrays:
A: [1, 2, 4, 5, 6, 7]
B: [8, 9, 10]
P3) Write a Python program to find all triplets equal to a given sum in a
unsorted set of elements. Example:
Input :
nums = { 1, 6, 3, 0, 8, 4, 1, 7 }
Output:
Triplets of sum 7
(0 1 6)
(0 3 4)
Output:
(())
()()
Example 2:
Input: n = 3 (number of parenthesis)
Output:
((()))
(()())
(())()
()(())
()()()
P9) You have given a string. There can have multiple special
characters inside the string. Write a program to reverse the given
string. The position of the special characters should not be changed.
Example:
Input: 'abc/defgh$ij'
Output: 'jih/gfedc$ba'
If the two different characters have the same frequency, these letters
should be sorted based on their alphabetical order.
Example:
Input String:
csestack
Output String:
aektccss