|
| 1 | +# The extended part of the repository starts from this page. Previous 94 problems were collected from the repository mentioned in intro. The following problems are collected from Hackerrank and other resources from internet.All the given solutions are in python 3. |
| 2 | + |
| 3 | +# Question 95 |
| 4 | + |
| 5 | +### **Question** |
| 6 | + |
| 7 | +>***Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.*** |
| 8 | +
|
| 9 | +>***If the following string is given as input to the program:*** |
| 10 | +>``` |
| 11 | +>5 |
| 12 | +>2 3 6 6 5 |
| 13 | +>``` |
| 14 | +>***Then, the output of the program should be:*** |
| 15 | +>``` |
| 16 | +>5 |
| 17 | +>``` |
| 18 | +### Hints |
| 19 | +> ***Pending*** |
| 20 | +
|
| 21 | +---------------------- |
| 22 | +**My Solution: Python 3** |
| 23 | +```python |
| 24 | +n = int(input()) |
| 25 | +arr = map(int, input().split()) |
| 26 | +arr = list(set(arr)) |
| 27 | +arr.sort() |
| 28 | +print(arr[-2]) |
| 29 | +``` |
| 30 | +--------------------- |
| 31 | + |
| 32 | +# Question 96 |
| 33 | + |
| 34 | +### **Question** |
| 35 | + |
| 36 | +>***You are given a string S and width W. |
| 37 | +Your task is to wrap the string into a paragraph of width.*** |
| 38 | + |
| 39 | +>***If the following string is given as input to the program:*** |
| 40 | +>``` |
| 41 | +>ABCDEFGHIJKLIMNOQRSTUVWXYZ |
| 42 | +>4 |
| 43 | +>``` |
| 44 | +>***Then, the output of the program should be:*** |
| 45 | +>``` |
| 46 | +>ABCD |
| 47 | +>EFGH |
| 48 | +>IJKL |
| 49 | +>IMNO |
| 50 | +>QRST |
| 51 | +>UVWX |
| 52 | +>YZ |
| 53 | +>``` |
| 54 | +
|
| 55 | +### Hints |
| 56 | +> ***Pending*** |
| 57 | +
|
| 58 | +---------------------- |
| 59 | +
|
| 60 | +**My Solution: Python 3** |
| 61 | +```python |
| 62 | +import textwrap |
| 63 | +
|
| 64 | +def wrap(string, max_width): |
| 65 | + string = textwrap.wrap(string,max_width) |
| 66 | + string = "\n".join(string) |
| 67 | + return string |
| 68 | +
|
| 69 | +if __name__ == '__main__': |
| 70 | + string, max_width = input(), int(input()) |
| 71 | + result = wrap(string, max_width) |
| 72 | + print(result) |
| 73 | +``` |
| 74 | +--------------------- |
| 75 | + |
| 76 | +# Question 97 |
| 77 | + |
| 78 | +### **Question** |
| 79 | + |
| 80 | +>***You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)*** |
| 81 | +
|
| 82 | +>***Different sizes of alphabet rangoli are shown below:*** |
| 83 | +>``` |
| 84 | +>#size 3 |
| 85 | +> |
| 86 | +>----c---- |
| 87 | +>--c-b-c-- |
| 88 | +>c-b-a-b-c |
| 89 | +>--c-b-c-- |
| 90 | +>----c---- |
| 91 | +> |
| 92 | +>#size 5 |
| 93 | +> |
| 94 | +>--------e-------- |
| 95 | +>------e-d-e------ |
| 96 | +>----e-d-c-d-e---- |
| 97 | +>--e-d-c-b-c-d-e-- |
| 98 | +>e-d-c-b-a-b-c-d-e |
| 99 | +>--e-d-c-b-c-d-e-- |
| 100 | +>----e-d-c-d-e---- |
| 101 | +>------e-d-e------ |
| 102 | +>--------e-------- |
| 103 | +>``` |
| 104 | +### Hints |
| 105 | +>***Pending*** |
| 106 | +
|
| 107 | +---------------------- |
| 108 | +**My Solution: Python 3** |
| 109 | +```python |
| 110 | +
|
| 111 | +import string |
| 112 | +def print_rangoli(size): |
| 113 | + n = size |
| 114 | + alph = string.ascii_lowercase |
| 115 | + width = 4 * n - 3 |
| 116 | +
|
| 117 | + ans = [] |
| 118 | + for i in range(n): |
| 119 | + left = '-'.join(alph[n - i - 1:n]) |
| 120 | + mid = left[-1:0:-1] + left |
| 121 | + final = mid.center(width, '-') |
| 122 | + ans.append(final) |
| 123 | +
|
| 124 | + if len(ans) > 1: |
| 125 | + for i in ans[n - 2::-1]: |
| 126 | + ans.append(i) |
| 127 | + ans = '\n'.join(ans) |
| 128 | + print(ans) |
| 129 | +
|
| 130 | +
|
| 131 | +if __name__ == '__main__': |
| 132 | + n = int(input()) |
| 133 | + print_rangoli(n) |
| 134 | +``` |
| 135 | +--------------------- |
| 136 | + |
| 137 | + |
| 138 | +# Question 98 |
| 139 | + |
| 140 | +### **Question** |
| 141 | + |
| 142 | +>***You are given a date. Your task is to find what the day is on that date.*** |
| 143 | +
|
| 144 | +**Input** |
| 145 | +>***A single line of input containing the space separated month, day and year, respectively, in MM DD YYYY format.*** |
| 146 | +>``` |
| 147 | +>08 05 2015 |
| 148 | +>``` |
| 149 | +
|
| 150 | +
|
| 151 | +**Output** |
| 152 | +>***Output the correct day in capital letters.*** |
| 153 | +>``` |
| 154 | +>WEDNESDAY |
| 155 | +>``` |
| 156 | +
|
| 157 | +
|
| 158 | +---------------------- |
| 159 | +### Hints |
| 160 | +> ***Pending*** |
| 161 | +
|
| 162 | +---------------------- |
| 163 | +
|
| 164 | +**Solution:** |
| 165 | +```python |
| 166 | +import calendar |
| 167 | +
|
| 168 | +month, day, year = map(int, input().split()) |
| 169 | +
|
| 170 | +dayId = calendar.weekday(year, month, day) |
| 171 | +print(calendar.day_name[dayId].upper()) |
| 172 | +``` |
| 173 | +---------------- |
| 174 | + |
| 175 | + |
| 176 | +# Question 99 |
| 177 | + |
| 178 | +### **Question** |
| 179 | + |
| 180 | +>***Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either M or N but do not exist in both.*** |
| 181 | +
|
| 182 | +**Input** |
| 183 | +>***The first line of input contains an integer, M.The second line contains M space-separated integers.The third line contains an integer, N.The fourth line contains N space-separated integers.*** |
| 184 | +>``` |
| 185 | +>4 |
| 186 | +>2 4 5 9 |
| 187 | +>4 |
| 188 | +>2 4 11 12 |
| 189 | +>``` |
| 190 | +
|
| 191 | +**Output** |
| 192 | +>***Output the symmetric difference integers in ascending order, one per line.*** |
| 193 | +>``` |
| 194 | +>5 |
| 195 | +>9 |
| 196 | +>11 |
| 197 | +>12 |
| 198 | +>``` |
| 199 | +
|
| 200 | +
|
| 201 | +---------------------- |
| 202 | +### Hints |
| 203 | +> ***Pending*** |
| 204 | +
|
| 205 | +---------------------- |
| 206 | +
|
| 207 | +**Solution:** |
| 208 | +```python |
| 209 | +if __name__ == '__main__': |
| 210 | + n = int(input()) |
| 211 | + set1 = set(map(int,input().split())) |
| 212 | +
|
| 213 | + m = int(input()) |
| 214 | + set2 = set(map(int, input().split())) |
| 215 | +
|
| 216 | + ans = list(set1 ^ set2) |
| 217 | + ans.sort() |
| 218 | + for i in ans: |
| 219 | + print(i) |
| 220 | +``` |
| 221 | +---------------- |
0 commit comments