Skip to content

JRRS1982/Kata

Repository files navigation

Code Kata

This repository holds Kata that i have collected and completed on the Leetcode training platform. It has been useful to work on these kata locally as it allows me to group them and write test cases / store notes.

If you have been granted access to my template repo, you will find the kata template I am replicating for each test here

The list includes a lot of the teamblind.com kata, and i hope to work my way through it.

Array

Algorithms that are associated with manipulating Arrays. Reduce, Map, Filter are your friends here.


Backtracking

"Every you have a problem that is solved by a series of decisions you may have to backtrack to another point and choose something else"

It incrementally builds all candidates for the solution and abandon's / backtracks when the solution is not valid. It is a general graph search.

https://leetcode.com/problems/permutations/solutions/18239/A-general-approach-to-backtracking-questions-in-Java-(Subsets-Permutations-Combination-Sum-Palindrome-Partioning)/

  • Subsets
  • Combination Sum
  • Permutations
  • Subsets 2
  • Combination Sum 2
  • Palindrome Partitioning
  • Letter Combination of a Phone Number
  • N Queens

Binary Search

Binary search is a fast search algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search parameter in half.

https://leetcode.com/discuss/study-guide/786126/Python-Powerful-Ultimate-Binary-Search-Template.-Solved-many-problems


Bit Manipulation

https://leetcode.com/problems/sum-of-two-integers/solutions/84278/A-summary:-how-to-use-bit-manipulation-to-solve-problems-easily-and-efficiently/

  • Single Number
  • Number of 1 Bits
  • Counting Bits
  • Reverse Bits
  • Missing Number
  • Sum of To Integers
  • Reverse Integer

Dynamic Programming

https://leetcode.com/discuss/study-guide/458695/Dynamic-Programming-Patterns

1D Dynamic Programming

2D Dynamic Programming

Recursion

Recursion is the backbone of dynamic programming and backtracking.

https://leetcode.com/discuss/study-guide/1733447/become-master-in-recursion


Graph

https://leetcode.com/discuss/study-guide/655708/Graph-For-Beginners-Problems-or-Pattern-or-Sample-Solutions


Advanced Graph

  • Reconstruct Itinerary
  • Min Cost To Connect All Points
  • Network Delay Time
  • Swim In Rising Water
  • Alien Dictionary
  • Cheapest Flights Within K Stops

Greedy

A greedy algorithm: requires you to internally solve problems (optimally) to solve the higher scope problem. Examples being Dijkstra's algo, where you find the shortest path in a graph and Prim's or Krustal's algo where you find the minimum spanning trees in a graph.

  • Maximum Sub Array
  • Jump Game 2
  • Gas Station
  • Hand Of Straights
  • Merge Triplets To Form Target Triplet
  • Partition Labels
  • Valid Parenthesis String

Heap

An advanced tree based data structure used primarily for sorting and implementing priority queues


Interval


Linked List


Math and Geometry


Sliding Window

Think of it like a window sliding across and array of elements, where the window is analysed against a given constraint, i.e. a sub array of elements within a larger array and you update a variable outside the loop.

There are two types of this, one where the window reduces in size and one where it doesn`t

https://leetcode.com/problems/frequency-of-the-most-frequent-element/solutions/1175088/C++-Maximum-Sliding-Window-Cheatsheet-Template/


Stack

  • Valid Parentheses
  • Min Stack
  • [] Evaluate Reverse Polish Notation
  • [] Generate Parentheses
  • [] Daily Temperatures
  • [] Car Fleet
  • [] Largest Rectangle In Histogram

Two Pointers


Tree

https://leetcode.com/discuss/study-guide/1337373/tree-question-pattern-2021-placement


Tries


Queue

A linear structure with the first in, first out order. Imagine lining up for a ride, those at the front get on first.

  • Kth Largest Element In A Stream
  • Last Stone Weight
  • K Closest Points to Origin
  • Kth Largest Element In An Array
  • Task Scheduler
  • Design Twitter
  • Find Median From Data Stream

PEDAC

This is a model for solving coding problems

Process > Example > Data > Algo > Code

Process (understand) the problem

  • Read the description
  • Identify inputs / outputs
  • Identify rules / requirements
  • Ask clarifying questions
  • Examine all examples

Example test cases

  • Understand how the input translates to the output
  • Identify edge cases: i.e. do we need to handle an empty input?
  • Create test cases and confirm outputs

Data Structures

  • What kind of data is being dealt with? Strings? Arrays? Objects? Big Numbers etc

Algorithm

  • Step by step a process that take you from input to output
  • Handle edge cases and valid example inputs
  • Code will depend on the algorithm

Code

  • Use everything you've gathered so far to write the code
  • If there are errors in the output, adjust your algorithm before looking at the code

About

Kata and exercises from Leetcode and elsewhere

Topics

Resources

Stars

Watchers

Forks