FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interview/python/recursion/stringpermutation.py at master · ankursd/interview · GitHub
ankursd
interview
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
interview
/
python
/
recursion
/
stringpermutation.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (30 loc) · 900 Bytes
Breadcrumbs
interview
/
python
/
recursion
/
stringpermutation.py
Copy path
File metadata and controls
35 lines (30 loc) · 900 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# string permutation in lexicographically order with repetition of characters in the string
def
permute
(
input
):
count_map
=
{}
for
ch
in
input
:
if
ch
in
count_map
.
keys
():
count_map
[
ch
]
=
count_map
[
ch
]
+
1
else
:
count_map
[
ch
]
=
1
keys
=
sorted
(
count_map
)
str
=
[]
count
=
[]
for
key
in
keys
:
str
.
append
(
key
)
count
.
append
(
count_map
[
key
])
result
=
[
0
for
x
in
range
(
len
(
input
))]
permute_util
(
str
,
count
,
result
,
0
)
def
permute_util
(
str
,
count
,
result
,
level
):
if
level
==
len
(
result
):
print
(
result
)
return
for
i
in
range
(
len
(
str
)):
if
count
[
i
]
==
0
:
continue
;
result
[
level
]
=
str
[
i
]
count
[
i
]
-=
1
permute_util
(
str
,
count
,
result
,
level
+
1
)
count
[
i
]
+=
1
if
__name__
==
'__main__'
:
input
=
[
'B'
,
'C'
,
'A'
,
'A'
]
permute
(
input
)
Back
|
FazBrowse Home
|
New Git URL