Zum Hauptinhalt springen
LIVE
CVSS 7.0CVE-2026-138158 | libgphoto2 through 2.5.34 contains a stack buffer overflow in sierra_get_string_register() that lets a malicious sierra-protocol camera or USB device overwrite stack memory. When files are listed, the device can answer the file-name register with an oversized packet, writing up to 32 KB past small stack buffers to cause crashes or possible code execution.CVSS 7.7CVE-2026-138159 | edbrowse through 3.8.19 contains an integer overflow in stringAndBytes() that allows malicious servers to write past a heap buffer by sending response bodies larger than 2 GB. When a user browses to an attacker-controlled HTTP, FTP, or gopher server, the oversized body skips reallocation and corrupts the heap, causing crashes or potentially code execution.CVSS 8.5CVE-2026-138160 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.CVSS 8.5CVE-2026-138161 | Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.CVSS 7.3CVE-2026-138162 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.CVSS 8.5CVE-2026-138163 | Gammu before 1.45.2 contains a heap-based buffer overflow in ReadWAPSettingsEntry() that allows attackers to corrupt heap memory via crafted backup files with excess WAP or MMS settings entries. Attackers can supply a backup with more than four TitleNN keys in a [WAPSettings] or [MMSSettings] section, loaded via convertbackup, restore, or GSM_ReadBackupFile, causing crashes or potential code execution.CVSS 4.8CVE-2026-138164 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in SaveBackupText() in backtext.c that allows attackers to corrupt stack memory by supplying long text fields. Attackers can craft a backup with long calendar or note fields that, when converted with gammu convertbackup, writes hex digits past the 10,000-byte stack buffer.CVSS 9.3CVE-2026-138154 | POSTAL 2 before build 26810491 contains a sandbox escape vulnerability that allows malicious Steam Workshop mods to execute code by calling ConsoleCommand with a start file URI. Attackers can ship a batch file in a mod at the predictable workshop install path and launch it via ShellExecuteW, executing commands as the player on Windows.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Maximum Width of Binary Tree

Given the root of a binary tree, return the **## Problem Statement Given the root of a binary tree, return the maximum width of the tree. The width of a level…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
CVE & Threat-Kontext · 6 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Given the root of a binary tree, return the **## Problem Statement



Given the root of a binary tree, return the maximum width of the tree.



The width of a level is defined as:




Distance between the leftmost
and rightmost non-null nodes
(including null nodes in between).












Brute Force Intuition



In an interview, you can explain it like this:




Perform a level-order traversal and count the number of nodes at each level.




However, this is incorrect because missing (null) nodes between two existing nodes also contribute to the width.



Example:




        1
/ \
2 3
/ \
4 5






Level 3 has only two nodes,



but its width is:




4






not 2.









Complexity




  • Time Complexity: O(N)

  • Space Complexity: O(N)









Moving Towards the Optimal Approach



Treat the binary tree as if it were stored in an array.



Assign every node an index.



Rules:




Root → 0






For every node:




Left Child

↓

2 * index + 1









Right Child

↓

2 * index + 2






Now,



Width of a level becomes:




Last Index

-

First Index

+

1












Pattern Recognition



Whenever you see:




  • Width of Binary Tree

  • Complete Binary Tree Positioning



Think:



Level Order Traversal + Indexing









Key Observation



Store inside the queue:




(Node, Index)






For every level:




First Index

↓

Last Index






Width:




last - first + 1;






To prevent integer overflow,



normalize indices at every level.









Optimal Approach






Step 1



Perform BFS.



Queue stores:




(Node, Index)












Step 2



For every level,



store:




Minimum Index






Subtract it from every index.



This keeps numbers small.









Step 3



Track:




First Index

↓

Last Index












Step 4



Update answer:




last - first + 1;












Optimal Java Solution






class Pair {

TreeNode node;
int index;

Pair(TreeNode node, int index) {

this.node = node;
this.index = index;
}
}

