This is the transcript of the mock interview with Candidate DG (10years)

**SDEGuru:** Hello Good Evening! How are you? We can get started any time you are ready.

**Candidate DG:** Hello, Thank you for asking. I’m ready. Thanks for meeting!

**SDEGuru:** My pleasure. Let’s get started. Welcome to the IM interview. First let us talk a bit about your work experience, and then we will go on to a coding question. Does that work?

**SDEGuru:** Tell me about a project at ABC Inc that you delivered. What is your proudest accomplishment?

**Candidate DG:** The biggest project I worked on at ABC Inc was a conversion of an existing Desktop Application (PowerBuilder framework) into WPF (.NET).

**SDEGuru:** What was so challenging about it?

**Candidate DG:** This was a critical application that managed inventory, processes, authorization, enforced limits on certain chemicals/etc, as well as provided reports. It was challenging because it’s such a huge system, we had to deliver new .NET code that ran alongside existing legacy code in PowerBuilder.

**SDEGuru:** Urgh PowerBuilder!!

**Candidate DG:** This meant that we had to learn how to sometimes update PB code (okay so you are familiar, sorry to hear that :)) to enforce new rules that we were implementing in the new .NET pages/screens. I would say I’m proud of how attentive I was in talking to the product owners, listening to their needs, and understanding how it all tied into the overall system. While I was on the project, we did 2 releases to Production that didn’t cause problems.

**SDEGuru:** So, What is the language of choice for you?

**Candidate DG:** C#

**SDEGuru:** On a scale of 1-10 how do rate yourself in C#?

**Candidate DG:** Maybe 7 or 8

**SDEGuru:** What will it take to make it a 9? What are you missing?

**Candidate DG:** I need more practice with things like generic classes, asyc/await and Tasks. I know them but I feel I could be better. I know with generic classes you can say things like “T where T is class” and I don’t know what all the options are for this.

**SDEGuru:** Excellent. Let us dive into coding question. Are you familiar with Sudoku?

Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids or sub-squares that compose the grid contains all of the digits from 1 to 9, no duplicates, no numbers missing.

**Candidate DG:** Yeah! I am familiar with it.

**SDEGuru:** Given a Sudoku matrix, can you validate if it is a valid solution?

**Candidate DG:** So I should validate if all the numbers are filled in, and I need to enforce the rules? I could do that.

**SDEGuru:** Pretend you are building a Sudoku validation service, that will validate if the given sudoku is a valid solution or not. You decide the input format and the response of the service.

**Candidate DG:** I think just a multi dimensional array where I am getting each row of the sudoku as an array.

**SDEGuru:** Data type of the elements?

**Candidate DG:** `int [][]`

**SDEGuru:** Method signature?

**Candidate DG:** `public bool isMatrixValid(int [][] matrix)`

**SDEGuru:** Moving on to the actual coding, what is your validation strategy?

**Candidate DG:** I need to know that the matrix is not null, and contains 9 sub-arrays, and each of those contains 9 integers, and each integer is between 1-9.

**SDEGuru:** Go on!

**Candidate DG:** I need to go through elements in sets of 3, so row 0, indexes 0-2, row 1 indexes 0-2, row 2 indexes 0-2

To validate the groups are unique. But possibly there would be a simpler way. Row/column is easy for the entire matrix.

**SDEGuru:**

**Candidate DG:** Do you have a matrix already? How is the input going to be?

**SDEGuru:** you said it will be `int[][]`

