Javascript Specific Flashcards

1
Q

What is the time complexity of trim()?

A

O(n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the time complexity of split()?

A

O(n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the time complexity of sort()?

A

O(n log n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the time complexity of map()?

A

O(n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you get a random number in a range?

A

Math.random() * (max - min +1) + min.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you get the square root?

A

Math.sqrt().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you import a priority queue

A

import { MinPriorityQueue } from “datastructuresjs/priority-queue”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you set custom priority in a priority queue thats been imported from “datastructuresjs/priority-queue”

A

const carsQueue = new PriorityQueue((a,b) => a.priority - b.priority);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is modulo propogation?

A

Modulo propagation is a technique where instead of computing the full value of a large number, we maintain only its remainder when divided by a given number (m). This allows us to efficiently check divisibility or perform modular arithmetic without handling large numbers.

126

1️⃣ Start with remainder 0.
2️⃣ Process “1” → (0 × 10 + 1) % 3 = 1
3️⃣ Process “2” → (1 × 10 + 2) % 3 = (10 + 2) % 3 = 12 % 3 = 0 ✅
4️⃣ Process “6” → (0 × 10 + 6) % 3 = 6 % 3 = 0 ✅

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can you use to calc big numbers in JavaScript

A

BigInt and 0n terminology

k = huge number
let num1 = 5n // number n is a bigInt
let num2 = BigInt(k)

let div = num2 / num1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you find a characters position in alphabet

A

char.charCodeAt(0) - “a”.charCodeAt(0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you get the first values of a set?

A

myset.values().next().value … values is an iterator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What makes maps different from objects?

A

map perserve insertion order … this is really useful for things like lru cache

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you get the first key of a map?

A

mymap.keys().next().value …. keys is an iterator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When are generators not useful in DSA

A

Generators are not ideal for:

Sorting Algorithms (since they require storing elements).
Random Access Data Structures (like heaps, where you need direct index-based access).
Cases Requiring Multiple Passes Over Data (generators are one-time iterators).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When are generators useful in DSA

A

✔ Generators shine in large data, trees, graphs, and infinite sequences.
✔ Use them for DFS, BFS, lazy evaluation, and streaming computations.
✔ Avoid them for sorting and direct index-based access (heaps, arrays).