class Solution {

public int widthOfBinaryTree(TreeNode root) {

if (root == null)
return 0;

Queue<Pair> q = new LinkedList<>();

q.offer(new Pair(root, 0));

int ans = 0;

while (!q.isEmpty()) {

int size = q.size();

int minIndex = q.peek().index;

int first = 0;
int last = 0;

for (int i = 0; i < size; i++) {

Pair curr = q.poll();

int index = curr.index - minIndex;

if (i == 0)
first = index;

if (i == size - 1)
last = index;

if (curr.node.left != null)

q.offer(new Pair(
curr.node.left,
2 * index + 1));

if (curr.node.right != null)

q.offer(new Pair(
curr.node.right,
2 * index + 2));
}

ans = Math.max(ans,
last - first + 1);
}

return ans;
}
}












Dry Run






          1
/ \
2 3
/ \
4 5






Assign indices:




          0
/ \
1 2
/ \
3 6












Level 1



Indices:




0






Width:




1












Level 2



Indices:




1

2






Width:




2












Level 3



Indices:




3

6






Width:




6 - 3 + 1

=

4






Answer:




4












Why Indexing Works?



The assigned indices represent the positions of nodes in a complete binary tree.



Even if some nodes are missing,



their positions are preserved.



Thus,




Last Index

-

First Index

+

1






correctly measures the actual width.









Complexity Analysis




















Metric Complexity
Time Complexity O(N)
Space Complexity O(N)








Interview One-Liner




Perform a level-order traversal while assigning complete binary tree indices to each node. The width of each level is the difference between the first and last indices plus one.










Pattern Learned






Level Order

↓

Assign Indices

↓

First Index

↓

Last Index

↓

Maximum Width









Similar Problems




  • Maximum Width of Binary Tree

  • Complete Binary Tree

  • Left View

  • Right View

  • Vertical Order Traversal









Memory Trick



Think:




Root → 0

↓

Left = 2i + 1

↓

Right = 2i + 2

↓

Width

=

Last - First + 1









Mental Model






BFS

↓

(Node, Index)

↓

Track First & Last

↓

Update Maximum Width






Whenever you hear:




"Maximum Width of Binary Tree"




your brain should immediately think:



Level Order Traversal + Complete Binary Tree Indexing .



The width of a level is defined as:




Distance between the leftmost
and rightmost non-null nodes
(including null nodes in between).












Brute Force Intuition



In an interview, you can explain it like this:




Perform a level-order traversal and count the number of nodes at each level.




However, this is incorrect because missing (null) nodes between two existing nodes also contribute to the width.



Example:




        1
/ \
2 3
/ \
4 5






Level 3 has only two nodes,



but its width is:




4






not 2.









Complexity




  • Time Complexity: O(N)

  • Space Complexity: O(N)









Moving Towards the Optimal Approach



Treat the binary tree as if it were stored in an array.



Assign every node an index.



Rules:




Root → 0






For every node:




Left Child

↓

2 * index + 1









Right Child

↓

2 * index + 2






Now,



Width of a level becomes:




Last Index

-

First Index

+

1












Pattern Recognition



Whenever you see:




  • Width of Binary Tree

  • Complete Binary Tree Positioning



Think:



Level Order Traversal + Indexing









Key Observation



Store inside the queue:




(Node, Index)






For every level:




First Index

↓

Last Index






Width:




last - first + 1;






To prevent integer overflow,



normalize indices at every level.









Optimal Approach






Step 1



Perform BFS.



Queue stores:




(Node, Index)












Step 2



For every level,



store:




Minimum Index






Subtract it from every index.



This keeps numbers small.









Step 3



Track:




First Index

↓

Last Index












Step 4



Update answer:




last - first + 1;












Optimal Java Solution






class Pair {

TreeNode node;
int index;

Pair(TreeNode node, int index) {

this.node = node;
this.index = index;
}
}

class Solution {

public int widthOfBinaryTree(TreeNode root) {

if (root == null)
return 0;

Queue<Pair> q = new LinkedList<>();

q.offer(new Pair(root, 0));

int ans = 0;

while (!q.isEmpty()) {

int size = q.size();

int minIndex = q.peek().index;

int first = 0;
int last = 0;

for (int i = 0; i < size; i++) {

Pair curr = q.poll();

int index = curr.index - minIndex;

if (i == 0)
first = index;

if (i == size - 1)
last = index;

if (curr.node.left != null)

q.offer(new Pair(
curr.node.left,
2 * index + 1));

if (curr.node.right != null)

q.offer(new Pair(
curr.node.right,
2 * index + 2));
}

ans = Math.max(ans,
last - first + 1);
}

return ans;
}
}












