Skip to content

Instantly share code, notes, and snippets.

@anupamkumar
anupamkumar / Ch182.java
Last active August 29, 2015 14:07
dailyprogrammer challenge 182
package dailyprogrammer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
@anupamkumar
anupamkumar / Problem6
Created October 31, 2014 09:27
Permutation of String - Iterative
import java.util.ArrayList;
/**
* all permutations of a string / char array
* @author anupam
*/
public class Problem6 {
public static ArrayList<String> allPerms(String str) {
ArrayList<String> al = new ArrayList<>();
int i=0;
var jsobj = {'badjsobj':'bad';
@anupamkumar
anupamkumar / goodjson.js
Last active August 29, 2015 14:15
goodjson.js
var goodjsobj = {"goodjson":"good"};
@anupamkumar
anupamkumar / .htaccess
Created February 17, 2015 21:23
HTACCESS FILE
RewriteEngine on
RewriteCond %{HTTP_HOST} ^anupamsblog.gear.host$ [OR]
RewriteCond %{HTTP_HOST} ^www.anupamsblog.gear.host" target="_blank">www.anupamsblog.gear.host$
RewriteRule ^php$ http://anupamsblog.gear.host" target="_blank">http://anupamsblog.gear.host [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^anupamsblog.gear.host$ [OR]
RewriteCond %{HTTP_HOST} ^www.anupamsblog.gear.host" target="_blank">www.anupamsblog.gear.host$
RewriteRule ^share$ http://anupamsblog.gear.host" target="_blank">http://anupamsblog.gear.host [R=301,L]
import sys
def minCost(cost,N):
best_way_to_reach = [0]*N
for k in range(1,N):
minimum_cost_to_get_from_0_to_k = sys.maxint
for i in range(k,0,-1):
if(minimum_cost_to_get_from_0_to_k > best_way_to_reach[k-i]+cost[k-i][k]):
minimum_cost_to_get_from_0_to_k = best_way_to_reach[k-i]+cost[k-i][k]
best_way_to_reach[k] = min(minimum_cost_to_get_from_0_to_k,cost[0][k])
@anupamkumar
anupamkumar / gist:818f94c570a9a5419f1c
Last active August 29, 2015 14:17
NumberOfWaysToReachScore
def numOfWaysToTgt(target,allowedUnits)
scores = Array.new(target+1,0)
scores[0] = 1
allowedUnits.each do |allowedScore|
(allowedScore..target).each do |k|
scores[k] += scores[k-allowedScore]
end
end
puts "#{target} can be reached in #{scores[target]} ways"
end
// Maximize number of 0s by flipping a subarray
// Given a binary array, find the maximum number zeros in an array with one flip of a subarray allowed.
// A flip operation switches all 0s to 1s and 1s to 0s.
// Examples:
// Input : arr[] = {0, 1, 0, 0, 1, 1, 0}
// Output : 6
@anupamkumar
anupamkumar / MaximizeArrayDiff.js
Created September 14, 2016 01:35
Maximize value of (arr[i] – i) – (arr[j] – j) in an array
// Maximize value of (arr[i] – i) – (arr[j] – j) in an array
// Given an array, arr[] find the maximum value of (arr[i] – i) – (arr[j] – j) where i is not equal to j.
// Where i and j vary from 0 to n-1 and n is size of input array arr[].
// Examples:
// Input : arr[] = {9, 15, 4, 12, 13}
// Output : 12
@anupamkumar
anupamkumar / StringMatchesPattern2.js
Last active September 16, 2016 01:26
// Check if string follows order of characters defined by a pattern or not | Set 2
// Check if string follows order of characters defined by a pattern or not | Set 2
// Given an input string and a pattern, check if characters in the input string follows the same order as determined by characters present in the pattern.
// Assume there won’t be any duplicate characters in the pattern.
// Another solution to the same problem is posted here.
// Examples: