Todos Novo

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

Registrar-se

Entrar


Todos Novo Registrar-se Entrar

All gists matching topic interview

Mais recente criado
Menos recente criado
Mais recente atualizado
Menos recente atualizado

linkjobai / Segment Trees for Interviews: Range Queries with Updates

0 curtidas
0 bifurcações
1 arquivos
Última atividade 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)
Próximo Anterior

Desenvolvido por Opengist ⋅ Load: 43ms⋅

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