Dry Run






          1
/ \
2 3
/ \
4 5






Assign indices:




          0
/ \
1 2
/ \
3 6












Level 1



Indices:




0






Width:




1












Level 2



Indices:




1

2






Width:




2












Level 3



Indices:




3

6






Width:




6 - 3 + 1

=

4






Answer:




4












Why Indexing Works?



The assigned indices represent the positions of nodes in a complete binary tree.



Even if some nodes are missing,



their positions are preserved.



Thus,




Last Index

-

First Index

+

1






correctly measures the actual width.









Complexity Analysis




















Metric Complexity
Time Complexity O(N)
Space Complexity O(N)








Interview One-Liner




Perform a level-order traversal while assigning complete binary tree indices to each node. The width of each level is the difference between the first and last indices plus one.










Pattern Learned






Level Order

↓

Assign Indices

↓

First Index

↓

Last Index

↓

Maximum Width









Similar Problems




  • Maximum Width of Binary Tree

  • Complete Binary Tree

  • Left View

  • Right View

  • Vertical Order Traversal









Memory Trick



Think:




Root → 0

↓

Left = 2i + 1

↓

Right = 2i + 2

↓

Width

=

Last - First + 1









Mental Model






BFS

↓

(Node, Index)

↓

Track First & Last

↓

Update Maximum Width






Whenever you hear:




"Maximum Width of Binary Tree"




your brain should immediately think:



Level Order Traversal + Complete Binary Tree Indexing

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Community-Diskussion & Kommentare

🌐 Zum Hauptchat

Starte die Diskussion im Social-Chat Broadcast Stream oder reiche oben über „Information ergänzen“ einen Fachbeitrag ein.

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar & Graph

MITRE ATT&CK Matrix Navigator
1 belegte Technik
T1110TA0006 · Credential Access
Brute Force
Mitigation: M1036 Account Use Policies
Quelle: Kontext-Klassifikation des Artikeltextes · Konfidenz 85%
MFA/Passkeys aktivieren, Account-Lockouts und Passwort-Policies verschärfen, Anmeldeversuche überwachen.
Credential Access
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
3 Knoten · 2 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Community Rating &amp; Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War dieser Artikel hilfreich?
0
Jetzt Bewertung abgeben
Detail-Bewertung (optional)
Inhalt & Qualität
Quelle & Glaubwürdigkeit
Aktualität
Security Briefing Kostenlos · 1-Klick-Abmeldung

Intelligence Digest — kostenlos

Täglich die wichtigsten Security-News · jederzeit abbestellbar

Verwandte Story-Cluster & Quellen (Vektor-KI)

