{"id":11229,"date":"2025-11-24T17:00:40","date_gmt":"2025-11-24T11:30:40","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=11229"},"modified":"2025-11-24T17:18:21","modified_gmt":"2025-11-24T11:48:21","slug":"reconstruct-itinerary","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/reconstruct-itinerary\/","title":{"rendered":"Reconstruct Itinerary"},"content":{"rendered":"\n<!-- Inorder & Postorder recursive approach: 4 -->\n<link\n    href=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/themes\/prism-tomorrow.min.css\"\n    rel=\"stylesheet\"\n\/>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/prism.min.js\"><\/script>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/plugins\/autoloader\/prism-autoloader.min.js\"><\/script>\n\n<style>\n.wp_blog_theme {\n  --primary: #E58C32;\n  --secondary: #030302;\n  --light-bg: #fef9f4;\n  --text-dark: #2d2d2d;\n  --tab-radius: 12px;\n  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n  --code-bg: #001f3f;\n  --code-text: #d4f1ff;\n}\n\n.wp_blog_container {\n  font-family: 'Segoe UI', sans-serif;\n  background: var(--light-bg);\n  margin: 0;\n  padding: 0;\n  color: var(--text-dark);\n}\n\n\/* Heading *\/\n.wp_blog_main-heading {\n  text-align: center;\n  font-size: 2.4rem;\n  color: var(--primary);\n  margin-top: 2.5rem;\n  font-weight: bold;\n}\n\n\/* Explanation Card *\/\n.wp_blog_explanation,\n.wp_blog_code-tabs-container {\n  max-width: 940px;\n  margin: 2rem auto;\n  padding: 2rem;\n  background: white;\n  border-radius: var(--tab-radius);\n  box-shadow: var(--shadow);\n}\n\n\/* Text and Visuals *\/\n.wp_blog_explanation h2 {\n  font-size: 1.4rem;\n  color: var(--primary);\n  margin-bottom: 0.5rem;\n}\n\n.wp_blog_explanation p,\n.wp_blog_explanation li {\n  font-size: 1.05rem;\n  line-height: 1.7;\n  margin: 0.5rem 0;\n}\n\n.wp_blog_explanation code {\n  background: #fef9f4;   \/* light bg instead of dark blue *\/\n  color: #E58C32;        \/* brand orange *\/\n  padding: 3px 6px;\n  border-radius: 4px;\n  font-family: 'Courier New', monospace;\n  font-weight: 600;      \/* optional, makes it pop *\/\n}\n\n.wp_blog_explanation img {\n  max-width: 100%;\n  border-radius: var(--tab-radius);\n  margin-top: 1rem;\n  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);\n}\n\n\/* Tab Buttons *\/\n.wp_blog_code-tabs-header {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 0.5rem;\n  margin-bottom: 1rem;\n}\n\n.wp_blog_code-tab-button {\n  padding: 0.6rem 1.2rem;\n  border: 1px solid var(--primary);\n  background: white;\n  color: var(--primary);\n  border-radius: 50px;\n  font-weight: 600;\n  cursor: pointer;\n  transition: all 0.3s ease;\n}\n\n.wp_blog_code-tab-button:hover {\n  background: var(--secondary);\n}\n\n.wp_blog_code-tab-button.active {\n  background: var(--primary);\n  color: white;\n}\n\n\/* Code Content *\/\n.wp_blog_code-tab-content {\n  display: none;\n  background: var(--code-bg);\n  border-radius: var(--tab-radius);\n}\n\n.wp_blog_code-tab-content.active {\n  display: block;\n}\n\n.wp_blog_code-tab-content pre {\n  margin: 0;\n  padding: 1.5rem;\n  font-size: 1rem;\n  overflow-x: auto;\n  background: var(--code-bg);\n  border-radius: var(--tab-radius);\n  color: var(--code-text);\n}\n\n\/* Dark mode variables *\/\n.wp_blog_theme.dark-mode {\n  --light-bg: #121212;\n  --text-dark: #f5f5f5;\n  --shadow: 0 4px 12px rgba(255, 255, 255, 0.08);\n  --code-bg: #1e1e1e;\n  --code-text: #c5f0ff;\n}\n\n.wp_blog_theme.dark-mode .wp_blog_explanation {\n  background: #1e1e1e;\n}\n\n\/* Dark mode code highlight *\/\n.wp_blog_theme.dark-mode .wp_blog_explanation code {\n  background: #333;\n  color: #ffd27f;\n}\n\n.wp_blog_theme {\n  position: relative; \/* makes it the reference for absolute children *\/\n}\n\n.wp_blog_toggle-btn {\n  position: absolute;\n  top: 1rem;\n  right: 1rem;\n  z-index: 9999;\n  padding: 0.5rem 0.8rem;\n  border-radius: 10%;\n  background: var(--primary);\n  color: white;\n  font-weight: bold;\n  cursor: pointer;\n  border: none;\n  box-shadow: var(--shadow);\n  transition: background 0.3s, transform 0.2s;\n}\n\n.wp_blog_toggle-btn:hover {\n  background: #cc772e;\n}\n\n.wp_blog_theme.dark-mode .wp_blog_code-tabs-container {\n  background: #1e1e1e;\n}\n<\/style>\n\n<div class=\"wp_blog_container wp_blog_theme\"> \n      <button id=\"blogNotesThemeToggle\" class=\"wp_blog_toggle-btn\">\ud83c\udf19<\/button>\n\n    <h1 class=\"wp_blog_main-heading\"><\/h1>\n    <div class=\"wp_blog_explanation\">\n        <h2>Problem Statement<\/h2>\n        \n        <p>\n            You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.\n        <\/p>\n\n        <p>\n            All of the tickets belong to a man who departs from &#8220;JFK&#8221;, thus, the itinerary must begin with &#8220;JFK&#8221;. If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.\n        <\/p>\n\n        <p>\n            For example, the itinerary [&#8220;JFK&#8221;, &#8220;LGA&#8221;] has a smaller lexical order than [&#8220;JFK&#8221;, &#8220;LGB&#8221;].\n        <\/p>\n\n        <p>\n            You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.\n        <\/p>\n\n\n                <h2>Example 1:<\/h2>\n                <img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2025\/11\/Screenshot-2025-11-24-at-2.30.11-PM.png\" alt=\"\">\n                <p><strong>Input:<\/strong>  tickets = [[&#8220;MUC&#8221;,&#8221;LHR&#8221;],[&#8220;JFK&#8221;,&#8221;MUC&#8221;],[&#8220;SFO&#8221;,&#8221;SJC&#8221;],[&#8220;LHR&#8221;,&#8221;SFO&#8221;]]<\/p>\n                <p><strong>Output:<\/strong> [&#8220;JFK&#8221;,&#8221;MUC&#8221;,&#8221;LHR&#8221;,&#8221;SFO&#8221;,&#8221;SJC&#8221;]<\/p>\n        \n                <h2>Example 2:<\/h2>\n                <img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2025\/11\/Screenshot-2025-11-24-at-2.30.15-PM.png\" alt=\"\">\n                <p><strong>Input:<\/strong> tickets = [[&#8220;JFK&#8221;,&#8221;SFO&#8221;],[&#8220;JFK&#8221;,&#8221;ATL&#8221;],[&#8220;SFO&#8221;,&#8221;ATL&#8221;],[&#8220;ATL&#8221;,&#8221;JFK&#8221;],[&#8220;ATL&#8221;,&#8221;SFO&#8221;]]\n                <p><strong>Output:<\/strong> [&#8220;JFK&#8221;,&#8221;ATL&#8221;,&#8221;JFK&#8221;,&#8221;SFO&#8221;,&#8221;ATL&#8221;,&#8221;SFO&#8221;]<\/p>\n                <p><strong>Explanation: <\/strong>Another possible reconstruction is [&#8220;JFK&#8221;,&#8221;SFO&#8221;,&#8221;ATL&#8221;,&#8221;JFK&#8221;,&#8221;ATL&#8221;,&#8221;SFO&#8221;] but it is larger in lexical order.<\/p>\n\n                    <h2>Constraints:<\/h2>\n                   <ul>\n                    <li><code>1 <= tickets.length <= 300<\/code><\/li>\n                    <li><code>tickets[i].length == 2<\/code><\/li>\n                    <li><code>tickets[i].length == 2<\/code><\/li>\n                    <li><code>to<sub>i<\/sub>.length == 3<\/code><\/li>\n                    <li><code>from<sub>i<\/sub><\/code> and <code>to<sub>i<\/sub><\/code> consist of uppercase English letters.<\/li>\n                    <li><code>fromi != to<sub>i<\/sub><\/code><\/li>\n                   <\/ul>\n\n                <h2>Approach<\/h2>\n           <ul>\n            <li><strong>Build Graph:<\/strong>\n            <ul>\n                <li>Create an adjacency list where each airport maps to a list of destination airports.<\/li>\n            <\/ul>\n            <\/li>\n\n                        <li><strong>Sort Destinations:<\/strong>\n            <ul>\n                <li>For every airport, sort its destination list lexicographically because we must always choose the smallest possible next airport.<\/li>\n            <\/ul>\n            <\/li>\n\n            <li><strong>Depth-First Search (DFS):<\/strong>\n            <ul>\n                <li>Use DFS starting from \"JFK\"\n                    <ul>\n                        <li>Always pick the lexicographically smallest unused ticket (shift from the list).<\/li>\n                        <li>Recursively visit that next airport.<\/li>\n                        <li>When an airport has no more outgoing edges, add it to the path.<\/li>\n                    <\/ul>\n                <\/li>\n            <\/ul>\n            <\/li>\n\n            <li><strong>Reverse Path:<\/strong>\n            <ul>\n                <li>The final itinerary builds in reverse order because nodes are added after exploring all edges, so reverse it before returning.<\/li>\n            <\/ul>\n            <\/li>\n           <\/ul>\n\n                <!-- <h2>Time Complexity:<\/h2>\n                <li>\n                  <p><strong>Time Complexity = O(n)<\/strong>\n                  <\/li>\n                <h2>Space Complexity:<\/h2>\n                <li>\n                  <p><strong>Space Complexity = O(n)<\/strong><\/p>\n                <\/li> -->\n<h2>Dry Run<\/h2> <div style=\"background: var(--light-bg); border-left: 4px solid var(--primary); padding: 1rem; border-radius: var(--tab-radius); margin: 1rem 0; color: var(--text-dark);\"> \n    <p><strong>Input:<\/strong> \n    <code>tickets = [[\"MUC\",\"LHR\"],[\"JFK\",\"MUC\"],[\"SFO\",\"SJC\"],[\"LHR\",\"SFO\"]]<\/code><\/p>\n    <pre style=\"white-space: pre-wrap; background: var(--code-bg); padding: 1rem; border-radius: 8px; overflow-x: auto; color: var(--code-text);\"> \n    Graph Construction: JFK \u2192 [MUC] MUC \u2192 [LHR] LHR \u2192 [SFO] SFO \u2192 [SJC] All adjacency lists sorted (already sorted here). \n    Initialize: path = [ ] Start DFS: dfs(\"JFK\") dfs(\"JFK\") \n    \u2022 neighbors = [\"MUC\"] \u2022 take \"MUC\" \u2192 dfs(\"MUC\") dfs(\"MUC\") \n    \u2022 neighbors = [\"LHR\"] \u2022 take \"LHR\" \u2192 dfs(\"LHR\") dfs(\"LHR\") \n    \u2022 neighbors = [\"SFO\"] \u2022 take \"SFO\" \u2192 dfs(\"SFO\") dfs(\"SFO\")\n    \u2022 neighbors = [\"SJC\"] \u2022 take \"SJC\" \u2192 dfs(\"SJC\") dfs(\"SJC\") \n    \u2022 graph[\"SJC\"] is empty \u2022 push \"SJC\" \u2192 path = [\"SJC\"] (return) Back to dfs(\"SFO\") \n    \u2022 no neighbors left \u2022 push \"SFO\" \u2192 path = [\"SJC\",\"SFO\"] Back to dfs(\"LHR\") \n    \u2022 no neighbors left \u2022 push \"LHR\" \u2192 path = [\"SJC\",\"SFO\",\"LHR\"] Back to dfs(\"MUC\") \n    \u2022 no neighbors left \u2022 push \"MUC\" \u2192 path = [\"SJC\",\"SFO\",\"LHR\",\"MUC\"] Back to dfs(\"JFK\") \n    \u2022 no neighbors left \u2022 push \"JFK\" \u2192 path = [\"SJC\",\"SFO\",\"LHR\",\"MUC\",\"JFK\"] \n    \n    Final step: Reverse path \u2192 [\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"] <\/pre> <p><strong>Output:<\/strong> \n        <code>[\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"]<\/code><\/p> <\/div>\n<\/div>\n\n    <div class=\"wp_blog_code-tabs-container\">\n        <div class=\"wp_blog_code-tabs-header\">\n            <button class=\"wp_blog_code-tab-button active\" data-lang=\"js\">JavaScript<\/button>\n            <button class=\"wp_blog_code-tab-button\" data-lang=\"py\">Python<\/button>\n            <button class=\"wp_blog_code-tab-button\" data-lang=\"java\">Java<\/button>\n            <button class=\"wp_blog_code-tab-button\" data-lang=\"cpp\">C++<\/button>\n            <button class=\"wp_blog_code-tab-button\" data-lang=\"c\">C<\/button>\n            <button class=\"wp_blog_code-tab-button\" data-lang=\"cs\">C#<\/button>\n        <\/div>\n\n        <!-- JavaScript -->\n        <div class=\"wp_blog_code-tab-content active\" data-lang=\"js\">\n            <pre><code class=\"language-javascript\">\nvar findItinerary = function(tickets) {\n  let graph = {};\n  for (let [from, to] of tickets) {\n    if (!graph[from]) graph[from] = [];\n    graph[from].push(to);\n  }\n  for (let node in graph) {\n    graph[node].sort(); \/\/ ascending lexicographic\n  }\n\n  let path = [];\n  let dfs = (curr) => {\n    while (graph[curr] && graph[curr].length) {\n      let neighbor = graph[curr].shift(); \/\/ remove from front\n      dfs(neighbor);\n    }\n    path.push(curr);\n  };\n\n  dfs(\"JFK\");\n  return path.reverse(); \/\/ reverse before returning\n};\n     <\/code><\/pre>\n        <\/div>\n\n        <div class=\"wp_blog_code-tab-content\" data-lang=\"py\">\n            <pre><code class=\"language-python\">\nfrom collections import defaultdict, deque\nfrom typing import List\n\ndef findItinerary(tickets: List[List[str]]) -> List[str]:\n    graph = defaultdict(list)\n    for frm, to in tickets:\n        graph[frm].append(to)\n    # sort and convert to deque for efficient popleft\n    for k in graph:\n        graph[k].sort()\n        graph[k] = deque(graph[k])\n\n    path = []\n    def dfs(curr: str):\n        dest = graph.get(curr, deque())\n        while dest:\n            nxt = dest.popleft()\n            dfs(nxt)\n        path.append(curr)\n\n    dfs(\"JFK\")\n    return path[::-1]\n            <\/code><\/pre>\n        <\/div>\n\n        <!-- Java -->\n        <div class=\"wp_blog_code-tab-content\" data-lang=\"java\">\n            <pre><code class=\"language-java\">\nimport java.util.*;\n\npublic class Solution {\n    public List<String> findItinerary(List<List<String>> tickets) {\n        Map<String, LinkedList<String>> graph = new HashMap<>();\n        for (List<String> t : tickets) {\n            graph.computeIfAbsent(t.get(0), k -> new LinkedList<>()).add(t.get(1));\n        }\n        \/\/ sort each adjacency list and turn into a LinkedList (so we can removeFirst)\n        for (Map.Entry<String, LinkedList<String>> e : graph.entrySet()) {\n            List<String> list = e.getValue();\n            Collections.sort(list);\n            e.setValue(new LinkedList<>(list));\n        }\n\n        List<String> path = new ArrayList<>();\n        dfs(\"JFK\", graph, path);\n        Collections.reverse(path);\n        return path;\n    }\n\n    private void dfs(String curr, Map<String, LinkedList<String>> graph, List<String> path) {\n        LinkedList<String> dest = graph.get(curr);\n        while (dest != null && !dest.isEmpty()) {\n            String next = dest.removeFirst();\n            dfs(next, graph, path);\n        }\n        path.add(curr);\n    }\n}\n     <\/code><\/pre>\n        <\/div>\n\n        <!-- C++ -->\n        <div class=\"wp_blog_code-tab-content\" data-lang=\"cpp\">\n            <pre><code class=\"language-cpp\">\n#include &lt;bits\/stdc++.h&gt;              \nusing namespace std;\n\nvector<string> findItinerary(vector<vector<string>>& tickets) {\n    unordered_map<string, vector<string>> graph;\n    for (auto &t : tickets) {\n        graph[t[0]].push_back(t[1]);\n    }\n    \/\/ sort destinations lexicographically ascending\n    for (auto &p : graph) sort(p.second.begin(), p.second.end());\n\n    vector<string> path;\n    function<void(const string&#038;)> dfs = [&](const string &curr) {\n        auto &dest = graph[curr];\n        while (!dest.empty()) {\n            string next = dest.front();\n            dest.erase(dest.begin()); \/\/ remove from front\n            dfs(next);\n        }\n        path.push_back(curr);\n    };\n\n    dfs(\"JFK\");\n    reverse(path.begin(), path.end());\n    return path;\n}\n    <\/code><\/pre>\n        <\/div>\n\n        <!-- C -->\n        <div class=\"wp_blog_code-tab-content\" data-lang=\"c\">\n            <pre><code class=\"language-c\">\n#include &lt;stdlib.h&gt;\n#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\n#define MAX_NODES 1000\n#define MAX_TICKETS 10000\n#define MAX_STR_LEN 64\n\/\/ adjacency list storage\nchar *adj[MAX_NODES][MAX_TICKETS];\nint adjCount[MAX_NODES];\n\nchar nodes[MAX_NODES][MAX_STR_LEN];\nint nodeCount = 0;\n\nint find_or_add_node(const char *s) {\n    for (int i = 0; i < nodeCount; ++i)\n        if (strcmp(nodes[i], s) == 0) return i;\n    if (nodeCount >= MAX_NODES) { fprintf(stderr, \"node limit\\n\"); exit(1); }\n    strncpy(nodes[nodeCount], s, MAX_STR_LEN-1);\n    nodes[nodeCount][MAX_STR_LEN-1] = '\\0';\n    adjCount[nodeCount] = 0;\n    return nodeCount++;\n}\n\nint cmp_strptr(const void *a, const void *b) {\n    const char *const *pa = a;\n    const char *const *pb = b;\n    return strcmp(*pa, *pb);\n}\n\nchar *path[MAX_TICKETS + MAX_NODES];\nint pathLen = 0;\n\nvoid dfs(int u) {\n    while (adjCount[u] > 0) {\n        \/\/ pop front: take adj[u][0], then shift remaining left\n        char *next = adj[u][0];\n        \/\/ shift left\n        for (int i = 1; i < adjCount[u]; ++i)\n            adj[u][i-1] = adj[u][i];\n        adjCount[u]--;\n        \/\/ find index of next node\n        int v = -1;\n        for (int i = 0; i < nodeCount; ++i)\n            if (strcmp(nodes[i], next) == 0) { v = i; break; }\n        if (v == -1) { fprintf(stderr, \"node not found\\n\"); exit(1); }\n        dfs(v);\n    }\n    path[pathLen++] = strdup(nodes[u]);\n}\n\nint main() {\n    \/\/ Example input: you can replace this with dynamic input parsing.\n    \/\/ Here we hardcode a few tickets for demonstration.\n    const char *tickets[][2] = {\n        {\"MUC\",\"LHR\"},\n        {\"JFK\",\"MUC\"},\n        {\"SFO\",\"SJC\"},\n        {\"LHR\",\"SFO\"}\n    };\n    int ticketCount = 4;\n\n    \/\/ build graph\n    for (int i = 0; i < ticketCount; ++i) {\n        int a = find_or_add_node(tickets[i][0]);\n        int b = find_or_add_node(tickets[i][1]);\n        adj[a][adjCount[a]++] = strdup(tickets[i][1]);\n    }\n\n    \/\/ sort adjacency lists lexicographically\n    for (int i = 0; i < nodeCount; ++i) {\n        if (adjCount[i] > 0) {\n            qsort(adj[i], adjCount[i], sizeof(char*), cmp_strptr);\n        }\n    }\n    \/\/ find index of \"JFK\"\n    int start = -1;\n    for (int i = 0; i < nodeCount; ++i) {\n        if (strcmp(nodes[i], \"JFK\") == 0) { start = i; break; }\n    }\n    if (start == -1) {\n        printf(\"No JFK start\\n\");\n        return 0;\n    }\n\n    dfs(start);\n\n    \/\/ reverse and print\n    for (int i = pathLen - 1; i >= 0; --i) {\n        printf(\"%s\", path[i]);\n        if (i) printf(\" -> \");\n    }\n    printf(\"\\n\");\n    for (int i = 0; i < pathLen; ++i) free(path[i]);\n    for (int i = 0; i < nodeCount; ++i)\n        for (int j = 0; j < adjCount[i]; ++j)\n            free(adj[i][j]);\n    return 0;\n}\n            <\/code><\/pre>\n        <\/div>\n\n        <!-- C# -->\n        <div class=\"wp_blog_code-tab-content\" data-lang=\"cs\">\n            <pre><code class=\"language-csharp\">\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\n\npublic class Solution {\n    public IList<string> FindItinerary(IList<IList<string>> tickets) {\n        var graph = new Dictionary<string, LinkedList<string>>();\n        foreach (var t in tickets) {\n            var from = t[0];\n            var to = t[1];\n            if (!graph.ContainsKey(from)) graph[from] = new LinkedList<string>();\n            graph[from].AddLast(to);\n        }\n\n        \/\/ sort each adjacency list lexicographically\n        var keys = graph.Keys.ToList();\n        foreach (var k in keys) {\n            var sorted = graph[k].OrderBy(s => s).ToList();\n            graph[k] = new LinkedList<string>(sorted);\n        }\n\n        var path = new List<string>();\n        Dfs(\"JFK\", graph, path);\n        path.Reverse();\n        return path;\n    }\n    private void Dfs(string curr, Dictionary<string, LinkedList<string>> graph, List<string> path) {\n        if (!graph.ContainsKey(curr)) {\n            path.Add(curr);\n            return;\n        }\n        var dest = graph[curr];\n        while (dest.Count > 0) {\n            var next = dest.First.Value;\n            dest.RemoveFirst();\n            Dfs(next, graph, path);\n        }\n        path.Add(curr);\n    }\n}\n       <\/code><\/pre>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<script>\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n  const buttons = document.querySelectorAll(\".wp_blog_code-tab-button\");\n  const contents = document.querySelectorAll(\".wp_blog_code-tab-content\");\n\n  buttons.forEach((button) => {\n    button.addEventListener(\"click\", () => {\n      const lang = button.getAttribute(\"data-lang\");\n\n      buttons.forEach((btn) => btn.classList.remove(\"active\"));\n      contents.forEach((content) => content.classList.remove(\"active\"));\n\n      button.classList.add(\"active\");\n      document\n        .querySelector(`.wp_blog_code-tab-content[data-lang=\"${lang}\"]`)\n        .classList.add(\"active\");\n    });\n  });\n\n  const themeToggle = document.getElementById(\"blogNotesThemeToggle\");\n  const themeContainer = document.querySelector(\".wp_blog_theme\");\n\n  themeToggle.addEventListener(\"click\", () => {\n    themeContainer.classList.toggle(\"dark-mode\");\n    themeToggle.textContent =\n      themeContainer.classList.contains(\"dark-mode\") ? \"\u2600\ufe0f\" : \"\ud83c\udf19\";\n  });\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>\ud83c\udf19 Problem Statement You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a man who departs from &#8220;JFK&#8221;, thus, the itinerary must begin with &#8220;JFK&#8221;. If there<\/p>\n","protected":false},"author":108,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[210,322,176,175,211,174,172,173],"tags":[],"class_list":{"0":"post-11229","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-algorithms","7":"category-algorithms-and-data-structures","8":"category-csharp","9":"category-cplusplus","10":"category-data-structures","11":"category-java","12":"category-javascript","13":"category-python"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/108"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=11229"}],"version-history":[{"count":1,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11229\/revisions"}],"predecessor-version":[{"id":11230,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11229\/revisions\/11230"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=11229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=11229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=11229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}