Lesson overview · Free interview practice

Randomized Algorithms

Utilize randomness to solve problems efficiently.

Topics in the full lesson
  • Concept and Use Cases
  • Key Concepts
  • Time and Space Complexity
  • Randomized Algorithms and Methods
  • Practical Tips and Tricks
  • Common Gotchas
  • Advanced Topics
  • Interview Tips and Tricks
  • Common Mistakes

Try the free interview questions

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

Question

You are given a 0-indexed array w, where w[i] is the weight of index i. Implement pickIndex(), which returns an index in [0, n) chosen at random with probability proportional to its weight — that is, index i is returned with probability w[i] / sum(w).

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given a list of non-overlapping axis-aligned rectangles, pick a random integer point uniformly from the space covered by the rectangles.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Randomized Algorithms material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium

Continue in this section