Programming Question: Longest Substring without Repeating Character

Question Setup

Solution Description

Behavior of the Fast Pointer

Hit Pause, Advance Slow Pointer

Code for the Brain

class Solution:
@param s: a string
@return: an integer
def lengthOfLongestSubstring(self, s):
if len(s) == 0:
return 0
maxLength = 0
charCount = [0 for _ in range(256)]
slow = 0
for fast in range(len(s)):
charCount[ord(s[fast])] += 1
if charCount[ord(s[fast])] > 1:
while slow <= fast: #think through for while loop loging using example of string "abbcd" and "babcd"
charCount[ord(s[slow])] -= 1
slow += 1
if charCount[ord(s[fast])] == 1:
else: #(B)
maxLength = max(maxLength, fast - slow + 1)

return maxLength




Writing to soothe the soul, programming to achieve flow

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Auto Scale Azure SQL DB using Azure Logic Apps PowerShell Script and SQL Agent .

An Arc which completes cloud circle: Azure Arc

Schema Changes: Lessons Learnt from Hard Deploys

🤖 @SpaceGate_fi presents the second #YOLOS report with the incredible income procedure that ends…

The Exciting World of 3D Environments & Lighting

How to Maintain UPM Package Part 4: Managing Package Release with CLI

Responsive and adaptive UI in Flutter for Web/PWA

The symbol in Ruby — Explanation

The symbol in Ruby — Explanation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Writing to soothe the soul, programming to achieve flow

More from Medium

An Intro to Recursion

Instance method, Class method, and Static method

Check if the parenthesis/brackets in a string are balanced or not. Python and stack Data Structures