Skip to content

Commit

Permalink
Merge pull request ZoranPandovski#3294 from SaiSudhaV/master
Browse files Browse the repository at this point in the history
Group the similar characters in combinations and concatenate first and last elements alternatively
  • Loading branch information
ZoranPandovski authored Oct 11, 2022
2 parents f3c0730 + ea95ff1 commit a626f07
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Logical Problems/LexicographicalGrouping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def GroupRotation(s, n):
tem, res = [], ""
for i in sorted(set(s.lower())):
comb = [i for i in range(n) if s[i].lower() == s]
print(comb)
p = ""
for i in comb:
p += s[i]
tem.append(p)
m = len(tem)
for i in range(m // 2):
res += tem[i] + tem[-(i + 1)]
if m % 2:
res += tem[m // 2]
return res

if __name__ == "__main__":
s = input()
print(GroupRotation(s, len(s)))

0 comments on commit a626f07

Please sign in to comment.