# Front End Engineer Interview Questions

Front end engineer interview questions shared by candidates

## Top Interview Questions

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. 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"] Show More Responses |

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

Find the Kth hisghest element in a given array. |

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. |

randomize an array. |

How would you pick the middle element of a list |

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

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

Write a function to reverse a linked-list. |

Given two set of numbers find all matching pairs. |

**1**–

**10**of

**657**Interview Questions

## See Interview Questions for Similar Jobs

- Software Engineer
- Front End Developer
- Senior Software Engineer
- Web Developer
- Software Developer
- Front End Software Engineer
- Front End Web Developer
- Software Engineer Intern
- Intern
- Software Development Engineer
- Front End
- Product Manager
- Senior Front End Engineer
- Engineer
- UI Developer
- Frontend Engineer
- Engineering
- Developer