๐ My Agoda Frontend Interview Experience | 82 LPA | Senior Software Engineer
Overview
Agoda, a global travel platform based in Singapore, seeks Frontend Engineers proficient in building scalable UI features using React/React Native. Ideal candidates should demonstrate expertise in implementing pixel-perfect designs, ensuring optimal performance, and collaborating effectively within international teams. The interview process assesses candidates' skills in JavaScript, TypeScript, and related frontend technologies.
Interview Rounds
The interview process comprised two main rounds:
Round 1: Machine Coding
-
Language: JavaScript
-
Platform: HackerRank
-
Duration: 90 minutes
-
Problem Statement: Implement an immutable copy functionality for a JavaScript class.
The candidate was required to enhance a given
MyClasswith methods to:getImmutableCopy(): Returns an immutable copy of the instance, preventing modification of propertiesa,b, andc.isMutable(): Returns a boolean indicating whether the object is mutable.
The provided code template was as follows:
class MyClass { constructor(a, b, c, mutable = true) { this.a = a; this.b = b; this.c = c; this._mutable = mutable; } sum() { return this.a + this.b + this.c; } isMutable() { return this._mutable; } getImmutableCopy() { const clone = new MyClass(this.a, this.b, this.c, false); return Object.freeze(clone); } } // Example usage: const input = '1 2 3'; // Replace this with actual input const [a, b, c] = input.split(' ').map(Number); const obj = new MyClass(a, b, c); console.log(obj instanceof MyClass); // true console.log(obj.isMutable()); // true const immutableObj = obj.getImmutableCopy(); console.log(immutableObj.isMutable()); // falseThe final working solution involved utilizing
Object.freeze()to create an immutable copy. The importance of shallow freezing was highlighted, noting that deeply nested objects would require recursive freezing for full immutability./** * ๐ง JavaScript Note: * Object.freeze() only freezes the object at the top level. * For deeply nested immutability, you'd need a recursive deep freeze. */ class MyClass { constructor(a, b, c, mutable = true) { this.a = a; this.b = b; this.c = c; this._mutable = mutable; // Flag to check mutability } // ๐ข Returns sum of a, b, and c sum() { return this.a + this.b + this.c; } /** * Returns an immutable copy of the object. * Uses Object.freeze() to make it read-only. */ getImmutableCopy() { const frozen = new MyClass(this.a, this.b, this.c, false); return Object.freeze(frozen); // ๐ง Object becomes read-only } /** * Returns whether the current instance is mutable. */ isMutable() { return this._mutable; } } // ๐งช HackerRank Input & Output Logic function main() { const input = require('fs').readFileSync(0, 'utf-8').trim().split(' '); const [a, b, c] = input.map(Number); const obj = new MyClass(a, b, c); const immutableCopy = obj.getImmutableCopy(); // โ This modification won't apply on frozen object try { immutableCopy.a = 999; } catch (e) {} // โ Output the required flags console.log(obj.a === a && obj.b === b && obj.c === c); // true console.log(obj.isMutable()); // true console.log(immutableCopy.isMutable()); // false }
Original Source
This experience was originally published on medium. Support the author by visiting the original post.
Read on medium