Pular para o conteúdo principal
ProdutosFerramentas de desktopTASTECADVisualização de desenhosTASTEFILESGerenciamento de arquivosTASTEFTPTransferência de arquivosTASTESSHEspaço de trabalho remotoTASTEZIPCompactação e extraçãoFerramentas para desenvolvedoresTASTECODEAmbiente de desenvolvimento integrado para RustTASTESTUDIOAmbiente integrado de desenvolvimento e testesTASTEETLIntegração de dados (ETL)ServidoresTASTEREMOTEServidor de área de trabalho remotaTASTEGEOServidor geoespacialTASTEMAILEspaço de trabalho de e-mailComeçarDownloadsDocumentaçãoComprarTodos os produtos
Marketplace
Notícias
TecnologiaNotíciasNotícias de desenvolvimento de hojeDocumentaçãoLinguagens de programaçãoRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFrameworks de front-end webNext.jsReactVue.js · NuxtSvelteKitAngularFrameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFrameworks de apps e desktopTauriFlutterReact NativeElectronAlgoritmosFundamentos de algoritmosAlgoritmos essenciaisAlgoritmos avançadosAlgoritmos práticos
ComunidadeProjetosRegistros de desenvolvimentoPromptsProblemas de ferramentas de IAVitrineGuia da comunidade
ColaboreTransferência técnicaConstrução de siteConstrução de app de desktopPipeline de lançamento e pagamentoParceiro de vendasContato
ServiçosÁrea de trabalho remotaPacotes de instalação sob medida
TASTEDEV
Produtos

Ferramentas de desktop

TASTECADDesenhos complexos, abertos com levezaTASTEFILESSó os arquivos de que você precisa, o mais rápido possívelTASTEFTPO caminho mais organizado para seus arquivosTASTESSHEntre você e o servidor, uma conexão mais sólidaTASTEZIPCompacte mais rápido, extraia com mais segurança

Ferramentas para desenvolvedores

TASTECODEEdite, compile, depure e teste apps Rust em uma única janelaTASTESTUDIODa edição aos testes remotos e às correções com IA aprovadasTASTEETLMova dados de olho nos valores

Servidores

TASTEREMOTEUma área de trabalho remota rodando no seu próprio servidorTASTEGEOUm servidor geoespacial compatível com o GeoServer, reconstruído em RustTASTEMAILRetome o controle do seu e-mail

Começar

DownloadsVersões mais recentes de cada produtoDocsComo usar cada produtoComprarAssinaturas e licenças perpétuasTodos os produtosTodos os produtos de relance
Todos os produtos
MarketplaceNotícias
Tecnologia

Notícias

Notícias de desenvolvimento de hojeAnúncios oficiais de linguagens, frameworks, GitHub e IADocumentaçãoGuias de linguagens, frameworks e algoritmos

Linguagens de programação

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Frameworks de front-end webNext.jsReactVue.js · NuxtSvelteKitAngular
Frameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Frameworks de apps e desktopTauriFlutterReact NativeElectron

Algoritmos

Fundamentos de algoritmosAnálise de complexidade · Ordenação · Busca · Estruturas de dados básicas · Árvores e heapsAlgoritmos essenciaisBusca em grafos · Caminho mínimo e árvore geradora mínima · Programação dinâmica · Algoritmos gulosos · Divisão e conquista · BacktrackingAlgoritmos avançadosAlgoritmos de strings · Matemática e teoria dos números · Manipulação de bits · Árvores de segmentos · Union-FindAlgoritmos práticosEstratégia para entrevistas de código · Cache LRU · Limitação de taxa · Hashing consistente
Toda a documentação de desenvolvimento
Comunidade
ProjetosDescubra criadores e trabalhosRegistros de desenvolvimentoDecisões e aprendizadosPromptsInstruções reutilizáveisProblemas de ferramentas de IAProblemas e contornos de Claude, Codex, GeminiVitrineResultados concluídosGuia da comunidadeComo construímos em aberto
Colabore
Transferência técnicaApps nativos em Rust e eguiConstrução de site10 idiomas, contas, documentação e downloadsConstrução de app de desktopRust e egui, sem WebViewPipeline de lançamento e pagamentoAssinatura, MSI, deb, rpm, AppImage, hashesParceiro de vendasRecomende e ganhe 30%ContatoDesenvolvimento, parcerias e investimento
Serviços
Área de trabalho remotaAcesse seu computador pelo navegadorPacotes de instalação sob medidaSó o necessário, configurações pré-carregadas
Comprar
PT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Entrar
Entrar
TASTEDEV

De pequenas ferramentas a um desenvolvimento melhor.

support@tastedev.netApoiar TASTEDEV
ProdutosLinha de produtosComprarDocsDownloadsMarketplaceSuporte
ComunidadeProjetosRegistros de desenvolvimentoPromptsProblemas de ferramentas de IAVitrine
PolíticasPolítica de privacidadeTermos de usoTermos de assinaturaReembolsoDiretrizes da comunidade
ContaEntrarCriar conta
Visitantes
Hoje
012345678901234567890123456789012345678901234567890123456789
Ontem
012345678901234567890123456789012345678901234567890123456789
Visualizações totais
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Empresa
GXSOFT
Representante
CHOI YOUNG GU
Número de registro comercial
853-44-00368
Endereço
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefone
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsável pela privacidade
CHOI YOUNG GU

