This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Following test case assumes you have express js server running at port 5000 and has api /api/login | |
var should = require('should'); | |
var assert = require('assert'); | |
var request = require('supertest'); | |
var winston = require('winston'); | |
describe('Routing', function() { | |
var url = 'http://localhost:5000'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void arraySlicing(int[] inputArr) { | |
List<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
for (int i = 0; i <= inputArr.length; i++) { | |
for (int j = i + 1; j <= inputArr.length; j++) { | |
System.out.println(Arrays.toString(Arrays.copyOfRange(inputArr, i, j))); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ListNode reverseList(ListNode head) { | |
ListNode current = head; | |
if (current == null) | |
return null; | |
if (current.next == null) | |
return current; | |
ListNode nextItem = current.next; | |
current.next = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new ArrayList<Element>(Arrays.asList(array)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[] VALUES = new String[] {"AB","BC","CD","AE"}; | |
String value= "AB"; | |
String notExists = "abc"; | |
Arrays.asList(VALUES).contains(value); //TRUE | |
Arrays.asList(VALUES).contains(notExists); //FALSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkedList { | |
private ListNode firstNode; | |
private ListNode lastNode; | |
private int size; | |
/** | |
* For the no-args constructor, the data and next will be null (empty list) | |
*/ | |
public LinkedList() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
permuteString("", "ABCD"); | |
//if endString.lenth <=1 then print | |
//for each character in endString | |
//Remove ith character | |
//permute i, remaining string | |
public static void permuteString(String beginningString, String endingString) { | |
if (endingString.length() <= 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean isCompoundWord(String word) { | |
if (dictionary.contains(word)) return true; | |
for (int i = 1; i < word.length(); i++) { | |
String prefix = word.substring(0, i); | |
if (isCompoundWord(prefix)) { | |
String remainder = word.substring(i, word.length()); | |
if (remainder.length() == 0) return true; | |
return isCompoundWord(remainder); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> Set<Set<T>> powerSet(Set<T> originalSet) { | |
Set<Set<T>> sets = new HashSet<Set<T>>(); | |
if (originalSet.isEmpty()) { | |
sets.add(new HashSet<T>()); | |
return sets; | |
} | |
List<T> list = new ArrayList<T>(originalSet); | |
T head = list.get(0); | |
Set<T> rest = new HashSet<T>(list.subList(1, list.size())); | |
for (Set<T> set : powerSet(rest)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (node->parent && node->parent->right) { | |
return node->parent->right; | |
} else { | |
return NULL; | |
} |