Front End Engineer Interview Questions | Glassdoor

Front End Engineer Interview Questions

439

Front end engineer interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index. Discuss the runtime of the algorithm and how you can be sure there won't be any infinite loops.

20 Answers

public static void permute(String[] a, int[] b) { int n = a.length; for (int i = 0; i < n; i++) { while (b[i] != i) { swap(i, b[i], a, b); } for (int j = 0; j < n; j++) { System.out.print(a[j]); } System.out.println(); } } public static void swap(int i, int j, String[] a, int[] b) { int bt = b[j]; b[j] = b[i]; b[i] = bt; String at = a[j]; a[j] = a[i]; a[i] = at; } // you know there aren't infinite loops because the algorithm reduces the number of misplaced elements at each step

Javascript Version: function mutate(input, specArr) { var visited = []; specArr.forEach(function(newIdx, i) { var tmp; visited.push(newIdx); if (visited.indexOf(i) < 0) { tmp = input[i]; input[i] = input[newIdx]; input[newIdx] = tmp; } }); } Trick is to keep track of visited indices and make sure you're not performing unecessary replacements. Run time is THETA(n) as indexOf is a constant-time operation since an array in javascript is simply an object (see http://es5.github.io/#x15.4.4.14 ).

function repositionElements(arr, indices) { // assert(arr.length === indices.length) var moved = []; for (var i = 0; i < arr.length; i++) { moved.push(false); } var moveFrom, moveTo, itemToMove; for (moveFrom = 0; moveFrom < arr.length; moveFrom++) { itemToMove = arr[moveFrom]; while (!moved[moveFrom]) { moveTo = indices[moveFrom]; var tmpItem = arr[moveTo]; arr[moveTo] = itemToMove; itemToMove = tmpItem; moved[moveFrom] = true; moveFrom = moveTo; } } return arr; } var arr = ["a", "b", "c", "d", "e", "f"], indices = [2, 3, 4, 0, 5, 1]; repositionElements(arr, indices); // returns: ["d", "f", "a", "b", "c", "e"]

Design a data structure to store sparse 2D matrix which contains only 0 or 1. then write function to add 2 such matrix.

4 Answers

Find the Kth hisghest element in a given array.

5 Answers

Given 2 very large numbers, each of which is so large it can only be represented as an array of integers, write a function to multiply them.

3 Answers

How would you pick the middle element of a list

4 Answers

randomize an array.

4 Answers

Write a function to compute the square root of a number without using any built-in functions.

2 Answers

In a given list of words, find matching words in the list that can be generated from the patterns of a given word.

2 Answers

2. Develop a form with checkboxes and that will output certain conditional messages depending on which checkboxes where checked.

1 Answer

How would you rate yourself with Javascript? (between 1 and 10)

1 Answer
110 of 439 Interview Questions