Skip to content

Commit 210941d

Browse files
committed
Add more tasks
1 parent 150ffd9 commit 210941d

File tree

4 files changed

+684
-85
lines changed

4 files changed

+684
-85
lines changed

tasks/easy/isomorphic_strings.toml

Lines changed: 74 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
11
level = "easy"
22
name = "isomorphic_strings"
3-
tags = ["strings"]
4-
time_to_solve_sec = 280
3+
tags = ["string"]
4+
time_to_solve_sec = 240
55

66
description_en = """
7-
Given two strings, determine if they are isomorphic.
7+
Determine if two strings are isomorphic.
88
9-
Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
9+
Two strings are isomorphic if the characters in the first string can be replaced to get the second string. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
1010
"""
1111

1212
description_ru = """
13-
Даны две строки, определите изоморфны ли они.
13+
Определите, являются ли две строки изоморфными.
1414
15-
Две строки являются изоморфными, если символы в одной строке можно заменить так, чтобы получить другую строку. Все вхождения определенного символа должны быть заменены другим символом, с сохранением порядка символов. Два различных символа не могут быть отражены на один и тот же итоговый, но символ может быть отражен на самого себя.
15+
Две строки являются изоморфными, если символы в первой строке можно заменить так, чтобы получить вторую строку. Все вхождения определенного символа должны быть заменены другим символом, с сохранением порядка символов. Два различных символа не могут быть отражены на один и тот же итоговый, но символ может быть отражен на самого себя.
1616
"""
1717

1818
limits = """
19-
- $0 \\leq \\text{len}(s1) \\leq 1000$
20-
- $\\text{len}(s1) = \\text{len}(s2)$
19+
- $1 \\leq |s_1|, |s_2| \\leq 100$
20+
- $|s_1| = |s_2|$
2121
"""
2222

2323
solution = """
2424
def solution(s1: str, s2: str) -> bool:
25-
if len(s1) != len(s2):
26-
return False
27-
28-
def get_pattern(s):
29-
mapping = {}
30-
pattern = []
31-
for c in s:
32-
if c not in mapping:
33-
mapping[c] = len(mapping)
34-
pattern.append(mapping[c])
35-
return pattern
36-
37-
return get_pattern(s1) == get_pattern(s2)
25+
def pattern(s):
26+
m = {}
27+
return [m.setdefault(c, len(m)) for c in s]
28+
return pattern(s1) == pattern(s2)
3829
"""
3930

4031
examples = """
41-
solution("aa", "bb") == True
42-
solution("ca", "ab") == True
4332
solution("egg", "add") == True
4433
solution("foo", "bar") == False
45-
solution("aabb", "abab") == False
34+
solution("paper", "title") == True
4635
"""
4736

4837
[[input_signature]]
@@ -60,27 +49,27 @@ name = "boolean"
6049

6150
[[asserts]]
6251
arguments = ["egg", "add"]
63-
comment = "Classic isomorphic example"
52+
comment = "Both have same pattern"
6453
expected = true
6554

6655
[[asserts]]
6756
arguments = ["paper", "title"]
68-
comment = "Word isomorphism"
57+
comment = "Pattern match"
6958
expected = true
7059

7160
[[asserts]]
7261
arguments = ["ca", "ab"]
73-
comment = "Simple two letter isomorphism"
62+
comment = "Two char match"
7463
expected = true
7564

7665
[[asserts]]
7766
arguments = ["aa", "bb"]
78-
comment = "Same letter repeated"
67+
comment = "Repeated char"
7968
expected = true
8069

8170
[[asserts]]
8271
arguments = ["aedor", "eiruw"]
83-
comment = "Five letter isomorphism"
72+
comment = "Five char isomorphic"
8473
expected = true
8574

8675
[[asserts]]
@@ -90,120 +79,120 @@ expected = false
9079

9180
[[asserts]]
9281
arguments = ["aabb", "abab"]
93-
comment = "Different pattern"
82+
comment = "Different patterns"
9483
expected = false
9584

9685
[[asserts]]
97-
arguments = ["", ""]
98-
comment = "Empty strings"
99-
expected = true
100-
101-
[[asserts]]
102-
arguments = ["a", "a"]
103-
comment = "Single same character"
86+
arguments = ["abc", "def"]
87+
comment = "All unique same pattern"
10488
expected = true
10589

10690
[[asserts]]
107-
arguments = ["a", "b"]
108-
comment = "Single different characters"
91+
arguments = ["abcd", "abcd"]
92+
comment = "Identical strings"
10993
expected = true
11094

11195
[[asserts]]
112-
arguments = ["abc", "def"]
113-
comment = "Simple sequence"
114-
expected = true
96+
arguments = ["ab", "aa"]
97+
comment = "Different pattern"
98+
expected = false
11599

