|
| 1 | +""" |
| 2 | +@Author: Aseem Jain |
| 3 | +@Linkedin: https://www.linkedin.com/in/premaseem/ |
| 4 | +@Github: https://github.com/premaseem/pythonLab/tree/master/challenge |
| 5 | +
|
| 6 | +Given array, [1,2,5,6,8,9,23,34,35,36,45,56,57,58,99] |
| 7 | +
|
| 8 | +Represent as = [ 1,2,5-9,23,34-36,45,56-58,99] |
| 9 | +and represt complement as = [0, 3, 4, 7, '10-22', '24-33', '37-44', '46-55'] |
| 10 | +feed values in array, |
| 11 | +if value is arr is greater then 2, represent them in string of 0 and -1 element |
| 12 | +
|
| 13 | +""" |
| 14 | + |
| 15 | +a = [1,2,5,6,7,8,9,23,26,27,34,35,36,45,56,57,58,99] |
| 16 | +ans1 = [ 1,2,5-9,23,34-36,45,56-58,99] |
| 17 | + |
| 18 | +#algo |
| 19 | +t = [] |
| 20 | +ans = [] |
| 21 | +for e in range(1,100): |
| 22 | + if e in a: |
| 23 | + continue |
| 24 | + if not t or t[-1]+1 == e: |
| 25 | + t.append(e) |
| 26 | + else: |
| 27 | + if len(t) > 2: |
| 28 | + ans.append(str(t[0])+"-"+str(t[-1])) |
| 29 | + else: |
| 30 | + ans.extend(t) |
| 31 | + t = [e] |
| 32 | +print(ans) |
| 33 | + |
| 34 | +# main - [1, 2, '5-9', 23, 26, 27, '34-36', 45, '56-58'] |
| 35 | +# complementary - [3, 4, '10-22', 24, 25, '28-33', '37-44', '46-55'] |
| 36 | + |
| 37 | + |
0 commit comments