To the Top
File:  root - text - article - 2019 - 11 - spiral-traversal-of-grid.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 239 Views, 14537 Search Bots | 90 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Amazon:

By the way, check out our NEW project AlgoPro (http://algopro.com) for over 60+ video coding sessions with ex-Google/ex-Facebook engineers.

You are given a 2D array of integers. Print out the clockwise spiral traversal of the matrix.

Example:


grid = [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]


The clockwise spiral traversal of this array is:


1, 2, 3, 4, 5, 10, 15, 20, 19, 18, 17, 16, 11, 6, 7, 8, 9, 14, 13, 12


Here is a starting point:


def matrix_spiral_print(M):
# Fill this in.

grid = [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]

matrix_spiral_print(grid)
# 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 239 Views, 14537 Search Bots | 90 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Tree Serialization
  2. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  3. Algorithm Interview: String Compression
  4. Fix Brackets
  5. Windows Scripting
  6. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  7. Daily Interview Question: Word Search
  8. Algorithm Interview: Maximum Path Sum in Binary Tree
  9. Most Frequent Subtree Sum
  10. [Daily Problem] Longest Palindromic Substring

Comments (0)

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />