{"id":436,"date":"2025-06-29T16:30:19","date_gmt":"2025-06-29T11:00:19","guid":{"rendered":"https:\/\/codeanddebug.in\/blog\/?p=436"},"modified":"2025-06-29T16:30:20","modified_gmt":"2025-06-29T11:00:20","slug":"spiral-matrix-leetcode-54","status":"publish","type":"post","link":"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/","title":{"rendered":"Spiral Matrix | Leetcode 54 | Explained in Python"},"content":{"rendered":"\n<p>LeetCode <strong>\u201cSpiral Matrix\u201d<\/strong> (#54) asks you to return all the elements of an <em>m \u00d7 n<\/em> matrix in <strong>clock-wise spiral order<\/strong>, starting from the top-left corner.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Example<\/strong><br><em>Input<\/em><br><code>[[1, 2, 3],<\/code><br><code>[4, 5, 6],<\/code><br><code>[7, 8, 9]]<\/code><br><em>Output<\/em><br><code>[1, 2, 3, 6, 9, 8, 7, 4, 5]<\/code><\/p>\n<\/blockquote>\n\n\n\n<p>Think of tracing the outer frame of the matrix, then peeling it away layer by layer\u2014just like unwrapping an onion.<\/p>\n\n\n\n<p>Here&#8217;s the [<strong><a href=\"https:\/\/leetcode.com\/problems\/spiral-matrix\/description\/\" target=\"_blank\" rel=\"noreferrer noopener\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\"><span style=\"text-decoration: underline;\">Problem Link<\/span><\/mark><\/a><\/strong>] to begin with.<\/p>\n\n\n<div style=\"max-width: -moz-fit-content; \" class=\"wp-block-ub-table-of-contents-block ub_table-of-contents ub_table-of-contents-collapsed\" id=\"ub_table-of-contents-e97b0eb9-50a4-4615-ae70-f607b4782202\" data-linktodivider=\"false\" data-showtext=\"show\" data-hidetext=\"hide\" data-scrolltype=\"auto\" data-enablesmoothscroll=\"true\" data-initiallyhideonmobile=\"false\" data-initiallyshow=\"false\"><div class=\"ub_table-of-contents-header-container\" style=\"\">\n\t\t\t<div class=\"ub_table-of-contents-header\" style=\"text-align: left; \">\n\t\t\t\t<div class=\"ub_table-of-contents-title\">Contents:<\/div>\n\t\t\t\t<div class=\"ub_table-of-contents-header-toggle\">\n\t\t\t<div class=\"ub_table-of-contents-toggle\" style=\"\">\n\t\t\t\u00a0[<a class=\"ub_table-of-contents-toggle-link\" href=\"#\" style=\"\">show<\/a>]\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div><div class=\"ub_table-of-contents-extra-container\" style=\"\">\n\t\t\t<div class=\"ub_table-of-contents-container ub_table-of-contents-1-column ub-hide\">\n\t\t\t\t<ul style=\"\"><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#0-optimal-solution-pointer-shrinking-technique\" style=\"\">Optimal Solution (Pointer Shrinking Technique)<\/a><ul><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#1-intuition-and-approach\" style=\"\">Intuition and Approach<\/a><\/li><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#2-code-implementation\" style=\"\">Code Implementation<\/a><\/li><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#3-code-explanation\" style=\"\">Code Explanation<\/a><\/li><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#4-dry-run-3-%C3%97-3-matrix\" style=\"\">Dry Run (3 \u00d7 3 Matrix)<\/a><\/li><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#5-time-and-space-complexity\" style=\"\">Time and Space Complexity<\/a><\/li><li style=\"\"><a href=\"https:\/\/codeanddebug.in\/blog\/spiral-matrix-leetcode-54\/#6-conclusion\" style=\"\">Conclusion<\/a><\/li><\/ul><\/li><\/ul>\n\t\t\t<\/div>\n\t\t<\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0-optimal-solution-pointer-shrinking-technique\">Optimal Solution (Pointer Shrinking Technique)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-intuition-and-approach\">Intuition and Approach<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Four Pointers<\/strong> mark the current \u201cunvisited rectangle\u201d:<br><em><code>top<\/code> row, <code>bottom<\/code> row, <code>left<\/code> column, <code>right<\/code> column.<\/em><\/li>\n\n\n\n<li>Repeatedly <strong>walk the perimeter<\/strong> of that rectangle in four mini-passes:\n<ol class=\"wp-block-list\">\n<li>Left \u279c Right across the <em>top<\/em> row.<\/li>\n\n\n\n<li>Top \u279c Bottom down the <em>right<\/em> column.<\/li>\n\n\n\n<li>Right \u279c Left across the <em>bottom<\/em> row (if any rows remain).<\/li>\n\n\n\n<li>Bottom \u279c Top up the <em>left<\/em> column (if any cols remain).<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>After completing the loop, <strong>shrink<\/strong> the rectangle:<br><em>increment <code>top<\/code>, decrement <code>bottom<\/code>, increment <code>left<\/code>, decrement <code>right<\/code>.<\/em><\/li>\n\n\n\n<li>Stop when <code>top > bottom<\/code> <strong>or<\/strong> <code>left > right<\/code>.<\/li>\n<\/ol>\n\n\n\n<p>Because every element is touched exactly once and we reuse the result list for output, the algorithm runs in <code>O(m\u00b7n)<\/code> time with <code>O(1)<\/code> extra space.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-code-implementation\">Code Implementation<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"class Solution:\n    def spiralOrder(self, matrix: List[List[int]]) -&gt; List[int]:\n        # Handle empty input\n        if not matrix or not matrix[0]:\n            return []\n\n        result = []                           # stores the spiral order\n\n        # Initialize boundary pointers\n        top, left = 0, 0\n        bottom, right = len(matrix) - 1, len(matrix[0]) - 1\n\n        # Continue until the boundaries cross\n        while top &lt;= bottom and left &lt;= right:\n            # Traverse the top row from left to right\n            for i in range(left, right + 1):\n                result.append(matrix[top][i])\n            top += 1                          # top row is done\n\n            # Traverse the right column from top to bottom\n            for i in range(top, bottom + 1):\n                result.append(matrix[i][right])\n            right -= 1                        # right column is done\n\n            # Traverse the bottom row from right to left (if any)\n            if top &lt;= bottom:\n                for i in range(right, left - 1, -1):\n                    result.append(matrix[bottom][i])\n                bottom -= 1                   # bottom row is done\n\n            # Traverse the left column from bottom to top (if any)\n            if left &lt;= right:\n                for i in range(bottom, top - 1, -1):\n                    result.append(matrix[i][left])\n                left += 1                     # left column is done\n\n        return result\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Solution<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">spiralOrder<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">self<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">matrix<\/span><span style=\"color: #D4D4D4\">: List[List[<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">]]) -&gt; List[<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #6A9955\"># Handle empty input<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">not<\/span><span style=\"color: #D4D4D4\"> matrix <\/span><span style=\"color: #569CD6\">or<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">not<\/span><span style=\"color: #D4D4D4\"> matrix[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">]:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> []<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        result = []                           <\/span><span style=\"color: #6A9955\"># stores the spiral order<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #6A9955\"># Initialize boundary pointers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        top, left = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        bottom, right = <\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(matrix) - <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(matrix[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">]) - <\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #6A9955\"># Continue until the boundaries cross<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">while<\/span><span style=\"color: #D4D4D4\"> top &lt;= bottom <\/span><span style=\"color: #569CD6\">and<\/span><span style=\"color: #D4D4D4\"> left &lt;= right:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #6A9955\"># Traverse the top row from left to right<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(left, right + <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                result.append(matrix[top][i])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            top += <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">                          <\/span><span style=\"color: #6A9955\"># top row is done<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #6A9955\"># Traverse the right column from top to bottom<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(top, bottom + <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                result.append(matrix[i][right])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            right -= <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">                        <\/span><span style=\"color: #6A9955\"># right column is done<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #6A9955\"># Traverse the bottom row from right to left (if any)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> top &lt;= bottom:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(right, left - <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, -<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                    result.append(matrix[bottom][i])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                bottom -= <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">                   <\/span><span style=\"color: #6A9955\"># bottom row is done<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #6A9955\"># Traverse the left column from bottom to top (if any)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> left &lt;= right:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(bottom, top - <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, -<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                    result.append(matrix[i][left])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                left += <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">                     <\/span><span style=\"color: #6A9955\"># left column is done<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> result<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-code-explanation\">Code Explanation<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Boundaries:<\/strong> <code>top<\/code>, <code>bottom<\/code>, <code>left<\/code>, and <code>right<\/code> fence in the part of the matrix we still need to visit.<\/li>\n\n\n\n<li><strong>Perimeter Walk:<\/strong> Each loop iteration captures one \u201cring\u201d of the onion in four straight passes.<\/li>\n\n\n\n<li><strong>Boundary Update:<\/strong> After finishing a side, we move the corresponding pointer inward so we don\u2019t revisit those cells.<\/li>\n\n\n\n<li><strong>Termination:<\/strong> When the pointers cross, no unvisited cells remain.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-dry-run-3-%C3%97-3-matrix\">Dry Run (3 \u00d7 3 Matrix)<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Step<\/th><th>top<\/th><th>bottom<\/th><th>left<\/th><th>right<\/th><th>Elements Added<\/th><th>result after step<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>0<\/td><td>2<\/td><td>0<\/td><td>2<\/td><td>1 2 3 (top row)<\/td><td>1 2 3<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>2<\/td><td>0<\/td><td>2<\/td><td>6 9 (right column)<\/td><td>1 2 3 6 9<\/td><\/tr><tr><td>3<\/td><td>1<\/td><td>2<\/td><td>0<\/td><td>1<\/td><td>8 7 (bottom row)<\/td><td>1 2 3 6 9 8 7<\/td><\/tr><tr><td>4<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td>4 (left column)<\/td><td>1 2 3 6 9 8 7 4<\/td><\/tr><tr><td>5<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>5 (final center element)<\/td><td>1 2 3 6 9 8 7 4 5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Pointers cross, done!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-time-and-space-complexity\">Time and Space Complexity<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Time:<\/strong> <code>O(m \u00d7 n)<\/code> \u2013 every cell is visited exactly once.<\/li>\n\n\n\n<li><strong>Space:<\/strong> <code>O(1)<\/code> extra \u2013 aside from the output list, only four integer pointers are used.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"6-conclusion\">Conclusion<\/h3>\n\n\n\n<p>Using four shrinking boundaries lets us capture the <strong>Spiral Matrix<\/strong> order cleanly, without auxiliary grids or markers. This pattern\u2014<em>peel the outer layer, shrink, repeat<\/em>\u2014is a handy template for many 2-D traversal problems.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.codeanddebug.in\/course\/zero-to-hero-python-dsa\" target=\"_blank\" rel=\"noreferrer noopener\">Join our Advance DSA COURSE<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><em>For any changes to the article, kindly email at <a href=\"mailto:code@codeanddebug.in\">code@codeanddebug.in<\/a> or contact us at <a href=\"tel:+91-9712928220\">+91-9712928220<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode \u201cSpiral Matrix\u201d (#54) asks you to return all the elements of an m \u00d7 n matrix in clock-wise spiral order, starting from the top-left corner. ExampleInput[[1, 2, 3],[4, 5, 6],[7, 8, 9]]Output[1, 2, 3, 6, 9, 8, 7, 4, 5] Think of tracing the outer frame of the matrix, then peeling it away layer<\/p>\n","protected":false},"author":1,"featured_media":437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ub_ctt_via":"","footnotes":""},"categories":[3,5],"tags":[26,18],"class_list":{"0":"post-436","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-structures-and-algorithm","8":"category-expert","9":"tag-2d-array","10":"tag-hard"},"featured_image_src":"https:\/\/codeanddebug.in\/blog\/wp-content\/uploads\/2025\/06\/spiral-matrix-featured-image.png","author_info":{"display_name":"codeanddebug","author_link":"https:\/\/codeanddebug.in\/blog\/author\/codeanddebug\/"},"_links":{"self":[{"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":1,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/posts\/436\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/posts\/436\/revisions\/438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/media\/437"}],"wp:attachment":[{"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/media?parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/categories?post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeanddebug.in\/blog\/wp-json\/wp\/v2\/tags?post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}