Python jr-3
Python jr-3
Questions
1. Provided a non-empty list of items, write a function to find all items which appear only once.
Input: [(1, 2), (3, 4), {'a': 'b'}, 'fine', 1, {'a': 'b'}, (3, 4), 1, 'fine', 'fine']
Output: (1, 2)
Explanation : The tuple (1, 2) appears only once where as tuple (3, 4) appears two times, the
dictionary appears two times, integer 1 appears two times, string 'fine' appears three times. The tuple
(1, 2) is the odd one out.
Input: [[]]
Output - []
Explanation: As the input list only contains one item which is another vacant list, this would be the
item with single occurrence. So the output is the vacant list item.
2. Given an array, replace every element with the next greatest element (greatest element on its right
side) in the array. Also, since there is no element next to the last element, replace it with -1.
Input: [2, 3, 1, 9]
Output: [9, 9, 9, -1]
Input: 4
Output:
1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
Input: 3
Output:
1 2 3 10 11 12
4589
67
4. Provided a positive integer as a parameter, write a function which returns a counting character
encoded sequence of the input integer.
Input: 1
output: 11
Explanation: Input has only one 1. We get 11 (Read as “one 1”) as output
input: 211
output : 1221
Explanation: Input has only one 2 and two 1s. Hence we get 1221 ( Read as “one 2 and two 1s” ) as
output
input: 1221
output: 112211
Explanation: Input has one 1, two 2s and one 1 again. Hence we get 112211 as output.