Všechno Nové

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Registrovat

Přihlásit se


Všechno Nové Registrovat Přihlásit se

linkjobai

Připojeno 5 days ago

Nedávno Vytvořeno
Nejméně nedávno Vytvořeno
Nedávno Aktualizováno
Nejméně nedávno Aktualizováno
Všechny gisty 1

linkjobai / Segment Trees for Interviews: Range Queries with Updates

0 Lajky
0 Forky
1 Soubory
Naposledy aktivní 5 days ago
Interview prep notes
interview

Segment Trees for Interviews: Range Queries with Updates

Prefix sums answer range-sum queries in O(1), but a single update costs O(n). When a problem mixes point updates and range queries (LeetCode 307, Range Sum Query - Mutable), a segment tree gives O(log n) for both.

Iterative segment tree (compact version)

class SegTree:
    def __init__(self, nums):
        self.n = len(nums)
Novější Starší

Vytvořeno pomocí Opengist ⋅ Load: 46ms⋅

Čeština
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文