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

Mahdi Shamlou | Solving LeetCode #1: Two Sum — The Classic Hash Map Solution

Hey everyone! I’m Mahdi Shamlou, and I’m starting a new series on classic LeetCode problems. Let’s kick it off with the very first one: Problem #1 — Two Sum. This is an Easy difficulty problem, but it’s legendary — it’s often the very fi…

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

Hey everyone! I’m Mahdi Shamlou, and I’m starting a new series on classic LeetCode problems. Let’s kick it off with the very first one: Problem #1 — Two Sum.





This is an Easy difficulty problem, but it’s legendary — it’s often the very first question in coding interviews at big tech companies. Solving it optimally shows you understand one of the most powerful tools in programming: hash maps (dictionaries in Python).

Problem Statement: Two Sum



Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to target.



You may assume that each input has exactly one solution, and you may not use the same element twice. You can return the answer in any order.



Examples:




Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: nums[0] + nums[1] = 2 + 7 = 9

Input: nums = [3,2,4], target = 6
Output: [1,2]

Input: nums = [3,3], target = 6
Output: [0,1]






The Optimal Approach: One-Pass Hash Map



The brute force way would be to check every pair with two nested loops — that’s O(n²) time, which is too slow for large arrays.



Instead, we use a dictionary to store numbers we’ve seen so far and their indices.

Become a member



As we iterate through the array:



For each number nums[i], calculate the target_less:

target — nums[i] 0 If the target_less is already in the dictionary, we’ve found our pair!

Otherwise, add the current number and its index to the dictionary.

This is one pass through the array → O(n) time and O(n) space.



Here’s the Python solution:




class Solution(object):
def twoSum(self, nums, target):
dict_key = {}

for i, num in enumerate(nums):
target_less = target - num

if target_less in dict_key:
return [dict_key[target_less], i]

dict_key[num] = i






Why is this approach great?



Super efficient: Beats 95%+ of submissions on LeetCode in time

Clean and readable: Easy to explain in interviews

Handles edge cases perfectly : like duplicate numbers



If you know other methods feel free to share in the comments! I’d love to learn and maybe create a separate post about them 🚀



Any questions? I’m happy to help!



Connect with me:



🔗 LinkedIn: https://www.linkedin.com/in/mahdi-shamlou-3b52b8278



📱 Telegram: https://telegram.me/mahdi0shamlou



📸 Instagram: https://www.instagram.com/mahdi0shamlou/



Author: Mahdi Shamlou | مهدی شاملو

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - Mahdi Shamlou | Solving LeetCode #1: Two Sum — The Classic Hash Map Solution
id: 77f4d971-2175-4939-bc7c-d5e6d0da4561
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
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-27"
        description = "YARA Signature for "
    strings:
        $str = "Mahdi Shamlou | Solving LeetCo" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Mahdi Shamlou  Solving LeetCode 1 Two Su")
| 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: "*Mahdi Shamlou  Solving LeetCode 1 Two Su*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Mahdi Shamlou  Solving LeetCode 1 Two Su"
| 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:

Analyse für identifizierte Bedrohung auf Basis von Live-CTI (ENISA EUVD): CVSS 0.0 · EPSS 0.0% · CISA KEV: nein. Handlungsableitung aus den verlinkten Hersteller-Quellen.

🛡️ 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.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Mahdi Shamlou | Solving LeetCode #1: Two Sum — The Classic Hash Map Solution

Thematisch verwandte Begriffe: Mahdi, Shamlou, Solving, LeetCode · 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 ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100739 | A vulnerability was detected in mathurvishal CloudClassroom-PHP-Project…
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