Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016
Problem statement:
Given a 2D array (matrix) named M, print all items of M in a spiral order, clockwise.
For example:
M = 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
The clockwise spiral print is: 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12
Julia worked on solution using brute force solution.
https://gist.github.com/jianminchen/aa7a35df305b05f5d90a
Evaluation from the mock interviewer:




























So, Julia worked on more to come out better idea, to avoid bugs, make coding interesting.
i
0 1 2
-------------->
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
The above case, LT = (0,0), LR = (0, 4), BR = (3, 4), BL = (3, 0)
https://gist.github.com/jianminchen/7d775438e2d0d316f77d
Actually, one more condition:
LT, BR, two pointers, make sure that M-1-i>=i, N-1-i>=i; in other words, left top pointer is above the bottom right pointer.
therefore, it should be i <= Math.Min((M-1)/2, (N-1)/2)
Weakness:
1. Jagged array initialization - take more than 5 minutes, look up internet;
2. Design has issue - only variable i, from 0 to (N+1)/2, <- original thought
should be: 0 to Math.Min((M-1)/2, (N-1)/2)
Debug the test case, and then, find the bug; it takes extra 10 minutes, run through several test cases, and then another 10 minutes.
3. Good design - extra checking - save time to debug, fix the bug. Always think about more checking.
Ref: 2015 June - Julia's practice
http://juliachencoding.blogspot.ca/2015/06/leetcode-sprial-array-printout.html
Pramp mock interview (4th practice): Matrix Spiral Print的更多相关文章
- Pramp - mock interview experience
Pramp - mock interview experience February 23, 2016 Read the article today from hackerRank blog on ...
- leetcode & Mock Interview
leetcode & Mock Interview https://leetcode.com/interview/ xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...
- 59. Spiral Matrix && Spiral Matrix II
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...
- leetcode@ [54/59] Spiral Matrix & Spiral Matrix II
https://leetcode.com/problems/spiral-matrix/ Given a matrix of m x n elements (m rows, n columns), r ...
- Eric Chen Mock Interview
Given an array with integers. Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is ...
- LeetCode 885. Spiral Matrix III
原题链接在这里:https://leetcode.com/problems/spiral-matrix-iii/ 题目: On a 2 dimensional grid with R rows and ...
- (Forward)5 Public Speaking Tips That'll Prepare You for Any Interview
Landing a job interview is incredibly exciting –- and often terrifying. But fear not. There are clev ...
- 使用 Python Mock 类进行单元测试
数据类型.模型或节点——这些都只是mock对象可承担的角色.但mock在单元测试中扮演一个什么角色呢? 有时,你需要为单元测试的初始设置准备一些“其他”的代码资源.但这些资源兴许会不可用,不稳定,或者 ...
- Palindromic Matrix
Palindromic Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Fabio 安装和简单使用
Fabio(Go 语言):https://github.com/eBay/fabio Fabio 是一个快速.现代.zero-conf 负载均衡 HTTP(S) 路由器,用于部署 Consul 管理的 ...
- nodejs之get/post请求的几种方式
最近一段时间在学习前端向服务器发送数据和请求数据,下面总结了一下向服务器发送请求用get和post的几种不同请求方式: 1.用form表单的方法:(1)get方法 前端代码: <form act ...
- PHP-----文件系统的交互
本文讲解php中于文件交互中所使用的函数 代码示例 <html> <head> <title> File Detail </title> </he ...
- PHP获取上个月最后一天的一个容易忽略的问题
正常来说,PHP是有一个很方便的函数可以获取上个月时间的 strtotime (PHP 4, PHP 5, PHP 7) strtotime - 将任何英文文本的日期时间描述解析为 Unix 时间戳 ...
- 以向VS 程序打包集成自动写入注册表功能为例,介绍如何实现自由控制安装过程
最近由于项目部署时需要更灵活的控制程序安装的流程以及自定义安装行为,特意研究了一下VS程序打包,把解决办法和大家分享一下. 以VS2010为例: 这是一个已经设置好最基本的Visual Studio ...
- 【WPF】日常笔记
本文专用于记录WPF开发中的小细节,作为备忘录使用. 1. 关于绑定: Text ="{Binding AnchorageValue,Mode=TwoWay,UpdateSourceTrig ...
- 信息安全-1:python之playfair密码算法详解[原创]
转发注明出处: http://www.cnblogs.com/0zcl/p/6105825.html 一.基本概念 古典密码是基于字符替换的密码.加密技术有:Caesar(恺撒)密码.Vigenere ...
- 【腾讯Bugly干货分享】微信iOS SQLite源码优化实践
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57b58022433221be01499480 作者:张三华 前言 随着微信iO ...
- 按照Enterprise Integration Pattern搭建服务系统
在前一篇文章中,我们已经对Enterprise Integration Pattern中所包含的各个组成进行了简单地介绍.限于篇幅(20页Word以内),我并没有深入地讨论各个组成.但是如果要真正地按 ...
- Lesson 19 Sold out
Text 'The play may begin at any moment,' I said. 'It may have begun already,' Susan answered. I hurr ...