My Apple Frontend Interview Experience | Frontend Engineer | Hyderabad
Overview
The candidate interviewed for a Frontend Engineer position at Apple in Hyderabad. The process began with a referral and progressed to a single round of online screening. This assessment evaluated the candidate's skills in problem-solving, JavaScript fundamentals, and React expertise. This document details the questions presented and the candidate's approaches to solving them.
Interview Rounds
Round 1: Online Screening (Platform Assessment)
- Role: Frontend Engineer
- Location: Hyderabad (Remote)
- Duration: 60 minutes
- Format: 10 questions (coding and theoretical)
1. Problem Solving: Fetch Keys from Nested Object / Array
The candidate was required to implement a function to extract keys pointing to primitive values from a nested object or array. The expected output was a flattened array of key paths.
Example Inputs/Outputs:
Input:
{ a: { b: {c:1}, d:2 }, e: 3 }
Output:
["a.b.c", "a.d", "e"]
Input:
[1, {a:2, b: [3,4]}, 5]
Output:
["0", "1.a", "1.b.0", "1.b.1", "2"]
Solution:
/**
* Recursively fetches all the paths (keys) to primitive
values from a nested object or array.
*
* @param {Object|Array} input - The input object or array to traverse.
* @returns {Array} - An array of strings,
each representing the path to a primitive value.
*/
function fetchKeys(input) {
const result = [];
/**
* Recursive helper function to traverse the input object/array.
*
* @param {*} value - The current value being traversed.
* @param {string} path - The current path constructed so far.
*/
function traverse(value, path) {
// Check if the current value is a primitive
// (string, number, boolean, null, etc.)
const isPrimitive = (val) =>
val === null || typeof val !== 'object';
// If it's a primitive, add the path to result and stop recursion
if (isPrimitive(value)) {
result.push(path);
return;
}
// If the value is an array, iterate over each element
if (Array.isArray(value)) {
value.forEach((item, index) => {
// Construct the new path with the index
const newPath = path ? `${path}.${index}` : `${index}`;
traverse(item, newPath); // Recursively traverse each item
});
} else {
// If it's an object, iterate over its keys
for (const key in value) {
if (value.hasOwnProperty(key)) {
// Construct the new path with the key
const newPath = path ? `${path}.${key}` : key;
traverse(value[key], newPath); // Recursively traverse the value
}
}
}
}
// Start traversing from the root of the input
traverse(input, '');
// Return the list of all paths to primitive values
return result;
}
Original Source
This experience was originally published on medium. Support the author by visiting the original post.
Read on medium