116100
[[asserts]]
117-
arguments = ["abc", "abc"]
118-
comment = "Identical strings"
119-
expected = true
101+
arguments = ["badc", "baba"]
102+
comment = "Not matching"
103+
expected = false
120104

121105
[[asserts]]
122-
arguments = ["aba", "bab"]
106+
arguments = ["abba", "cddc"]
123107
comment = "Palindrome pattern"
124108
expected = true
125109

126110
[[asserts]]
127-
arguments = ["abba", "cddc"]
128-
comment = "Mirror pattern"
111+
arguments = ["abcabc", "xyzxyz"]
112+
comment = "Repeating sequence"
129113
expected = true
130114

131115
[[asserts]]
132-
arguments = ["abcd", "abcd"]
133-
comment = "All unique same"
116+
arguments = ["abc", "bca"]
117+
comment = "Rotated still isomorphic"
134118
expected = true
135119

136120
[[asserts]]
137-
arguments = ["abcabc", "xyzxyz"]
138-
comment = "Repeating pattern"
121+
arguments = ["aba", "bab"]
122+
comment = "Simple alternating"
139123
expected = true
140124

141125
[[asserts]]
142-
arguments = ["aabbcc", "xxyyzz"]
143-
comment = "Paired pattern"
126+
arguments = ["abab", "baba"]
127+
comment = "Alternating patterns"
144128
expected = true
145129

146130
[[asserts]]
147-
arguments = ["abba", "abab"]
148-
comment = "Different symmetry"
131+
arguments = ["aaa", "abc"]
132+
comment = "All same vs all different"
149133
expected = false
150134

151135
[[asserts]]
152-
arguments = ["abcdefg", "hijklmn"]
153-
comment = "All unique mapping"
154-
expected = true
136+
arguments = ["abc", "aaa"]
137+
comment = "All different vs all same"
138+
expected = false
155139

156140
[[asserts]]
157-
arguments = ["aaa", "bbb"]
158-
comment = "All same repeated"
141+
arguments = ["abcdef", "uvwxyz"]
142+
comment = "Six unique characters"
159143
expected = true
160144

161145
[[asserts]]
162-
arguments = ["abc", "aaa"]
163-
comment = "Unique to same not valid"
164-
expected = false
146+
arguments = ["aabbcc", "xxyyzz"]
147+
comment = "Paired pattern"
148+
expected = true
165149

166150
[[asserts]]
167-
arguments = ["aaa", "abc"]
168-
comment = "Same to unique not valid"
151+
arguments = ["hello", "world"]
152+
comment = "Different word patterns"
169153
expected = false
170154

171155
[[asserts]]
172-
arguments = ["ab", "aa"]
173-
comment = "Two to one mapping invalid"
156+
arguments = ["abcd", "aaaa"]
157+
comment = "Unique vs repeated"
174158
expected = false
175159

176160
[[asserts]]
177-
arguments = ["aa", "ab"]
178-
comment = "One to two mapping invalid"
179-
expected = false
161+
arguments = ["aaaa", "bbbb"]
162+
comment = "All same both"
163+
expected = true
180164

181165
[[asserts]]
182-
arguments = ["abcabc", "defdef"]
183-
comment = "Repeating blocks"
166+
arguments = ["abcde", "abced"]
167+
comment = "All unique isomorphic"
184168
expected = true
185169

186170
[[asserts]]
187-
arguments = ["abcabc", "defghi"]
188-
comment = "Repeat vs unique"
189-
expected = false
171+
arguments = ["book", "deer"]
172+
comment = "Both have double letters"
173+
expected = true
190174

191175
[[asserts]]
192-
arguments = ["hello", "world"]
193-
comment = "Two l's vs unique"
194-
expected = false
176+
arguments = ["title", "paper"]
177+
comment = "Reverse of test 2"
178+
expected = true
195179

196180
[[asserts]]
197-
arguments = ["hello", "abccd"]
198-
comment = "Same double letter pattern"
181+
arguments = ["noon", "peep"]
182+
comment = "Palindrome pattern match"
199183
expected = true
200184

201185
[[asserts]]
202-
arguments = ["badc", "baba"]
203-
comment = "Different occurrence patterns"
186+
arguments = ["test", "best"]
187+
comment = "Different patterns"
204188
expected = false
205189

206190
[[asserts]]
207-
arguments = ["abcdefghij", "jihgfedcba"]
208-
comment = "All unique different order"
191+
arguments = ["rat", "car"]
192+
comment = "Three letter words"
193+
expected = true
194+
195+
[[asserts]]
196+
arguments = ["abcabc", "defdef"]
197+
comment = "Double pattern"
209198
expected = true

0 commit comments

Comments
 (0)