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 ...
随机推荐
- .NET Core中间件的注册和管道的构建(1)---- 注册和构建原理
.NET Core中间件的注册和管道的构建(1)---- 注册和构建原理 0x00 问题的产生 管道是.NET Core中非常关键的一个概念,很多重要的组件都以中间件的形式存在,包括权限管理.会话管理 ...
- HashSet HashTable 与 TreeSet
HashSet<T>类 HashSet<T>类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. HashSet& ...
- Ubuntu 16.10 安装KolourPaint 4画图工具
KolourPaint 4画图工具简单实用,可以绘画.视频处理和图标编辑: • 绘画:绘制图表和“手绘” • 视频处理:编辑截图和照片;应用特效 • 图标编辑:绘画剪贴和标识透明化 1.在Ubuntu ...
- Power BI官方视频(3) Power BI Desktop 8月份更新功能概述
Power BI Desktop 8月24日发布了更新版本.现将更新内容翻译整理如下,可以根据后面提供的链接下载最新版本使用. 1.主要功能更新 1.1 数据钻取支持在线版 以前的desktop中进行 ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- C#日志
参考页面: http://www.yuanjiaocheng.net/Entity/first.html http://www.yuanjiaocheng.net/Entity/jieshao.htm ...
- 电信计费业务:预后融合OCS到底应该实扣还是虚扣?
引入OCS的初衷之一是为了让计费系统能够参与到用户的通讯控制中来,也就是所谓的实时信控.用户在没有余额时,通讯就会被停止,不会造成"天价欠费 ",一方面保障用户的利益,一方面也保障 ...
- Android中点击事件的实现方式
在之前博文中多次使用了点击事件的处理实现,有朋友就问了,发现了很多按钮的点击实现,但有很多博文中使用的实现方式有都不一样,到底是怎么回事.今天我们就汇总一下点击事件的实现方式. 点击事件的实现大致分为 ...
- maven打包插件:appassembler
1.打包成bat 打包命令:mvn clean package appassembler:assemble <plugin> <groupId>org.codehaus.moj ...
- SQL SERVER导入数据到ORACLE的方法总结
我们偶尔会有将数据从SQL SERVER导入到ORACLE当中的这种需求,那么这种跨数据库导数有那些方法呢?这些方法又有那些利弊呢? 下面比较肤浅的总结了一些可行的方法. 1:生成SQL脚本然后去OR ...