Interview Q&A / Data Structures & Algorithms

INTERVIEW Q&A · 55 QUESTIONS

Data Structures & Algorithms interview questions

Arrays, linked lists, hashing, trees and patterns, with line-by-line code and complexity.

  1. When should you use a Map instead of a plain object in JavaScript?

    Use a Map when keys are not just strings, when you add and remove entries often, or when you need a reliable size and insertion order. Use a plain object for fixed, string-keyed records.

    BeginnerQuick answer1 min read
  2. Why does [10, 9, 1].sort() return [1, 10, 9] in JavaScript?

    By default sort converts elements to strings and compares them in dictionary order, so "10" comes before "9". Pass a comparator such as (a, b) => a - b to sort numbers numerically.

    BeginnerQuick answerCoding1 min read