Introduction
I had a mock interview today at 10:00 PM, and I like to write case study of my mock interview. It is important for me to learn how to pass mock interview on interviewing.io.
Case study
The code I wrote for the first algorithm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
// Give an array of string such as a = [orange, apple, lemon, pear, apple, orange, pear], targetWord = orange, k = 1 | |
// removeKElement(a, targetWord, k) | |
// => k = 1 => [apple, lemon, pear, apple, orange, pear] | |
// => k = 3 => [apple, lemon, pear, apple, pear] - remove first two orange | |
// time complexity : O(N) | |
// space: O(1) | |
// keep the original order -> | |
// | |
// array = [orange, [apple, [pear,[orange,apple]]], [watermelon,[lemon,apple]]], targetWord, k = 2 | |
// => [ [apple, pear,[apple]], [watermelon, [lemon, apple]]] | |
// To execute C#, please define "static void Main" on a class | |
// named Solution. | |
class Solution | |
{ | |
static void Main(string[] args) | |
{ | |
var result = removeTargetWordKtimes(new string[]{"orange","apple","apple","orange"}, "orange", 2); | |
foreach(var item in result) | |
Console.WriteLine(item); | |
} | |
/// [apple, lemon, pear, apple, orange, pear], target = "orange", K = 1 | |
public static string[] removeTargetWordKtimes(string[] words, string target, int K) | |
{ | |
if(words == null || words.Length == 0 || K <= 0) | |
return new string[0]; | |
if(target == null || target.Length == 0) | |
return words; | |
var length = words.Length; | |
var list = new List<string>(); | |
for(int i = 0;i < length; i++) | |
{ | |
var current = words[i]; // organge | |
if(current.CompareTo(target) == 0 && K > 0) | |
{ | |
K--; | |
} | |
else | |
{ | |
list.Add(current); | |
} | |
} | |
return list.ToArray(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// array = [orange, [apple, [pear,[orange,apple]]], [watermelon,[lemon,apple]]], targetWord, k = 2 | |
// => [ [apple, pear,[apple]], [watermelon, [lemon, apple]]] | |
// | |
// class NestedArray { | |
// List<NestedArray> array; | |
// String value; | |
// | |
// public boolean isEmpty() { return array.isEmpty() } | |
// | |
// [ orange, [apple, [pear]]] | |
/* | |
[ array1 => size is 2 | |
orange, => string value is orange | |
[ array2 => size is 2 | |
apple, => string value is apple | |
[ array3 => size is 1 | |
pear => string value is pear | |
] | |
] | |
] | |
*/ | |
// To execute C#, please define "static void Main" on a class | |
// named Solution. | |
class Solution | |
{ | |
public class Node | |
{ | |
List<Node> items; // either it is Node or string | |
public string value {get; set;} | |
public bool isString {get; set;} | |
// | |
Node next; // left, right -> | |
public Node() | |
{ | |
node1 = new Node(); | |
node1.isString = true; | |
node1.value = "orange"; | |
node1B = new Node(); | |
node1B.isString = true; | |
node1B.value = "apple"; | |
node2 = new Node(); | |
node2.isString = false; | |
node2.items = new List<Node>(); | |
node2.Add(node1B); | |
node2.Add(); // skip -> it is list simlar to node | |
node1.next = node2; | |
// written by interviewer - start from here | |
// [ orange, [apple, [pear]]] | |
NestedArray A; | |
NestedArray B => B.isString = true, B.value = "orange"; | |
NestedArray C => C.isString = false; | |
NestedArray D => D.isString = true, D.value = "apple"; | |
NestedArray E => E.isString = true, E.value = "pear"; | |
NestedArray F => F.isString = false; | |
F.arrays = [E]; | |
NestedArray G => G.arrays = [D, F]; | |
A.arrays = [B, G] | |
// end of the code written by interviewer | |
} | |
// interviewer wrote the code in the following | |
public void print(NestedArray a) { | |
if (nestedArray.isString) { | |
System.out.println(nestedArray.value); | |
} else { | |
System.out.println("["); | |
for (NestedArray b : a.arrays) { | |
print(b); | |
} | |
System.out.println("]"); | |
} | |
} |
Actionable Items
Follow upNov. 2, 2019
My ranking of interviewer does not match the feedback I wrote about the interviewer. I should lower the ranking of interviewer, at most 3. I have to learn how to make decision based on my careful consideration first.
Do not give the interviewer rank 4, which should be 2, not as good as 3.