6 Cluster
21 Quellen
CVE-2026-72088 | Linux Kernel up to 7.2-rc3 hpsa in_reset memory leak (WID-SEC-2026-2852)
VulDB Updates vor 2 Std.
20 weitere Quellen
VulDB Updatesvor 2 Std.CVE-2026-72089 | Linux Kernel up to 7.2-rc3 accel/ivpu fw_log_from_bo size/header_size memory corruption (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72090 | Linux Kernel up to 7.1.4 amdxdna amdxdna_drm_sync_bo_ioctl handle/driver_priv improper synchronization (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72091 | Linux Kernel up to 7.1.4/7.2-rc3 amdxdna amdxdna_drm_submit_execbuf null pointer dereference (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72093 | Linux Kernel up to 6.18.39/7.1.4/7.2-rc2 amdxdna amdxdna_gem_dmabuf_mmap use after free (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72092 | Linux Kernel up to 6.18.41/7.1.4/7.2-rc3 amdxdna amdxdna_cmd_submit null pointer dereference (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72095 | Linux Kernel up to 6.18.39/7.1.4/7.2-rc1 dma-fence dma_fence_dedup_array uninitialized variable (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72094 | Linux Kernel dma-fence kernel/dma/fence.c dma_fence_timeline_name/dma_fence_driver_name null pointer dereference (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72097 | Linux Kernel up to 7.2-rc2 dm-verity dm_verity_loadpin_is_bdev_trusted null pointer dereference (WID-SEC-2026-2852) VulDB Updatesvor 2 Std.CVE-2026-72096 | Linux Kernel up to 7.2-rc2 dm-verity race condition (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2022-30594 | Linux Kernel up to 5.17.1 seccomp PTRACE_SEIZE PT_SUSPEND_SECCOMP permission (EUVD-2022-52436 / Nessus ID 224708) VulDB Updatesvor 3 Std.CVE-2026-72075 | Linux Kernel up to 7.1.4 ims-pcu ims_pcu_reset_device race condition (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72076 | Linux Kernel up to 7.1.4 ims-pcu ims_pcu_irq out-of-bounds (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72077 | Linux Kernel up to 6.6.147/6.12.96/6.18.39/7.1.4 ims-pcu denial of service (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72078 | Linux Kernel up to 7.1.4 ims-pcu usb_fill_int_urb input validation (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72079 | Linux Kernel up to 7.1.4 ims-pcu ims_pcu_disconnect use after free (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72081 | Linux Kernel up to 7.2-rc3 efct efct_dispatch_fcp_cmd allocation of resources (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72082 | Linux Kernel up to 7.2-rc3 efct efct_hw_io_abort reference count (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72085 | Linux Kernel up to 7.2-rc3 scsiback scsiback_do_cmd_fn use after free (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72087 | Linux Kernel up to 7.2-rc3 lpfc lpfc_sli4_driver_resource_setup memory leak (WID-SEC-2026-2852) VulDB Updatesvor 3 Std.CVE-2026-72086 | Linux Kernel up to 7.2-rc3 scsiback scsiback_device_action double free (WID-SEC-2026-2852)
15 Quellen
Best GTA 6 accessory deals for Black Friday
Latest from Windows Central vor 40 Min.
14 weitere Quellen
DEV Communityvor 33 Min.The Top Black Friday Deal on r/buildapcsales Came With Canceled Orders CNETvor 1 Std.This Holdover Black Friday Sale Will Save You 20% on Branch’s Well-Built Ergonomic Furniture Latest from TechRadarvor 1 Std.Have power at your fingertips with these top power station deals this Black Friday weekend — I've tested some impressive battery systems, here are my top picks from Bluetti, Jackery and more The Vergevor 2 Std.Here’s what other Verge readers bought during Black Friday Latest from TechRadarvor 2 Std.Looking at a mini PC for local AI workloads? Black Friday may be over, but there's a great deal than the GMKtec EVO-X3 with 128GB of memory Latest from TechRadarvor 2 Std.9 essential small business upgrades in the Black Friday sales — professional tech deals for small teams, freelancers, and solopreneurs Latest from TechRadarvor 2 Std.The Garmin Forerunner 55 is £99 right now, and it’s the Black Friday deal I recommend Latest from TechRadarvor 2 Std.Is there a Black Friday Disney+ deal in the UK? Here's what you need to know Latest from TechRadarvor 2 Std.Black Friday kitchen deals: huge savings all weekend on Ninja, De'Longhi, Breville, and KitchenAid Latest from Windows Centralvor 3 Std.Upgrade your PC listening experience with the best wireless earbuds for Windows 11 devices this Black Friday Latest from TechRadarvor 3 Std.Meta's best affordable headset is an even better deal for Black Friday Latest from TechRadarvor 3 Std.The best Black Friday Garmin deals still live, picked by a smartwatch tester CNETvor 3 TagenThese Post-Black Friday MacBook Deals Make Apple’s Laptops Up to $500 Off Latest from Windows Centralvor 3 Std.The GameSir G7 Pro 8K is the only PC controller to buy on Black Friday weekend
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Maximum Width of Binary Tree

Thematisch verwandte Begriffe: Maximum, Width, Binary, Tree · 6 Treffer

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
Widgets & Themen
Widgets werden geladen…
Nächster Beitrag