k = 2
is the simplest scenario, and if it's impossible
with k = 2
, it's also impossible with
k >= 3
.
When we think about k = 3
, the first character of
t1
must be different from last characters of
t2
and t3
, but the condition is more strict
than thinking about only t1
v.s. t2
.
Therefore, I only consider k = 2
for simplicity's sake.
(not very confident about the explanation).
When k = 2
, we just have to check if there is a pair of
(t1, t2)
where
t1[0] != t2[-1] and t1[-1] != t2[0]
.
def possible(n: int, s: list[str]) -> bool:
for i in range(n - 1):
if s[i] != s[i + 1]:
return s[0] != s[n - 1]
return False
for _ in range(int(input())):
n: int = int(input())
s: list[str] = list(input())
if possible(n, s):
print("YES")
else:
print("NO")
Codeforces Round 968 (Div. 2) Editorial
A necessary condition for
s
to be good is thats1 != sn
.
For a string
s
wheres1 != sn
, lett1
be a string composed of just the simple characters1
, and lett2
be a string composed of then - 1
characters froms2
tosn
.
In this way, the condition is satisfied.
Therefore, if
s1
!=sn
, the answer is “Yes”; otherwise, the answer is “No”.
I misunderstood the problem. I thought t2
's first
character must not be equal to t1
's last character, but the
condition is
For all
1 <= i < j <= k
, the first character ofti
isn't equal to the last character oftj
. We only have to compare the first character ofti
with the last characters of strings come afterti
.
The answer is as simple as
for _ in range(int(input())):
n: int = int(input())
s: str = input()
if s[0] != s[-1]:
print("YES")
else:
print("NO")
discuss.python.org: Three month suspensions for a Core Developer
Lunduke’s blog: Python Bans Prominent Dev for Enjoying the Wrong Old SNL Sketch
When Tim Peters won the 2017 Python Distinguished Service Award, he had already been working on Python for over 20 years.
I didn't know that Tim has such a long history with the Python community.
The Register: Core Python developer suspended for three months
Python's sorting algorithm is known as Timsort, which is a combination of Merge sort and Insertion sort. The best-case time complexity of the Insertion Sort is O(n), and leveraging the fact improves the time complexity of Merge Sort, which is O(nlogn) at best. As I remember correctly, the reason why Quick Sort is not used is that Quick Sort does not retain the order of elements.
Most implementations of quicksort are not stable, meaning that the relative order of equal sort items is not preserved.
Even an amateur programmer like myself knows the name Tim Peters, who is the inventor of Timsort. Also, he is known as an author of “Zen of Python,” which heavily impacted my life as a programmer.
It's surprising to know that he has been suspended from the Python council.
Most of the communications happening seem to be private, but as far as I read the Chris's blog and Lunduke's one, the suspension of Tim seems to be unreasonable.
I don't have enough information to judge the situation, and I also don't have the power to influence the community, but I just hope the Python community and its ecosystem will not fall apart.
Rice 400 Meat and Potatos 500 Protein bars 400 Protein shake 200 Salad 400 Yogurt 200
Total 2100 kcal
10k walking
MUST:
TODO: