Skip to content

Instantly share code, notes, and snippets.

View warlock2k's full-sized avatar
🛰️
Stay curious l̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈

Achyuth Nandikotkur warlock2k

🛰️
Stay curious l̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈
  • The University of Victoria
View GitHub Profile
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.
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)
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.
*/
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
*/
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)
class Solution
{
public int[] sortArray(int[] nums)
{
quickSort(nums, 0, nums.length - 1);
return nums;
}
public void quickSort(int[] nums, int left, int right)
{
class Solution
{
public int[] sortArray(int[] nums)
{
mergeSort(nums, nums.length);
return nums;
}
public void mergeSort(int[] nums, int length)
{