Skip to content

Instantly share code, notes, and snippets.

Avatar
🛰️
Stay curious

Achyuth Nandikotkur warlock2k

🛰️
Stay curious
  • The University of Victoria
View GitHub Profile
View EditDistanceDP.java
import java.util.*;
class EditDistance {
public static int EditDistance(char[] a, char[] b)
{
// a & b represent two strings.
// we need to make a DP table to store values
int [][] editDistanceMemo = new int [a.length + 1][b.length + 1];
// Initialize all all elements in first row to i representing deletions.
View longestCommonSubSequenceDP.java
import java.util.*;
public class LCS2
{
/*
* As usual for DP, three Steps are involved:
* 1. Break down the main problem into sub problems.
* 2. Initialize cache to hold solutions to sub problems.
* 3. Build solution to main problem from sub problem.
* Refer to this https://youtu.be/ASoaQq66foQ (Back To Back SWE)
View PrimitiveCalculatorDP.java
import java.util.*;
public class PrimitiveCalculator
{
/*
* As usual for DP, three Steps are involved:
* 1. Break down the main problem into sub problems.
* 2. Initialize cache to hold solutions to sub problems.
* 3. Build solution to main problem from sub problem.
*/
View ChangeDP.java
import java.util.Scanner;
public class ChangeDP
{
/*
* The idea is to break down the problem into smaller sub problem:
* Finding minimun change for m can be broken down into sub problems of finding minimum change for each input from
* 1 to m
* The bottom up approach
*/
View InversionsRecursive.java
import java.util.*;
import java.io.*;
class Inversions
{
public static int mergeSort(int[] nums, int length)
{
int inversionCount = 0;
// That is if the array is one single size return;
// This is the base case.
if(length < 2)
View QuickSortRecurse.java
class Solution
{
public int[] sortArray(int[] nums)
{
quickSort(nums, 0, nums.length - 1);
return nums;
}
public void quickSort(int[] nums, int left, int right)
{
View MergeSortRecursive.java
class Solution
{
public int[] sortArray(int[] nums)
{
mergeSort(nums, nums.length);
return nums;
}
public void mergeSort(int[] nums, int length)
{