Algorithm

What is inside this repo? Each folder contains a algorithm questions, and some test (if it is written in ruby).

On the top of each question, there is a brief description of the question, input output, difficulty level and related tags.

How to ran it? Java solution:

  1. Open https://codepad.remoteinterview.io/pads in browser.
  2. Pause the solution in the editor and hit "run" on the bottom.

Ruby solution:

  1. Open the terminal and clone the folder.
  2. Direct inside the folder and ran Rspec file.

Greedy

  track everything!

Easy

Binary Search

input: an array of intergers and a target.
output: index position of the first/any/last of the given target.

Template

Easy

Med

Hard

Pool

Binary Tree & Divide Conquer

  public class TreeNode {
    public int value;
    public TreeNode left, right;
    public TreeNode(int) {
      this.value = int;
      this.left = this.right = null;
    }
  }
// for codepad
class MyCode {

  public static class TreeNode {
    public int val;
    public TreeNode left, right;
    public TreeNode(int num) {
      this.val = num;
      this.left = this.right = null;
    }

  }

  public static void main (String[] args) {
    TreeNode root = new TreeNode(2);
    root.left = new TreeNode(3);
    root.right = new TreeNode(4);
    System.out.println(root.val);
  }
}
  class TreeNode {
    constructor(num) {
      this.val = num;
      this.left = this.right = null;
    }
  }

  var root = new TreeNode(3);
  console.log(root.val);
class TreeNode
  attr_accessor :val, :left, :right
  def initialize(num)
    @val = num
    @left = @right = nil
  end
end

root = TreeNode.new(5)

puts root.val

Template

Easy

Med

Breath First Search

  public class TreeNode {
    public int value;
    public TreeNode left, right;
    public TreeNode(int) {
      this.value = int;
      this.left = this.right = null;
    }
  }
// for codepad
class MyCode {

  public static class TreeNode {
    public int val;
    public TreeNode left, right;
    public TreeNode(int num) {
      this.val = num;
      this.left = this.right = null;
    }

  }

  public static void main (String[] args) {
    TreeNode root = new TreeNode(2);
    root.left = new TreeNode(3);
    root.right = new TreeNode(4);
    System.out.println(root.val);
  }
}
  class TreeNode {
    constructor(num) {
      this.val = num;
      this.left = this.right = null;
    }
  }

  var root = new TreeNode(3);
  console.log(root.val);
class TreeNode
  attr_accessor :val, :left, :right
  def initialize(num)
    @val = num
    @left = @right = nil
  end
end

root = TreeNode.new(5)

puts root.val

Template

Depth First Search

Template

  Recursion:
    - Definition
    - Disassembly
    - Exit

Easy

Linked List & Array

Template

public ListNode {
  int val;
  ListNode next;
  ListNode(int val) {
    val = val;
    next = null;
  }
}

Two Pointers

Template

// reverse an array
// use while
public void reverse(char[] s) {
  int left = 0, right = s.length - 1;
  while (left < right) {
      char temp = s[left];
      s[left] = s[right];
      s[right] = temp;
      left++;
      right--;
  }
}

// use for loop
public void reverse(char[] s) {
    for (int i = 0, j = s.length - 1; i < j; i++, j--) {
        char temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}
Same direction two pointers questions:
Opposite direction two pointers questions:

Easy

Med

Question Pool

Coding Style

Google Coding Style

Data Structures

How do we do this one?

  1. We can vote the topic for the next meetup and do flash talk(15min?).
  2. Have someone talks about it during the meetup.(more like a short class?? it may be really dry!)