Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Day 1 of Solving LeetCode Problems: Tackling Problem #3

Today, I decided to challenge myself with LeetCode Problem 3: Longest Substring Without Repeating Characters. As someone who enjoys solving algorithmic problems, I thought this would be a walk in the park—a cup of coffee while coding, so t…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Today, I decided to challenge myself with LeetCode Problem 3: Longest Substring Without Repeating Characters. As someone who enjoys solving algorithmic problems, I thought this would be a walk in the park—a cup of coffee while coding, so to speak.

Well… I was in for a little surprise.

After writing my initial solution, I ran it against the LeetCode test cases. Out of 988 cases, 987 passed. But one stubborn test case failed. I realized it was probably a load test meant to check how efficient my solution really was. Even though it didn’t fully pass, this exercise taught me a lot about handling substrings, avoiding repeated characters, and thinking about efficiency.





Let me walk you through my journey.






Understanding the Problem

The problem sounds simple at first:

Given a string, find the length of the longest substring without repeating characters.

For example:

• "abcabcbb" → Longest substring: "abc" → length = 3

• "bbbbb" → Longest substring: "b" → length = 1

• "pwwkew" → Longest substring: "wke" → length = 3

Sounds easy, right? But implementing it efficiently is a bit tricky.






My First Attempt

Here’s the first function I wrote:

var lengthOfLongestSubstring = function (str) {

let arr = str.split('');

let mainLeft = 0;

let subLeft = 0;

let right = subLeft + 1;

let subStrArr = [];

let subStr = 0;




subStrArr.push(arr[subLeft]);
while (mainLeft < arr.length) {
if (right < arr.length) {
if ((!(arr[subLeft] === arr[right])) & !subStrArr.includes(arr[right])) {
subStrArr.push(arr[right]);
right++;
} else {
if (subStrArr.length > subStr) subStr = subStrArr.length;
subStrArr = [];
subLeft = right;
subStrArr.push(arr[subLeft]);
right++;
}
} else {
if (subStrArr.length > subStr) subStr = subStrArr.length;
mainLeft++;
subStrArr = [];
subLeft = mainLeft;
subStrArr.push(arr[subLeft]);
right = subLeft + 1;
}
}
return subStr;




};

At first glance, it’s messy—but each part has a purpose. Here’s the breakdown:






Step 1: Preparing the String

let arr = str.split('')

I converted the string into an array of characters to make it easier to access individual elements. For example, "abc" becomes ['a', 'b', 'c'].






Step 2: Defining Pointers

let mainLeft = 0;

let subLeft = 0;

let right = subLeft + 1;

• mainLeft: Keeps track of where to start exploring new substrings.

• subLeft: Marks the start of the current substring without repeats.

• right: Moves forward to expand the substring until a repeat is found.






Step 3: Tracking Substrings

let subStrArr = [];

let subStr = 0;

subStrArr.push(arr[subLeft]);

• subStrArr keeps the current substring we are building.

• subStr stores the length of the longest substring found so far.






Step 4: Iterating Through the String

I used a while loop to explore all possible substrings starting from mainLeft. Inside, I either expand the substring or reset it when a repeated character shows up.






Step 5: Expanding and Resetting

When the current character isn’t in subStrArr, I add it and move right forward. If it’s a repeat, I check if the current substring is the longest, reset, and start from the next position.






Reflection

The solution worked for most cases, but it failed on the load test. Why?

• Using an array and includes check is O(n) for each character.

• Nested iterations make the worst-case O(n²).

For large strings, this approach becomes inefficient.






The Efficient Solution: Sliding Window

Here’s the optimized solution I found on the LeetCode discussion:

var lengthOfLongestSubstring = function (s) {

let set = new Set();

let left = 0;

let maxLen = 0;



for (let right = 0; right < s.length; right++) {

while (set.has(s[right])) {

set.delete(s[left]);

left++;

}

set.add(s[right]);

maxLen = Math.max(maxLen, right - left + 1);

}



return maxLen;

};






How It Works




  1. Sliding Window:
    o We keep a “window” [left, right] of non-repeating characters.
    o left moves forward if a duplicate is found.

  2. Using a Set:
    o set.has() and set.delete() are O(1), so we avoid scanning the substring repeatedly.

  3. Expanding and Contracting:
    o Move right forward to include new characters.
    o If a repeat is found, remove characters from left until it’s gone.

  4. Updating Maximum Length:

  5. maxLen = Math.max(maxLen, right - left + 1);
    o This calculates the current substring length and updates the maximum.
    ________________________________________



Complexity

• Time Complexity: O(n) → each character is processed at most twice.

• Space Complexity: O(min(n, m)) → m is the character set size (e.g., 128 for ASCII).






Conclusion

Solving this problem was an eye-opener. My first solution worked but wasn’t efficient. The sliding window approach not only passes all test cases but also handles large strings efficiently.

This exercise reinforced the importance of:

• Using appropriate data structures

• Thinking about time complexity

• Sliding window technique for substring problems

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - Day 1 of Solving LeetCode Problems: Tackling Problem #3
id: 40c2e5a0-7dc5-45cb-a996-28bf5c7fecfc
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-26
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-26"
        description = "YARA Signature for "
    strings:
        $str = "Day 1 of Solving LeetCode Prob" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Day 1 of Solving LeetCode Problems Tackl")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Day 1 of Solving LeetCode Problems Tackl*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Day 1 of Solving LeetCode Problems Tackl"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Day 1 of Solving LeetCode Problems: Tack.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 1 of Solving LeetCode Problems: Tackling Problem #3

Thematisch verwandte Begriffe: Solving, LeetCode, Problems, Tackling · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100534 | OpenClaw versions before 2026.8.1 contain an authorization bypass vulne…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag