Position: Grad
Location: Brisbane
Phone:
On-site:
Interviewers were not excitied. Need to stick with the leadership principal more. Need to mention the principal out
better soluton: https://swe.auspham.dev/docs/algorithms/arrays/encodeanddecode/
let test = ["abcde++++", "bcdef\\\\++++", "efgh+"];
class Serialise{
DELIMETER: string;
SEPARATOR: string;
constructor() {
this.DELIMETER = "+";
this.SEPARATOR = "\\\\";
}
serialise(arr: Array<string | null>): string {
let result = [];
for (let word of arr) {
for (let char of word!) {
if (char === this.DELIMETER || char === this.SEPARATOR) {
result.push(this.SEPARATOR);
}
result.push(char);
}
result.push(this.DELIMETER);
}
return result.join("");
}
deserialise(token: string): Array<string | null> {
if (token.length === 0) return [];
let result = [];
let tmp = [];
let parse: boolean = false;
for (let char of token) {
if (!parse && char === this.SEPARATOR) {
parse = true;
continue;
}
if (!parse && char === this.DELIMETER) {
result.push(tmp.join(""));
tmp = [];
continue;
}
if (parse) {
parse = false;
}
tmp.push(char);
}
return result;
}
}
let s = new Serialise();
let t = s.serialise(test);
console.log("token", t);
console.log("expected", test);
console.log("actual", s.deserialise(t));