MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / traverse

Function traverse

javascript/0054-spiral-matrix.js:135–168  ·  view source on GitHub ↗
(matrix, top, bot, left, right, order)

Source from the content-addressed store, hash-verified

133};
134
135var traverse = (matrix, top, bot, left, right, order) => {
136 addTop(
137 matrix,
138 top,
139 bot,
140 left,
141 right,
142 order,
143 ); /* Time O(COLS) | Ignore Auxilary Spsace O(ROWS * COLS) */
144 addRight(
145 matrix,
146 top,
147 bot,
148 left,
149 right,
150 order,
151 ); /* Time O(ROWS) | Ignore Auxilary Spsace O(ROWS * COLS)*/
152 addBot(
153 matrix,
154 top,
155 bot,
156 left,
157 right,
158 order,
159 ); /* Time O(COLS) | Ignore Auxilary Spsace O(ROWS * COLS)*/
160 addLeft(
161 matrix,
162 top,
163 bot,
164 left,
165 right,
166 order,
167 ); /* Time O(ROWS) | Ignore Auxilary Spsace O(ROWS * COLS. */
168};
169
170var addTop = (matrix, top, bot, left, right, order) => {
171 for (let col = left; col <= right; col++) {

Callers 1

spiralOrderFunction · 0.70

Calls 4

addTopFunction · 0.85
addRightFunction · 0.85
addBotFunction · 0.85
addLeftFunction · 0.85

Tested by

no test coverage detected