This file contains hidden or 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <inttypes.h> | |
struct Node | |
{ | |
int data; | |
struct Node* npx; /* XOR of next and previous node */ | |
}; | |
This file contains hidden or 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
mapping=["1", "2", "3", "4", "5", "6", "7" "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"] | |
encodedCases = ["918", "739", "1142", "56", "82", "118", "1219", "6", "862", "1111"] | |
def decodeNumber(decoded, mapping): | |
count=0 | |
checkFirstLast=0 | |
for i in range(9, len(mapping)): | |
if mapping[i] in decoded: |
This file contains hidden or 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
#!/usr/bin/env ruby | |
dictionary = ["Dog", "Deer", "Deal"] | |
def autocomplete(search, dict) | |
result = Array.new | |
if dict.respond_to?("each") | |
dict.each do |d| | |
if search.eql? d[0..search.length-1] | |
result << d |
This file contains hidden or 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
#!/usr/bin/env python | |
def staircase(n, X): | |
cache = [0 for _ in range(n + 1)] | |
cache[0] = 1 | |
for i in range(n + 1): | |
cache[i] += sum(cache[i - x] for x in X if i - x > 0) | |
cache[i] += 1 if i in X else 0 | |
return cache[-1] |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'set' | |
def distinct_char(s,k) | |
#assert(len(s) >= k) | |
start_idx, end_idx, max_length = 0, k, k | |
while end_idx < s.length do | |
end_idx += 1 | |
while true do |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def pi_estimation(r=5) | |
inside =0.0 | |
outside = 0.0 | |
total = 0.0 | |
rnd = Random.new | |
for i in 1 ... 10000 | |
x = rnd.rand(-1*inside..inside) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def random_element(stream) | |
size = stream.length | |
rnd = Random.rand(size) | |
return stream[rnd] | |
end | |
stream = [22,44,33,55] | |
for i in 0..1000 |
This file contains hidden or 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
#!/usr/bin/env ruby | |
class Log | |
def initialize(log=["1","2","3","4"]) | |
@log = log | |
end | |
def size | |
return @log.length | |
end | |
def record(order_id) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def longest_absolute_path(paths, skips) | |
size = 0; | |
paths.each do |p| | |
skips.each do |skip| | |
p.sub(skip, '') | |
end | |
end | |
return paths.max.length |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def maximum_subarray_values(k, arr) | |
max_vals = Array.new | |
arr.each do |i| | |
if max_vals.length == 0 || max_vals.length < k | |
max_vals << i | |
else | |
if i > max_vals.min |