Skip to content

wattsjay/problems

Repository files navigation

Problems

A selection of problems implemented in TypeScript.

A — Array

1. 🟢 🙂 Contains Duplicate

  • DS: Set
  • Algorithm: Count difference in length.

2. 🟢 🙂 Valid Anagram

  • DS: List
  • Algorithm: Count frequency of each character.

3. 🟢 🙂 Two Sum

  • DS: Map
  • Algorithm: Test for compliment.

4. 🟠 🙂 Group Anagrams

  • DS: Map
  • Algorithm: Sort.
  • DS: Map
  • Algorithm: Sort.
  • DS: List
  • Algorithm: Prefix & Postfix.

7. 🟠 🙂 Valid Soduko

  • DS: Map of Sets
  • Algorithm: Loop rows, columns to get cell. Test if cell is contained in respective row, column, or square set of values using a unique set key. Square keys are generated by banding and intersecting row and column indices using Math.floor and square dimension of 3: ${row}-${column}.
  • DS: List
  • Algorithm: Nested while loop.
  • DS: Set
  • Algorithm:
    1. CREATE numbers Set.
    2. ITERATE numbers.
    3. GET sequence start. IF previous number IS NOT IN Set.
    4. SET sequence length IF longer THAN existing.
    5. RETURN sequence length.

B — Stack

1. 🟢 🙂 Valid Parentheses

  • DS: Stack
  • Algorithm:
    1. ITERATE brackets.
    2. IF open THEN push.
    3. ELSE IF pop != matching bracket THEN RETURN false.
    4. ELSE RETURN stack = empty.

2. 🟠 🙂 Min Stack

  • DS: Stack x 2
  • Algorithm:
    1. WHEN push IF value < MinStack top THEN push MinStack.
    2. WHEN pop IF value = MinStack top THEN pop MinStack.
  • DS: Stack
  • Algorithm:
    1. IF operator THEN evaluate two integers on Stack.
    2. ELSE push integer to Stack.
  • Heuristics: Backtracking, Recursion
  • DS: Stack
  • Algorithm: Call generator function recursively.

5. 🟠 🙁 Daily Temperatures

  • Heuristics: Greedy
  • DS: Stack
  • Algorithm: ?

6. 🟠 🙂 Car Fleet

  • Heuristics: Greedy
  • DS: Stack
  • Algorithm:
    1. Zip distance and speed.
    2. Sort descending distance.
    3. ITERATE zipped cars.
    4. Calculate ETA THEN push to Stack.
    5. IF car ETA < car ahead THEN pop and merge car from Stack.

C — Two Pointers

1. 🟢 🙂 Valid Palindrome

  • Algorithm: Walk two pointers in opposite directions.
  • Algorithm:
    1. Walk two pointers in possite directions
    2. IF sum > target THEN decrease endPointer
    3. IF sum < target THEN increase startPointer

About

DSA problems solved in TypeScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published