LESSON 21 / 75·2 min readFoundation

Arrays and strings in JavaScript

Should knowConcept lesson
01 Understand02 Recall03 Prepare

Problems to practice

  • Two Sum
  • Move Zeroes
  • Best Time to Buy and Sell Stock
  • Maximum Subarray
  • Product of Array Except Self
  • Valid Palindrome
  • Longest Substring Without Repeating Characters
  • Group Anagrams

Example: two sum

JavaScript
function twoSum(nums, target) {
  const map = new Map();

  for (let i = 0; i < nums.length; i++) {
    const needed = target - nums[i];
    if (map.has(needed)) return [map.get(needed), i];
    map.set(nums[i], i);
  }

  return [];
}

Time and space complexity

  • Time: O(n)
  • Space: O(n)

PAUSE & RECALL

Can you explain it without the notes?

Arrays and strings in JavaScript

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Common questions

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Hashing and maps in JavaScript

Adapted from 16_DSA_JAVASCRIPT.md · “2. Arrays and strings in JavaScript”. Examples are study fragments; framework behavior can depend on your version.