Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions tasks/elementary/collections/max_abs_elem.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ tags = ["collections"]
time_to_solve_sec = 150

description_en = """
Find the maximum absolute value of an array.
Find the number in array with the maximum absolute value. If there are several of such numbers, return the largest one.
"""

description_ru = """
Найдите максимальное по модулю число в массиве.
Найдите максимальное по модулю число в массиве. Если их несколько, верните наибольшее.
"""

limits = """
- $-100 \\leq arr[i] \\leq 100$
- $2 \\leq \\text{len}(arr) \\leq 20$
- $1 \\leq \\text{len}(arr) \\leq 20$
"""

solution = """
def solution(arr: list[int]) -> int:
return max(abs(x) for x in arr)
min_num, max_num = min(arr), max(arr)
return min_num if abs(min_num) > abs(max_num) else max_num
"""

examples = """
solution([-1, -1]) == 1
solution([1, -2, 3, 4]) == 4
solution([2, 0, -16, -1]) == 16
solution([2, 0, -16, -1]) == -16
solution([122, -113, 100]) == 122
"""

Expand All @@ -46,12 +47,12 @@ expected = 4
[[asserts]]
arguments = [[2, 0, -16, -1]]
comment = "Negative has largest absolute value"
expected = 16
expected = -16

[[asserts]]
arguments = [[-1, -1]]
comment = "All same negative values"
expected = 1
expected = -1

[[asserts]]
arguments = [[122, -113, 100]]
Expand All @@ -71,7 +72,7 @@ expected = 5
[[asserts]]
arguments = [[-10, -10, -10]]
comment = "All same negative values"
expected = 10
expected = -10

[[asserts]]
arguments = [[1, 2, 3, 4, 5]]
Expand All @@ -81,7 +82,7 @@ expected = 5
[[asserts]]
arguments = [[-1, -2, -3, -4, -5]]
comment = "Descending negative sequence"
expected = 5
expected = -5

[[asserts]]
arguments = [[10, -10]]
Expand All @@ -91,22 +92,22 @@ expected = 10
[[asserts]]
arguments = [[-50, 49]]
comment = "Negative slightly larger"
expected = 50
expected = -50

[[asserts]]
arguments = [[49, -50]]
comment = "Positive slightly smaller"
expected = 50
expected = -50

[[asserts]]
arguments = [[100, -99, 0, 1]]
comment = "Maximum positive dominates"
expected = 100

[[asserts]]
arguments = [[-100, 99, 0, 1]]
arguments = [[-100, 99, 0, -1]]
comment = "Maximum negative dominates"
expected = 100
expected = -100

[[asserts]]
arguments = [[0, 1, -1]]
Expand All @@ -116,7 +117,7 @@ expected = 1
[[asserts]]
arguments = [[15, -20, 10, -5]]
comment = "Random mixed values"
expected = 20
expected = -20

[[asserts]]
arguments = [[7, 14, 21, 28]]
Expand All @@ -126,12 +127,12 @@ expected = 28
[[asserts]]
arguments = [[-7, -14, -21, -28]]
comment = "Multiples of 7 descending negative"
expected = 28
expected = -28

[[asserts]]
arguments = [[33, -44, 55, -66]]
comment = "Alternating signs increasing magnitude"
expected = 66
expected = -66

[[asserts]]
arguments = [[-1, 0, 1, 2]]
Expand All @@ -141,7 +142,7 @@ expected = 2
[[asserts]]
arguments = [[80, -85, 70, -60]]
comment = "Large values close together"
expected = 85
expected = -85

[[asserts]]
arguments = [[12, 34, -56, 78]]
Expand All @@ -151,7 +152,7 @@ expected = 78
[[asserts]]
arguments = [[-12, -34, 56, -78]]
comment = "Various two-digit numbers negative heavy"
expected = 78
expected = -78

[[asserts]]
arguments = [[3, -3, 6, -6, 9]]
Expand All @@ -161,7 +162,7 @@ expected = 9
[[asserts]]
arguments = [[25, -30, 35, -40]]
comment = "Multiples of 5 ascending magnitude"
expected = 40
expected = -40

[[asserts]]
arguments = [[1, 1, 1, -1, -1]]
Expand All @@ -176,14 +177,24 @@ expected = 21
[[asserts]]
arguments = [[-95, -90, -85, 80]]
comment = "Large negatives with one positive"
expected = 95
expected = -95

[[asserts]]
arguments = [[42, -43, 44, -45]]
comment = "Numbers around 40 alternating"
expected = 45
expected = -45

[[asserts]]
arguments = [[8, 16, -24, 32]]
comment = "Multiples of 8"
expected = 32

[[asserts]]
arguments = [[67]]
comment = "Single positive number"
expected = 67

[[asserts]]
arguments = [[-20]]
comment = "Single negative number"
expected = -20
2 changes: 1 addition & 1 deletion tasks/medium/collections/longest_winter_holiday.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ examples = """
solution([1], 0) == 1
solution([0], 1) == 1
solution([1, 0, 1], 1) == 3
solution([1, 0, 0, 1], 1) == 3
solution([1, 0, 0, 1], 1) == 2
solution([1, 1, 0, 0, 1, 1], 2) == 6
"""

Expand Down
55 changes: 38 additions & 17 deletions tasks/medium/strings/reverse_with_capitalize.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,32 @@ limits = """

solution = """
def solution(sentence: str) -> str:
def reverse_word(word):
if not word:
return word
punct = ''
if word[-1] in '.!?':
punct = word[-1]
word = word[:-1]
if not word:
return punct
had_upper = any(char.isupper() for char in word)
reversed_word = word[::-1].lower()
if had_upper:
reversed_word = reversed_word[0].upper() + reversed_word[1:].lower()
return reversed_word + punct
return ' '.join(reverse_word(word) for word in sentence.split())
sentence += "$"
res = ""
word, upper = [], []
for ch in sentence:
if ch.isalpha():
word.append(ch.lower())
upper.append(ch.isupper())
elif ch in "'-":
word.append(ch)
else:
word.reverse()
k = 0
for c in word:
if c.isalpha():
if upper[k]:
c = c.upper()
k += 1
res += c
word, upper = [], []
res += ch
return res[:-1]
"""

examples = """
solution("Hello! Are you.") == "Olleh! Era uoy."
solution("11Helloworld!") == "Dlrowolleh11!"
solution("11Helloworld!") == "11Dlrowolleh!"
solution("Abstraction is often one floor above you.") == "Noitcartsba si netfo eno roolf evoba uoy."
"""

Expand All @@ -56,7 +62,7 @@ expected = "Olleh! Era uoy."
[[asserts]]
arguments = ["11Helloworld!"]
comment = "With numbers and punctuation"
expected = "Dlrowolleh11!"
expected = "11Dlrowolleh!"

[[asserts]]
arguments = ["Abstraction is often one floor above you."]
Expand Down Expand Up @@ -197,3 +203,18 @@ expected = "Peed Gninrael"
arguments = ["Artificial Intelligence"]
comment = "AI full term"
expected = "Laicifitra Ecnegilletni"

[[asserts]]
arguments = ["WOW That's Amazing!"]
comment = "An apostrophe inside a word"
expected = "WOW S'taht Gnizama!"

[[asserts]]
arguments = ["Do you like my T-shirt?"]
comment = "A hyphen inside a word"
expected = "Od uoy ekil ym Trihs-t?"

[[asserts]]
arguments = ["My BFF lives in Arden-Arcade and works at the AT'n'T shop."]
comment = "Very complicated sentence"
expected = "Ym FFB sevil ni EdacrA-nedra dna skrow ta eht T'N'tA pohs."