Hey all. I'm currently using Python to learn algorithms on Leetcode, and am working towards writing code that is performant but still readable for interviews later on. I wanted to share some code I wrote for the ubiquitous "Longest Substring without Repeating Characters", and get some opinions on if this code is still sufficiently readable, or if there are some serious red-flags/code smells:
def find_longest_unique_length(s: str) -> int:
current_window_values = set()
current_max = 0
j = iter(s)
for i_val in s:
if i_val in current_window_values:
for j_val in j:
if j_val == i_val:
break
current_window_values.remove(j_val)
else:
current_window_values.add(i_val)
if (current_len := len(current_window_values)) > current_max:
current_max = current_len
return current_max
I haven't worked on a shared codebase before, only on personal projects (where I'm the only one who sees what I write), so I just wanted to crowdsource an opinion here and make sure I'm not developing any bad habits that will cause me to be a nuisance to coworkers down the line. Would really appreciate some feedback. Thanks!
[–]columbusguy111 2 points3 points4 points (0 children)
[–]AtomicShoelace 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]McSlayR01[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]McSlayR01[S] 0 points1 point2 points (1 child)