Skip to content

Instantly share code, notes, and snippets.

View jiahaoliuliu's full-sized avatar

Jiahao Liu Liu jiahaoliuliu

View GitHub Profile
@jiahaoliuliu
jiahaoliuliu / NumberOfIslands.java
Created November 17, 2018 16:56
SImple algorithm to find the number of islands in a matrix
/**
* Given a matrix of 0 and 1, where 0 represents water and 1 represent land.
* Two pieces of land are connected if they are touching each other(vertical, horizontal or diagonal)
* Please write a method that counts the number of islands.
*
* Here is an example :
* 0 (1 1) 0 0 0 [1]
* 0 (1) 0 0 [1 1] 0
* 0 (1 1) 0 0 [1] 0
* 0 0 0 0 0 0 0
package com.emirates;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import io.reactivex.Observable;
import io.reactivex.observers.TestObserver;
@jiahaoliuliu
jiahaoliuliu / recursivePermutations.java
Created October 26, 2018 10:46
Permutation using recursive on Java
package com.jiahaoliuliu.tools;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Permutations<T> {
private List<List<T>> generatePermutations(List<T> seedLists) {
return generatePermutations(new ArrayList<>(), seedLists);
@jiahaoliuliu
jiahaoliuliu / ListSplitterSum
Created November 13, 2015 09:12
A simple solution to split a list into two and the sum of the elements are similar
package com.jiahaoliuilu.testing.toptal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test1 {
// Testing array
private static int[] array = {5, 5, 1, 7, 2, 3, 5};
@jiahaoliuliu
jiahaoliuliu / SudokuChecker.java
Last active August 29, 2015 14:25
Sudoku checker. Simple checker for Sudoku with complexity O(N^2)
package com.jiahaoliuliu.sudokuchecker;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/**
* A class to check the if the content of a Sudoku is correct or not. The complexity of the algorithm
* has been kept to O(N^2), instead of O(N^3) for the cube check.
*
/*
* Copyright 2012 CodeSlap - Cristian Castiblanco
* Modified by Jiahao Liu [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
-- ExportSQLite: SQLite export plugin for MySQL Workbench
-- Copyright (C) 2009 Thomas Henlich
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of