. Assume matrix is available to you. I will provide some raw test data.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
using System; class Solution { static void Main(string[] args) { int[][] matrix = new int[][]{ {5,3,4,6,7,8,9,1,2}, {6,7,2,1,9,5,3,4,8}, {1,9,8,3,4,2,5,6,7}, {8,5,9,7,6,1,4,2,3}, {4,2,6,8,5,3,7,9,1}, {7,1,3,9,2,4,8,5,6}, {9,6,1,5,3,7,2,8,4}, {2,8,7,4,1,9,6,3,5}, {3,4,5,2,8,6,1,7,9} }; //Service Validator public static bool IsMatrixValid(int [][] matrix) { SanitizeInput(matrix); ValidateSubMatrices(matrix); } private static bool SanitizeInput(int [][] matrix) { bool isValid = false; //I need to know that the matrix is not null, if (matrix == null) { isValid = false; } else { } return isValid; } /* Imagine the matrix has 3 large rows and 3 large columns that represent the sub-matrices. params: matrixRow is either row 0, 1, or 2 matrixColumn is either col 0, 1, or 2. */ private static int[][] ExtractSubMatrix(int [][] matrix, int matrixRow, int matrixColumn) { int[][] subMatrix = matrix[matrixRow][matrixColumn]; //TODO: validate that the matrix has this many elements. return subMatrix; } // I need to go through elements in sets of 3, so row 0, // indexes 0-2, row 1 indexes 0-2, row 2 indexes 0-2 private static bool ValidateSubMatrices(int [][] matrix) { bool valid = true; int [][] subMatrix; for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; j++) { subMatrix = ExtractSubMatrix(matrix, i, j); valid = valid && ValidateSubMatrix(submatrix); } } return valid; } private static bool ValidateSubMatrix(int [][] subMatrix) { bool isValid = false; int occurrenceCount = 0; //For the possible numbers 1-9 for (int num = 1; num <= 9; num++) { //Count the number of occurrences of this number. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (subMatrix[i, j] == num) { occurrenceCount++; } } } //handle errors....this can be done elsewhere...depends how you want to do this if (occurrenceCount != 1) { isValid = false; break; } else { isValid = isValid && true; } //Reset counter. occurrenceCount=0; } //end of outer for loop #1-9 } } |

**Candidate DG:** Comment: I am going to hard code the extraction of the sub-matrix here. This is kind of gross but I’m going to put it here for now.

**SDEGuru:** Can you do this programmatically? Say nested for loops?

**Candidate DG:** Yes I see that now that I’m writing it out.

**SDEGuru:** Good call on moving the looping code inside the function.

**Candidate DG:** ValidateSubMatrix should check Numbers 1-9 should appear exactly once. Right?

**SDEGuru:** No duplicates, no number missing, all numbers from 1-9 should appear once and only once.

**SDEGuru:** BTW, what is the big O for your algorithm?

**Candidate DG:** O(n^2)?

**SDEGuru:** Tell me more about how you plan to accomplish this.

**Candidate DG:** I could do this sequentially searching. I don’t know if I should do something fancy like a Stack ?!?

**SDEGuru:** How does it improve the algorithm in terms of runtime complexity, if you use a Stack?

**Candidate DG:** It doesn’t help performance, just makes code easier maybe?

**SDEGuru:** This line: `isValid = isValid && true;`

What does this line accomplish? foo && true is always foo?

**SDEGuru:** Time check, 7 mins to go!

**SDEGuru:** Are you sure the algorithm is still n^2?

**SDEGuru:** And we are done!!! Post interview followup time

**SDEGuru:** So what do you think? How did you do?

**Candidate DG:** I felt fairly comfortable with it. I tend to program that way that I write, rethink, move around, etc.

**SDEGuru:** How hard was the question?

**Candidate DG:** Fairly easy question

**SDEGuru:** How close are you to the solution? The expectation in a real interview (in person or phone interview), will be be complete all the three validations, in working code.

**Candidate DG:** I almost have the sub-matrix validation. I need the entire row and entire column validation. I feel sub-matrix was harder so that’s why I started there.

**SDEGuru:** I think it was a wise choice. I would have nudged you towards the sub-matrix part anyways. On the whole I don’t think you were able to showcase your full potential.

**SDEGuru:** A few tips for you

**Ask more questions:**You should be making and stating assumptions and getting to the method signature, test data etc much more quickly. In this case, I had to ask pointed questions to extract this information from you.**Take the time to design:**You were too quick to jump into coding. You should have taken a bit more time on designing your solution. Think before you code, otherwise, you may come across as a bit clueless.

There are two extremes in terms of answering styles. Quick on the draw and eternal thinker. The sweet spot is somewhere in between and a bit on the quicker side. You made the rookie mistake of being quick on the draw. Try slowing your roll a bit.

**Candidate DG:** On the second tip, I can be both. I find that I am more effective when I start plopping down algorithms, because I will see a more efficient way or how I want to organize something faster than if I think a long time. Maybe I am too quick, yes

**SDEGuru:** If you do not spend appropriate time planning you are running the risk of appearing “lost” and you will be wasting a lot of time writing/correcting stuff down on white board.

**SDEGuru:** Another thing, are you sure about the stack solution?

**Candidate DG:** Stack might be too much memory for this I think. I don’t use them often but just envisioned doing the Pop() for some reason.

**SDEGuru:** I am not sure how a stack based solution will work. It looks like the wrong DS for this problem. Again, you seemed to have trusted your instincts and blurted out something that was not properly thought through. This makes you look really bad in terms of your grasp of DS fundamentals.

For this question, if you had picked any other DS like a Hashmap/hashset, bitvector or similar, they make a lot more sense.

**SDEGuru: **Thanks for your time!!

**Verdict: **If this were a real interview, the candidate will most likely not make it to the next round. While there are some promising bits in the interview, a straight forward question like this should have yielded clean swift coding with a clear though process. Clearly the candidate is not prepared, and will struggle if they were to be brought on-site for an interview.