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 void getSubsets(List<Integer> superSet, int k, int idx, Set<Integer> current,List<Set<Integer>> solution) { | |
//successful stop clause | |
if (current.size() == k) { | |
solution.add(new HashSet<>(current)); | |
return; | |
} | |
//unseccessful stop clause | |
if (idx == superSet.size()) return; | |
Integer x = superSet.get(idx); | |
current.add(x); |
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
findCandidate(a[], size) | |
1. Initialize index and count of majority element | |
maj_index = 0, count = 1 | |
2. Loop for i = 1 to size – 1 | |
(a)If a[maj_index] == a[i] | |
count++ | |
(b)Else | |
count--; | |
(c)If count == 0 | |
maj_index = i; |
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
import java.lang.annotation.Documented; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
import javax.ws.rs.HttpMethod; | |
import javax.ws.rs.NameBinding; | |
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
Booting Spring Boot into Heroku | |
FRIDAY, JANUARY 17, 2014 | |
Spring Boot is a new approach from Spring to build web applications. The quote from Spring is that it "takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible." One of the things I like doing when evaluating a new framework is to ensure that I have an environment to deploy my work. So this post will show you how to get a sample Spring Boot application running on heroku. | |
To get started, you need a few prerequistes. | |
JDK 1.7 | |
Maven 3 | |
A Herkou account | |
Heroku command line tools |
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
https://spring.io/guides/gs/accessing-mongodb-data-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
/** | |
* Module dependencies. | |
*/ | |
var express = require('express') | |
, routes = require('./routes') | |
, http = require('http') | |
, mongoose = require('mongoose') | |
, path = require('path'); |
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
git reset --hard # removes staged and working directory changes | |
git clean -f -d # remove untracked files | |
git clean -f -x -d # CAUTION: as above but removes ignored files like config. |
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
Map<String, String> memoized; | |
String SegmentString(String input, Set<String> dict) { | |
if (dict.contains(input)) return input; | |
if (memoized.containsKey(input) { | |
return memoized.get(input); | |
} | |
int len = input.length(); | |
for (int i = 1; i < len; i++) { | |
String prefix = input.substring(0, i); |
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
import java.util.Arrays; | |
public class MaxSumInRectangle { | |
public int start = 0, finish = 0; | |
public int maxSubArraySum(int arr[]) { | |
// initialize sum, maxSum and start | |
int sum = 0, maxSum = Integer.MIN_VALUE, i; | |
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 MaximumRectangle { | |
public static void main(String[] args) | |
{ | |
int nRows = 5, nCols = 6; | |
int[][] boolMatrix = { | |
{1,0,0,1,1,0}, | |
{0,1,1,1,1,0}, | |
{0,1,1,1,1,1}, | |
{1,0,1,1,1,0}, | |
{0,1,1,0,1,1} |