© 2026 TASTEDEVAs informações dos produtos se baseiam em fontes de desenvolvimento verificadas.Lançado · em melhoria

Documentação de Estruturas de dados básicas
Estruturas de dados básicas
Core ConceptsHow It WorksImplementationComplexity AnalysisPractice ProblemsReal-World Use
Discussões

Guia de Estruturas de dados básicas · 5/6

Practice Problems

Por enquanto, este capítulo está disponível apenas em inglês.

These five problems are written for this guide. Each one is solved by choosing the right structure rather than by clever tricks. Try each before reading the approach.

Problem 1: Browser back and forward

A small browser starts at a home page. It supports three commands: visit url opens a new page, back returns to the previous page and forward undoes a back. Visiting a new page clears the forward history. Ignore back or forward when there is nowhere to go. Return the current page after all commands.

Approach: keep two stacks. back_stack holds pages behind the current one and forward_stack holds pages ahead of it. Going back moves the current page onto the forward stack; visiting clears the forward stack. Every command is O(1).

def browse(home, commands):
    current, back_stack, forward_stack = home, [], []
    for command in commands:
        if command.startswith("visit "):
            back_stack.append(current)
            current = command[6:]
            forward_stack.clear()
        elif command == "back" and back_stack:
            forward_stack.append(current)
            current = back_stack.pop()
        elif command == "forward" and forward_stack:
            back_stack.append(current)
            current = forward_stack.pop()
    return current

cmds = ["visit a", "visit b", "back", "back", "back", "forward", "visit c", "forward"]
print(browse("home", cmds))  # c

Problem 2: Requests in the last minute

A server logs request timestamps in seconds, in non-decreasing order. After each request, report how many requests arrived in the last 60 seconds, counting the current one (timestamps t - 59 through t).

Approach: a queue holds the timestamps still inside the window. On each new timestamp, append it and pop from the front while the oldest is older than t - 59. Each timestamp enters and leaves once, so the total cost is O(n).

from collections import deque

def recent_counts(timestamps, window=60):
    inside = deque()
    result = []
    for t in timestamps:
        inside.append(t)
        while inside[0] <= t - window:
            inside.popleft()
        result.append(len(inside))
    return result

print(recent_counts([1, 10, 59, 60, 61, 125]))  # [1, 2, 3, 4, 4, 1]

At t = 61 the window covers 2 through 61, so the request at 1 drops out. At t = 125 the window is 66 through 125 and only the current request remains.

Problem 3: First repeated order ID

Order IDs arrive as a list of strings. Return the first ID that appears for the second time, judged by the position of that second appearance, or None if all IDs are unique. Also report how many distinct IDs were seen before the answer.

Dúvidas sobre este capítulo?
Capítulo anteriorComplexity AnalysisPróximo capítuloReal-World Use

Approach: a set remembers IDs already seen. Scanning left to right, the first ID that is already in the set is the answer. Each check and insert is O(1) on average, so the scan is O(n) instead of the O(n squared) of comparing every pair.

def first_repeat(order_ids):
    seen = set()
    for order_id in order_ids:
        if order_id in seen:
            return order_id, len(seen)
        seen.add(order_id)
    return None, len(seen)

print(first_repeat(["A7", "B2", "C9", "B2", "A7"]))  # ('B2', 3)
print(first_repeat(["X1", "X2"]))                    # (None, 2)

Problem 4: Hottest temperature in every window

Given hourly temperatures and a window size k, return the maximum temperature of every block of k consecutive hours.

Approach: a deque stores indices whose temperatures are in decreasing order. Before appending index i, pop from the back every index with a temperature less than or equal to the new one, because those can never be a maximum again. Pop from the front when an index slides out of the window. The front is always the maximum of the current window. Every index is pushed and popped at most once: O(n) total instead of O(n * k).

from collections import deque

def window_max(temps, k):
    candidates = deque()   # indices, temperatures decreasing
    result = []
    for i, t in enumerate(temps):
        while candidates and temps[candidates[-1]] <= t:
            candidates.pop()
        candidates.append(i)
        if candidates[0] <= i - k:
            candidates.popleft()
        if i >= k - 1:
            result.append(temps[candidates[0]])
    return result

print(window_max([12, 15, 11, 9, 14, 18, 13, 10], 3))  # [15, 15, 14, 18, 18, 18]

Problem 5: Group words by letters

Group words that are anagrams of each other, keeping groups in the order their first word appeared.

Approach: two words are anagrams exactly when their sorted letters are equal, so the sorted letters make a dictionary key. Python dictionaries keep insertion order, which gives the required group order for free.

def group_anagrams(words):
    groups = {}
    for word in words:
        key = "".join(sorted(word))
        groups.setdefault(key, []).append(word)
    return list(groups.values())

print(group_anagrams(["listen", "stone", "silent", "notes", "enlist", "tones", "cat"]))
# [['listen', 'silent', 'enlist'], ['stone', 'notes', 'tones'], ['cat']]

Summary

Undo and redo patterns call for stacks, sliding time windows call for queues, "have I seen this?" calls for a set, and "group or count by key" calls for a dictionary. When a nested loop compares every pair, ask whether a hash table or a monotonic deque can remember what the inner loop keeps recomputing.

0 comentários

Principais comentáriosMais recentes primeiro

Fazer login · Faça login para deixar um comentário.