unreasonably effective

you can be sloppy, as long as you are rigorous

  • LeetCode 332: Reconstruct Itinerary

    link Backtrack A valid itinerary uses each ticket exactly once and is lexicographically sorted. So, we build a directed graph where an edge is a ticket. Starting with “JFK” we backtrack to find a path that consumes all tickets. Each hop of the path consumes one available ticket. We use sorted edge-lists so that possible…

    tanvirdotzaman

    March 23, 2025
    foundational_interview, graph
  • LeetCode 815: Bus Routes

    link Change of routes is what we care about, bus-stops within a route can be abstracted away. We thus have an undirected graph where vertices are route indices and there is an edge if the two routes share a bus-stop. In this route graph, we want to find the shortest distance between two routes: one…

    tanvirdotzaman

    March 23, 2025
    foundational_interview, graph
  • LeetCode 261: Graph Valid Tree

    link A tree has barely enough edges to remain connected. So, with nodes there must be edges and all nodes must belong to a single connected component. We use DFS for the connected component part. Time: , space:

    tanvirdotzaman

    March 22, 2025
    foundational_interview, graph
  • LeetCode 133: Clone Graph

    link We can piggyback on DFS to clone the graph. We copy a node when we explore it. Note, if a shallow reference of exists in the map, we should grab that reference and deepen it. Otherwise, an earlier node storing ‘s reference in its neighbors list, will not be able to access the updated,…

    tanvirdotzaman

    March 22, 2025
    foundational_interview, graph
  • LeetCode 2077: Paths in Maze That Lead to Same Room

    link Backtrack A 3-cycle like below consists of a 3-room path () and an edge from the last room to the first room (). So, we consider each room as the head of a possible 3-cycle, generate 3-length path and check if there is an edge from last room to first. If largest number of…

    tanvirdotzaman

    March 22, 2025
    foundational_interview, graph
  • LeetCode 743: Network Delay Time

    link We use Dijkstra’s shortest path distance algorithm to find delays to all nodes from source. Max distance from source is the minimum time it would take for the signal to reach all nodes. heapq does not allow updating key, so we insert new entries like (d_v, v) whenever there is a better distance and…

    tanvirdotzaman

    March 22, 2025
    foundational_interview, graph
  • CS readings

    tanvirdotzaman

    March 21, 2025
    popcomp
  • LeetCode 20: Valid Parentheses

    link Stack We match and pop matching pairs using a stack. If s is valid, in the end, the stack must be empty. Time: , space: same. Two pointers Like this problem, if we are allowed to modify the string s in-place, we need constant extra space. Time: , space: .

    tanvirdotzaman

    March 19, 2025
    foundational_interview, stack
  • LeetCode 2696: Minimum String Length After Removing Substrings

    link Stack Here “AB” is like “()” and “CD” is like “{}”. Deleting a pair enables further deletes if they are nested with matching open and close like: (()), {()}, {{}}, ({}). For example: “ACDB”. So, we use a stack to simulate deletes. Time: , space: same. Two pointers If we could modify the string,…

    tanvirdotzaman

    March 19, 2025
    foundational_interview, stack
  • LeetCode 394: Decode String

    link Our problem is a concatenation of the below pattern: Since there are nested sub-problems, we use stack to solve it. As we process the string from left-to-right, we have two decision points: In the end, the stack has the repeated string. Time: , space: same.

    tanvirdotzaman

    March 19, 2025
    foundational_interview, stack
Previous Page
1 … 15 16 17 18 19 … 30
Next Page

Blog at WordPress.com.

  • Subscribe Subscribed
    • unreasonably effective
    • Already have a WordPress.com account? Log in now.
    • unreasonably effective
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar