Todos Nuevo

user:thomas gists creados por el usuario

title:mygist gists con el título indicado

filename:myfile.txt gists que contienen archivos con el nombre indicado

extension:yml gists que contienen archivos con la extensión indicada

language:go gists que contienen archivos con el lenguaje indicado

topic:homelab gists with given topic

Registrarse

Iniciar sesión


Todos Nuevo Registrarse Iniciar sesión

All gists matching topic interview

Recientemente creado
Menos reciente creado
Recientemente actualizado
Menos reciente actualizado

linkjobai / Segment Trees for Interviews: Range Queries with Updates

0 gustos
0 bifurcaciones
1 archivos
Última actividad 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)
Siguiente Anterior

Desarrollado por Opengist ⋅ Load: 43ms⋅

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