diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index f7de390225..1fb598ef96 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,14 @@
+
+
+
+
+
+
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b0e29ad520..bb5b1dd06d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,52 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -69,6 +110,21 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -81,7 +137,6 @@
-
1618147556538
@@ -174,14 +229,7 @@
1618519836247
-
- 1619208153576
-
-
-
- 1619208153576
-
-
+
@@ -213,7 +261,6 @@
-
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4ca10cc8bf..3306775322 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.ossez
parent-modules
- 0.0.1
+ 0.0.1-SNAPSHOT
pom
CWIKIUS-OSSEZ Java Parent Modules
diff --git a/src/main/java/com/ossez/lang/tutorial/Main.java b/src/main/java/com/ossez/codebank/algorithm/Main.java
similarity index 94%
rename from src/main/java/com/ossez/lang/tutorial/Main.java
rename to src/main/java/com/ossez/codebank/algorithm/Main.java
index 3e743ee941..eb5e8b5d20 100644
--- a/src/main/java/com/ossez/lang/tutorial/Main.java
+++ b/src/main/java/com/ossez/codebank/algorithm/Main.java
@@ -1,4 +1,4 @@
-package com.ossez.lang.tutorial;
+package com.ossez.codebank.algorithm;
import java.util.Properties;
diff --git a/src/main/java/com/ossez/codebank/algorithm/models/ListNode.java b/src/main/java/com/ossez/codebank/algorithm/models/ListNode.java
new file mode 100644
index 0000000000..81a4985eae
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/algorithm/models/ListNode.java
@@ -0,0 +1,16 @@
+package com.ossez.codebank.algorithm.models;
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class ListNode {
+ public int val;
+ public ListNode next;
+
+ public ListNode(int x) {
+ val = x;
+ next = null;
+ }
+}
diff --git a/src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java b/src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java
new file mode 100644
index 0000000000..d879b60b16
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/algorithm/models/TreeNode.java
@@ -0,0 +1,16 @@
+package com.ossez.codebank.algorithm.models;
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class TreeNode {
+ public int val;
+ public TreeNode left, right;
+
+ public TreeNode(int val) {
+ this.val = val;
+ this.left = this.right = null;
+ }
+}
diff --git a/src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java b/src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java
similarity index 83%
rename from src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java
rename to src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java
index ed62dfaf9c..52aaef5c9a 100644
--- a/src/main/java/com/ossez/lang/tutorial/objplusclass/CreateObject.java
+++ b/src/main/java/com/ossez/codebank/algorithm/objplusclass/CreateObject.java
@@ -1,4 +1,4 @@
-package com.ossez.lang.tutorial.objplusclass;
+package com.ossez.codebank.algorithm.objplusclass;
/**
*
diff --git a/src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java b/src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java
similarity index 82%
rename from src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java
rename to src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java
index d4d868528e..131751f93e 100644
--- a/src/main/java/com/ossez/lang/tutorial/overview/FreshJuiceEnums.java
+++ b/src/main/java/com/ossez/codebank/algorithm/overview/FreshJuiceEnums.java
@@ -1,4 +1,4 @@
-package com.ossez.lang.tutorial.overview;
+package com.ossez.codebank.algorithm.overview;
/**
* Java Tutorial
diff --git a/src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java b/src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java
similarity index 81%
rename from src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java
rename to src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java
index 471ec43175..45af846b31 100644
--- a/src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java
+++ b/src/main/java/com/ossez/codebank/algorithm/overview/HelloWorld.java
@@ -1,4 +1,4 @@
-package com.ossez.lang.tutorial.overview;
+package com.ossez.codebank.algorithm.overview;
/**
* Java Tutorial
diff --git a/src/main/java/com/ossez/lang/tutorial/usecases/VarargsCase.java b/src/main/java/com/ossez/codebank/algorithm/usecases/VarargsCase.java
similarity index 100%
rename from src/main/java/com/ossez/lang/tutorial/usecases/VarargsCase.java
rename to src/main/java/com/ossez/codebank/algorithm/usecases/VarargsCase.java
diff --git a/src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java b/src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java
similarity index 85%
rename from src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java
rename to src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java
index ead47224c0..aafa847383 100644
--- a/src/main/java/com/ossez/lang/tutorial/utils/TreeUtils.java
+++ b/src/main/java/com/ossez/codebank/algorithml/utils/TreeUtils.java
@@ -1,55 +1,55 @@
-package com.ossez.lang.tutorial.utils;
-
-import java.util.ArrayList;
-
-import com.ossez.lang.tutorial.models.TreeNode;
-
-/**
- *
- * @author YuCheng
- *
- */
-public class TreeUtils {
-
- public static TreeNode initTree(String data) {
- // NULL CHECK
- if (data.equals("{}")) {
- return null;
- }
-
- ArrayList treeList = new ArrayList();
-
- data = data.replace("{", "");
- data = data.replace("}", "");
- String[] vals = data.split(",");
-
- // INSERT ROOT
- TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
- treeList.add(root);
-
- int index = 0;
- boolean isLeftChild = true;
- for (int i = 1; i < vals.length; i++) {
- if (!vals[i].equals("#")) {
- TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
- if (isLeftChild) {
- treeList.get(index).left = node;
- } else {
- treeList.get(index).right = node;
- }
- treeList.add(node);
- }
-
- // LEVEL
- if (!isLeftChild) {
- index++;
- }
-
- // MOVE TO RIGHT OR NEXT LEVEL
- isLeftChild = !isLeftChild;
- }
-
- return root;
-
- }
-}
+package com.ossez.codebank.algorithml.utils;
+
+import java.util.ArrayList;
+
+import com.ossez.codebank.algorithm.models.TreeNode;
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class TreeUtils {
+
+ public static TreeNode initTree(String data) {
+ // NULL CHECK
+ if (data.equals("{}")) {
+ return null;
+ }
+
+ ArrayList treeList = new ArrayList();
+
+ data = data.replace("{", "");
+ data = data.replace("}", "");
+ String[] vals = data.split(",");
+
+ // INSERT ROOT
+ TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
+ treeList.add(root);
+
+ int index = 0;
+ boolean isLeftChild = true;
+ for (int i = 1; i < vals.length; i++) {
+ if (!vals[i].equals("#")) {
+ TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
+ if (isLeftChild) {
+ treeList.get(index).left = node;
+ } else {
+ treeList.get(index).right = node;
+ }
+ treeList.add(node);
+ }
+
+ // LEVEL
+ if (!isLeftChild) {
+ index++;
+ }
+
+ // MOVE TO RIGHT OR NEXT LEVEL
+ isLeftChild = !isLeftChild;
+ }
+
+ return root;
+
+ }
+}
diff --git a/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java
new file mode 100644
index 0000000000..fa272b22a1
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/interview/KayakCountUpDown.java
@@ -0,0 +1,86 @@
+package com.ossez.codebank.interview;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Count+Up+Down
+ *
+ * @author YuCheng
+ *
+ */
+public class KayakCountUpDown {
+ private final static Logger logger = LoggerFactory.getLogger(KayakCountUpDown.class);
+
+ static int minNumber = 0;
+ static int maxNumber = 0;
+ int tmpN = 0;
+ List retList = new ArrayList();
+
+ /**
+ *
+ * @param start
+ * @param end
+ * @return
+ */
+ public List countUp(int start, int end) {
+ logger.debug("BEGIN");
+ maxNumber = end;
+ tmpN = start;
+ moveUp(0);
+ retList.add(end);
+ return retList;
+
+ }
+
+ /**
+ *
+ * @param start
+ * @param end
+ * @return
+ */
+ public List countUpDown(int start, int end) {
+ logger.debug("BEGIN");
+ minNumber = start;
+ maxNumber = end;
+ tmpN = start;
+
+ moveUp(0);
+ retList.add(end);
+
+ moveDown(1);
+ return retList;
+
+ }
+
+ /**
+ *
+ * @param n
+ */
+ private void moveUp(int n) {
+ retList.add(tmpN);
+ tmpN++;
+ if (tmpN != maxNumber) {
+ moveUp(tmpN + 1);
+ }
+
+ }
+
+ /**
+ *
+ * @param n
+ */
+ private void moveDown(int n) {
+ tmpN = (maxNumber - n);
+ retList.add(tmpN);
+
+ if (tmpN != minNumber) {
+ moveDown(n + 1);
+ }
+ }
+
+}
diff --git a/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java
new file mode 100644
index 0000000000..22cb653292
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/interview/KayakRobotMovement.java
@@ -0,0 +1,47 @@
+package com.ossez.codebank.interview;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Robot+Movement
+ *
+ * @author YuCheng
+ *
+ */
+public class KayakRobotMovement {
+
+ private final static Logger logger = LoggerFactory.getLogger(KayakRobotMovement.class);
+
+ /**
+ * Get coordinates for Robot Movement
+ *
+ * @param data
+ * @return
+ */
+ public static String getCoordinates(String data) {
+ logger.debug("BEGIN");
+
+ String retStr = "";
+
+ int x = 0;
+ int y = 0;
+ int[][] move = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
+ int dir = 0;
+
+ for (char ch : data.toCharArray()) {
+ if (ch == 'F') {
+ x += move[dir][0];
+ y += move[dir][1];
+ } else if (ch == 'L') {
+ dir--;
+ } else if (ch == 'R') {
+ dir++;
+ }
+ dir = (dir + 4) % 4;
+ }
+ retStr = x + "," + y;
+
+ return retStr;
+ }
+}
diff --git a/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java b/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java
new file mode 100644
index 0000000000..d98b2da869
--- /dev/null
+++ b/src/main/java/com/ossez/codebank/interview/ManNextFibonacciNumber.java
@@ -0,0 +1,68 @@
+package com.ossez.codebank.interview;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Next+Fibonacci+Number
+ *
+ * @author YuCheng
+ *
+ */
+public class ManNextFibonacciNumber {
+ private final static Logger logger = LoggerFactory.getLogger(ManNextFibonacciNumber.class);
+
+ public static void main(String[] args) throws java.lang.Exception {
+ int fArray[] = new int[60];
+
+ for (int i = 0; i < 60; i++) {
+ fArray[i] = getFib(i);
+ }
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String input = br.readLine();
+ // System.out.println(fib(Integer.valueOf(input)));
+
+ for (int i = 0; i < Integer.valueOf(input); i++) {
+ Integer inputInt = Integer.valueOf(br.readLine());
+ // System.out.println(inputInt);
+ for (int j = 0; j < fArray.length; j++) {
+ if (fArray[j] > inputInt) {
+ // System.out.println(fArray[j]);
+ logger.debug("{} Next Fibonacci [{}]", inputInt, fArray[j]);
+ break;
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * Get Fibonacci Number
+ *
+ * @param n
+ * @return
+ */
+ private static int getFib(int n) {
+ if (n < 0) {
+ return -1;
+ } else if (n == 0) {
+ return 0;
+ } else if (n == 1 || n == 2) {
+ return 1;
+ } else {
+ int[] fibAry = new int[n + 1];
+ fibAry[0] = 0;
+ fibAry[1] = fibAry[2] = 1;
+ for (int i = 3; i <= n; i++) {
+ fibAry[i] = fibAry[i - 1] + fibAry[i - 2];
+ }
+ return fibAry[n];
+ }
+ }
+}
diff --git a/src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java
similarity index 90%
rename from src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java
rename to src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java
index eb570df0dd..257c6a3a68 100644
--- a/src/test/java/com/ossez/lang/tutorial/tests/BitOperationTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/BitOperationTest.java
@@ -1,36 +1,36 @@
-package com.ossez.lang.tutorial.tests;
-
-import org.apache.commons.math3.util.FastMath;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author YuCheng
- *
- */
-public class BitOperationTest {
-
- private final static Logger logger = LoggerFactory.getLogger(BitOperationTest.class);
-
- /**
- * 35 https://www.lintcode.com/problem/reverse-linked-list/description
- */
- @Test
- public void testInt2Bit() {
- logger.debug("BEGIN");
- System.out.println(Integer.toBinaryString(5));
- System.out.println(Integer.toBinaryString(2));
-
- System.out.println(Integer.toBinaryString(2 << 2));
-
- System.out.println(Integer.parseInt(Integer.toBinaryString(2 << 2), 2));
-
- System.out.println(5 / 3);
- System.out.println(5 % 3);
- FastMath.pow(2, 3);
-
- }
-
-}
+package com.ossez.codebank.algorithm.tests;
+
+import org.apache.commons.math3.util.FastMath;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class BitOperationTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(BitOperationTest.class);
+
+ /**
+ * 35 https://www.lintcode.com/problem/reverse-linked-list/description
+ */
+ @Test
+ public void testInt2Bit() {
+ logger.debug("BEGIN");
+ System.out.println(Integer.toBinaryString(5));
+ System.out.println(Integer.toBinaryString(2));
+
+ System.out.println(Integer.toBinaryString(2 << 2));
+
+ System.out.println(Integer.parseInt(Integer.toBinaryString(2 << 2), 2));
+
+ System.out.println(5 / 3);
+ System.out.println(5 % 3);
+ FastMath.pow(2, 3);
+
+ }
+
+}
diff --git a/src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
similarity index 97%
rename from src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java
rename to src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
index 139295c4b1..7cf699092d 100644
--- a/src/test/java/com/ossez/lang/tutorial/tests/LintcodeTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/LintcodeTest.java
@@ -2,11 +2,17 @@ package com.ossez.lang.tutorial.tests;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
+import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.management.ListenerNotFoundException;
+
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java
similarity index 91%
rename from src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java
rename to src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java
index a6cd888777..041a9b840c 100644
--- a/src/test/java/com/ossez/lang/tutorial/tests/SingletonTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/SingletonTest.java
@@ -1,4 +1,4 @@
-package com.ossez.lang.tutorial.tests;
+package com.ossez.codebank.algorithm.tests;
import org.junit.Test;
import org.slf4j.Logger;
diff --git a/src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
similarity index 86%
rename from src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java
rename to src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
index ee67e07c05..93a489f5bb 100644
--- a/src/test/java/com/ossez/lang/tutorial/tests/TreeTest.java
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/TreeTest.java
@@ -1,85 +1,85 @@
-package com.ossez.lang.tutorial.tests;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.ossez.lang.tutorial.models.TreeNode;
-import com.ossez.lang.tutorial.utils.TreeUtils;
-
-/**
- *
- * @author YuCheng
- *
- */
-public class TreeTest {
- private final static Logger logger = LoggerFactory.getLogger(TreeTest.class);
- private static List loopList = new ArrayList();
-
- @Test
- public void testMain() {
- logger.debug("TREE TEST");
- String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}";
- TreeNode treeNode = TreeUtils.initTree(data);
-
- // PRE
- loopList = new ArrayList();
- preOrderTraverselRecursion(treeNode);
- System.out.println(loopList);
-
- // IN
- loopList = new ArrayList();
- inOrderTraverselRecursion(treeNode);
- System.out.println(loopList);
-
- // POST
- loopList = new ArrayList();
- postOrderTraversalRecursion(treeNode);
- System.out.println(loopList);
- }
-
-
-
-
- /**
- *
- * @param root
- */
- public void preOrderTraverselRecursion(TreeNode root) {
- if (root != null) {
- loopList.add(root.val);
- preOrderTraverselRecursion(root.left);
- preOrderTraverselRecursion(root.right);
- }
- }
-
- /**
- *
- * @param root
- */
- public void inOrderTraverselRecursion(TreeNode root) {
- if (root != null) {
- inOrderTraverselRecursion(root.left);
- loopList.add(root.val);
- inOrderTraverselRecursion(root.right);
- }
-
- }
-
- /**
- *
- * @param root
- */
- public void postOrderTraversalRecursion(TreeNode root) {
- if (root != null) {
- postOrderTraversalRecursion(root.left);
- postOrderTraversalRecursion(root.right);
- loopList.add(root.val);
- }
-
- }
-
-}
+package com.ossez.codebank.algorithm.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.algorithm.models.TreeNode;
+import com.ossez.codebank.algorithml.utils.TreeUtils;
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class TreeTest {
+ private final static Logger logger = LoggerFactory.getLogger(TreeTest.class);
+ private static List loopList = new ArrayList();
+
+ @Test
+ public void testMain() {
+ logger.debug("TREE TEST");
+ String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}";
+ TreeNode treeNode = TreeUtils.initTree(data);
+
+ // PRE
+ loopList = new ArrayList();
+ preOrderTraverselRecursion(treeNode);
+ System.out.println(loopList);
+
+ // IN
+ loopList = new ArrayList();
+ inOrderTraverselRecursion(treeNode);
+ System.out.println(loopList);
+
+ // POST
+ loopList = new ArrayList();
+ postOrderTraversalRecursion(treeNode);
+ System.out.println(loopList);
+ }
+
+
+
+
+ /**
+ *
+ * @param root
+ */
+ public void preOrderTraverselRecursion(TreeNode root) {
+ if (root != null) {
+ loopList.add(root.val);
+ preOrderTraverselRecursion(root.left);
+ preOrderTraverselRecursion(root.right);
+ }
+ }
+
+ /**
+ *
+ * @param root
+ */
+ public void inOrderTraverselRecursion(TreeNode root) {
+ if (root != null) {
+ inOrderTraverselRecursion(root.left);
+ loopList.add(root.val);
+ inOrderTraverselRecursion(root.right);
+ }
+
+ }
+
+ /**
+ *
+ * @param root
+ */
+ public void postOrderTraversalRecursion(TreeNode root) {
+ if (root != null) {
+ postOrderTraversalRecursion(root.left);
+ postOrderTraversalRecursion(root.right);
+ loopList.add(root.val);
+ }
+
+ }
+
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java
new file mode 100644
index 0000000000..a4cfa28a76
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/VariableTest.java
@@ -0,0 +1,49 @@
+package com.ossez.codebank.algorithm.tests;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Object of VariableOssez
+ *
+ * @author YuCheng
+ *
+ */
+class OssezVariable {
+ int s1, s2;
+ static int s3;
+
+ OssezVariable(int x, int y, int z) {
+ s1 = x;
+ s2 = y;
+ s3 = z;
+ }
+}
+
+/**
+ *
+ * @author YuCheng
+ *
+ */
+public class VariableTest extends TestCase {
+
+ private final static Logger logger = LoggerFactory.getLogger(VariableTest.class);
+
+ /**
+ * Do RetsServerConnection Test
+ */
+ @Test
+ public void testStaticVariableChange() {
+
+ OssezVariable objA = new OssezVariable(1, 2, 3);
+ logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
+
+ OssezVariable objB = new OssezVariable(4, 5, 6);
+ logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
+ logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objB.s1, objB.s2, OssezVariable.s3);
+ }
+
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java
new file mode 100644
index 0000000000..88c4405f13
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/codility/CodilityBinaryGapTest.java
@@ -0,0 +1,56 @@
+package com.ossez.codebank.algorithm.tests.codility;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * More details about question see link below
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class CodilityBinaryGapTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(CodilityBinaryGapTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+
+ int N = 529;
+ String intStr = Integer.toBinaryString(N);
+
+ intStr = intStr.replace("1", "#1#");
+
+ String[] strArray = intStr.split("1");
+
+ int maxCount = 0;
+ for (int i = 0; i < strArray.length; i++) {
+ String checkStr = strArray[i];
+ int countLength = 0;
+
+ if (checkStr.length() > 2 && checkStr.startsWith("#") && checkStr.endsWith("#")) {
+ checkStr = checkStr.replace("#", "");
+ countLength = checkStr.length();
+
+ if (maxCount < countLength) {
+ maxCount = countLength;
+ }
+
+ }
+ }
+
+ logger.debug("MAX COUNT: [{}]", maxCount);
+ }
+
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java
new file mode 100644
index 0000000000..d1c3438ff8
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0007SerializeAndDeserializeTest.java
@@ -0,0 +1,131 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.algorithm.models.TreeNode;
+
+/**
+ *
+ * 7
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0007SerializeAndDeserializeTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0007SerializeAndDeserializeTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ String data = "{3,9,20,#,#,15,7}";
+
+ System.out.println(serialize(deserialize(data)));
+
+ }
+
+ /**
+ * Deserialize from array to tree
+ *
+ * @param data
+ * @return
+ */
+ private TreeNode deserialize(String data) {
+ // NULL CHECK
+ if (data.equals("{}")) {
+ return null;
+ }
+
+ ArrayList treeList = new ArrayList();
+
+ data = data.replace("{", "");
+ data = data.replace("}", "");
+ String[] vals = data.split(",");
+
+ // INSERT ROOT
+ TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
+ treeList.add(root);
+
+ int index = 0;
+ boolean isLeftChild = true;
+ for (int i = 1; i < vals.length; i++) {
+ if (!vals[i].equals("#")) {
+ TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
+ if (isLeftChild) {
+ treeList.get(index).left = node;
+ } else {
+ treeList.get(index).right = node;
+ }
+ treeList.add(node);
+ }
+
+ // LEVEL
+ if (!isLeftChild) {
+ index++;
+ }
+
+ // MOVE TO RIGHT OR NEXT LEVEL
+ isLeftChild = !isLeftChild;
+ }
+
+ return root;
+
+ }
+
+ /**
+ *
+ * @param root
+ * @return
+ */
+ public String serialize(TreeNode root) {
+ // write your code here
+ if (root == null) {
+ return "{}";
+ }
+
+ ArrayList queue = new ArrayList();
+ queue.add(root);
+
+ for (int i = 0; i < queue.size(); i++) {
+ TreeNode node = queue.get(i);
+ if (node == null) {
+ continue;
+ }
+ queue.add(node.left);
+ queue.add(node.right);
+ }
+
+ while (queue.get(queue.size() - 1) == null) {
+ queue.remove(queue.size() - 1);
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("{");
+ sb.append(queue.get(0).val);
+ for (int i = 1; i < queue.size(); i++) {
+ if (queue.get(i) == null) {
+ sb.append(",#");
+ } else {
+ sb.append(",");
+ sb.append(queue.get(i).val);
+ }
+ }
+ sb.append("}");
+ return sb.toString();
+ }
+
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java
new file mode 100644
index 0000000000..75633c8b25
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0069LevelOrderTest.java
@@ -0,0 +1,124 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.algorithm.models.TreeNode;
+
+/**
+ *
+ * 69
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0069LevelOrderTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0069LevelOrderTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ String data = "{3,9,20,#,#,15,7}";
+
+ TreeNode tn = deserialize(data);
+ System.out.println(levelOrder(tn));
+
+ }
+
+ /**
+ * Deserialize from array to tree
+ *
+ * @param data
+ * @return
+ */
+ private TreeNode deserialize(String data) {
+ // NULL CHECK
+ if (data.equals("{}")) {
+ return null;
+ }
+
+ ArrayList treeList = new ArrayList();
+
+ data = data.replace("{", "");
+ data = data.replace("}", "");
+ String[] vals = data.split(",");
+
+ // INSERT ROOT
+ TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
+ treeList.add(root);
+
+ int index = 0;
+ boolean isLeftChild = true;
+ for (int i = 1; i < vals.length; i++) {
+ if (!vals[i].equals("#")) {
+ TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
+ if (isLeftChild) {
+ treeList.get(index).left = node;
+ } else {
+ treeList.get(index).right = node;
+ }
+ treeList.add(node);
+ }
+
+ // LEVEL
+ if (!isLeftChild) {
+ index++;
+ }
+
+ // MOVE TO RIGHT OR NEXT LEVEL
+ isLeftChild = !isLeftChild;
+ }
+
+ return root;
+
+ }
+
+ private List> levelOrder(TreeNode root) {
+ Queue queue = new LinkedList();
+ List> rs = new ArrayList>();
+
+ // NULL CHECK
+ if (root == null) {
+ return rs;
+ }
+
+ queue.offer(root);
+
+ while (!queue.isEmpty()) {
+ int length = queue.size();
+ List list = new ArrayList();
+
+ for (int i = 0; i < length; i++) {
+ TreeNode curTN = queue.poll();
+ list.add(curTN.val);
+ if (curTN.left != null) {
+ queue.offer(curTN.left);
+ }
+ if (curTN.right != null) {
+ queue.offer(curTN.right);
+ }
+ }
+
+ rs.add(list);
+ }
+
+ return rs;
+ }
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java
new file mode 100644
index 0000000000..8e63d7cdd2
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0102HasCycleTest.java
@@ -0,0 +1,63 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.algorithm.models.ListNode;
+
+/**
+ *
+ * 102
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0102HasCycleTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0102HasCycleTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ // INIT LINKED LIST
+ ListNode head = new ListNode(1);
+ head.next = new ListNode(2);
+ head.next.next = new ListNode(3);
+ head.next.next.next = new ListNode(4);
+
+ // CREATE A LOOP
+ head.next.next.next.next = head.next.next.next;
+
+ boolean retResult = false;
+
+ // LIKED LIST MAY NULL:
+ if (!(head == null || head.next == null)) {
+ ListNode s = head;
+ ListNode f = head.next;
+
+ while (f.next != null && f.next.next != null) {
+
+ s = s.next;
+ f = f.next.next;
+
+ if (f == s) {
+ retResult = true;
+ break;
+ }
+ }
+ }
+
+ System.out.println(retResult);
+
+ }
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java
new file mode 100644
index 0000000000..15d4fa17e4
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0165MergeTwoListsTest.java
@@ -0,0 +1,89 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ossez.codebank.algorithm.models.ListNode;
+
+/**
+ *
+ * 102
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0165MergeTwoListsTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0165MergeTwoListsTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ // INIT LINKED LIST l1
+ ListNode l1 = new ListNode(1);
+ l1.next = new ListNode(3);
+ l1.next.next = new ListNode(8);
+ l1.next.next.next = new ListNode(11);
+ l1.next.next.next.next = new ListNode(15);
+
+ // INIT LINKED LIST l2
+ ListNode l2 = new ListNode(2);
+
+ // RETURN RESULT
+ ListNode retResult = new ListNode(0);
+
+ // NULL CHECK
+ // if (l1 == null && l2 == null) {
+ // retResult = null;
+ // }
+ //
+ // if (l1 == null) {
+ // retResult = l2;
+ // }
+ //
+ // if (l2 == null) {
+ // retResult = l1;
+ // }
+
+ // MERGE
+ retResult = new ListNode(0);
+ ListNode tmpNode = new ListNode(0);
+ retResult = tmpNode;
+ while (l1 != null & l2 != null) {
+ if (l1.val <= l2.val) {
+ tmpNode.next = l1;
+ l1 = l1.next;
+ } else {
+ tmpNode.next = l2;
+ l2 = l2.next;
+ }
+
+ tmpNode = tmpNode.next;
+ }
+
+ if (l1 == null) {
+ tmpNode.next = l2;
+ }
+
+ if (l2 == null) {
+ tmpNode.next = l1;
+ }
+
+ retResult = retResult.next;
+
+ System.out.println(retResult.val);
+ System.out.println(retResult.next.val);
+ System.out.println(retResult.next.next.val);
+
+ }
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java
new file mode 100644
index 0000000000..328f7a3367
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0425LetterCombinationsTest.java
@@ -0,0 +1,78 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 425
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0425LetterCombinationsTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0425LetterCombinationsTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("LetterCombinationsTest");
+ String digits = "23";
+
+ HashMap phoneKeyMap = new HashMap();
+ phoneKeyMap.put("0", "");
+ phoneKeyMap.put("1", "");
+ phoneKeyMap.put("2", "abc");
+ phoneKeyMap.put("3", "def");
+ phoneKeyMap.put("4", "ghi");
+ phoneKeyMap.put("5", "jkl");
+ phoneKeyMap.put("6", "mno");
+ phoneKeyMap.put("7", "pqrs");
+ phoneKeyMap.put("8", "tuv");
+ phoneKeyMap.put("9", "wxyz");
+
+ List retStatus = new ArrayList<>();
+
+ if (digits != null && digits.length() != 0) {
+ phoneRecursive(digits, retStatus, phoneKeyMap, "", 0);
+ }
+
+ System.out.println(retStatus);
+ }
+
+ /**
+ * phoneRecursive
+ *
+ * @param digits
+ * @param retStatus
+ * @param phoneKeyMap
+ * @param comb
+ * @param index
+ */
+ private void phoneRecursive(String digits, List retStatus, HashMap phoneKeyMap, String comb, int index) {
+ if (index == digits.length()) {
+ retStatus.add(comb);
+ return;
+ }
+
+ char pos = digits.charAt(index);
+ for (char c : ((String) phoneKeyMap.get(String.valueOf(pos))).toCharArray()) {
+ phoneRecursive(digits, retStatus, phoneKeyMap, comb + c, index + 1);
+ }
+ }
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java
new file mode 100644
index 0000000000..0e8d5cd08c
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode0433NumIslandsTest.java
@@ -0,0 +1,94 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 433
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0433NumIslandsTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0433NumIslandsTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ // INIT GRID
+ boolean[][] grid = { { true, true, false, false, false }, { false, true, false, false, true }, { false, false, false, true, true },
+ { false, false, false, false, false }, { false, false, false, false, true }
+
+ };
+
+ // NULL CHECK
+ if (grid.length == 0 || grid[0].length == 0) {
+ System.out.println("NULL");
+ // return 0;
+ }
+
+ // GET SIZE
+ int n = grid.length;
+ int m = grid[0].length;
+
+ // ARRAY FOR VISITED LOG
+ boolean[][] visited = new boolean[n][m];
+
+ int count = 0;
+
+ // LOOP FOR GRID
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < m; j++) {
+ if (grid[i][j] && !visited[i][j]) {
+ numIslandsDFS(grid, visited, i, j);
+ count++;
+ }
+ }
+ }
+
+ System.out.println(count);
+
+ }
+
+ /**
+ *
+ * @param grid
+ * @param visited
+ * @param x
+ * @param y
+ */
+ public void numIslandsDFS(boolean[][] grid, boolean[][] visited, int x, int y) {
+ if (x < 0 || x >= grid.length) {
+ return;
+ }
+
+ if (y < 0 || y >= grid[0].length) {
+ return;
+ }
+
+ if (grid[x][y] != true || visited[x][y]) {
+ return;
+ }
+
+ visited[x][y] = true;
+
+ // Recursive call
+ numIslandsDFS(grid, visited, x - 1, y);
+ numIslandsDFS(grid, visited, x + 1, y);
+ numIslandsDFS(grid, visited, x, y - 1);
+ numIslandsDFS(grid, visited, x, y + 1);
+
+ }
+}
diff --git a/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java
new file mode 100644
index 0000000000..b32db4bf6f
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/algorithm/tests/lintcode/LintCode1480DotProductTest.java
@@ -0,0 +1,35 @@
+package com.ossez.codebank.algorithm.tests.lintcode;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 1480
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode1480DotProductTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode1480DotProductTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("BEGIN");
+ int t = 87;
+ int[] dur = { 20, 25, 19, 37 };
+ // Write your code here
+ }
+
+}
diff --git a/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java b/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java
new file mode 100644
index 0000000000..df2101b3ca
--- /dev/null
+++ b/src/test/java/com/ossez/codebank/interview/tests/AmazonTest.java
@@ -0,0 +1,210 @@
+package com.ossez.codebank.interview.tests;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Amazon
+ *
+ *
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class AmazonTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(AmazonTest.class);
+
+ List returnList = new ArrayList();
+
+ /**
+ * https://www.cwiki.us/display/ITCLASSIFICATION/Flatten+Nested+Arrays
+ *
+ * FlattenNestedArrays
+ */
+ @Test
+ public void testFlattenNestedArrays() {
+ logger.debug("Test FlattenNestedArrays");
+ int numRows = 3;
+ int numColumns = 3;
+ List> area = new ArrayList>();
+ List a1 = new ArrayList();
+ List a2 = new ArrayList();
+ List a3 = new ArrayList();
+
+ a1.add(1);
+ a1.add(0);
+ a1.add(0);
+
+ a2.add(1);
+ a2.add(0);
+ a2.add(0);
+
+ a3.add(1);
+ a3.add(9);
+ a3.add(1);
+ area.add(a1);
+ area.add(a2);
+ area.add(a3);
+
+ int countD = 0;
+
+ int x = 0;
+ int y = 0;
+
+ for (int i = 0; i < area.size(); i++) {
+ boolean found9 = false;
+ y = 0;
+
+ List xList = area.get(i);
+ for (int j = 0; j < xList.size(); j++) {
+ if (xList.get(j) != 9) {
+ y++;
+ } else {
+ found9 = true;
+ break;
+ }
+
+ }
+
+ if (found9) {
+ break;
+ }
+
+ x++;
+
+ }
+
+ int carX = 0;
+ int carY = 0;
+
+ for (int k = 0; k < numRows * numRows; k++) {
+
+ String command = makeMove(carX, carY, numRows, numColumns, area);
+
+ if (command != null) {
+
+ if (command.equals("U")) {
+ carY = carY + 1;
+ }
+ if (command.equals("R")) {
+ carX = carX + 1;
+ }
+ if (command.equals("L")) {
+ carX = carX - 1;
+ }
+ if (command.equals("D")) {
+ carY = carY + 1;
+ }
+
+ countD = countD + 1;
+
+ if (carX == x && carY == y) {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ System.out.println("---" + x + y);
+ System.out.println("--COUNT-" + countD );
+
+ }
+
+ /**
+ * Java 8 Stream to Flatten array.
+ *
+ * @param array
+ * @return
+ */
+ private static String makeMove(int carX, int carY, int numRows, int numColumns, List> area) {
+
+
+
+ if ((carX + 1 0 && area.get(carX + 1).get(carY) !=9 )
+ if (area.get(carX - 1).get(carY) == 1)
+ return "L";
+ else
+ return "F";
+
+ else if (carX > 0 && carY > 0 && area.get(carX - 1).get(carY - 1) == 1)
+ return "D";
+
+ return null;
+ }
+
+ /**
+ * Loop And Recursive
+ *
+ * @param inputArray
+ * @return
+ * @throws IllegalArgumentException
+ */
+ private List> nearestVegetarianRestaurant(int totalRestaurants, List> allLocations, int numRestaurants) {
+ // WRITE YOUR CODE HERE
+
+ List> ret = new ArrayList>();
+ HashMap> mp = new HashMap>();
+ Double[] keyArray = new Double[totalRestaurants];
+
+ int i = 0;
+ for (List al : allLocations) {
+ Double dis = getDis(al.get(0), al.get(1));
+ mp.put(dis, al);
+ keyArray[i] = dis;
+
+ i++;
+ }
+
+ Arrays.sort(keyArray);
+ for (int j = 0; j < numRestaurants; j++) {
+ ret.add(mp.get(keyArray[j]));
+ }
+
+ return null;
+ }
+
+ private Double getDis(int a, int b) {
+ // WRITE YOUR CODE HERE
+
+ return Math.sqrt(a * a + b * b);
+
+ }
+
+ /**
+ * Java 8 Stream to Flatten array.
+ *
+ * @param array
+ * @return
+ */
+ private static Stream