Skip to content

Instantly share code, notes, and snippets.

View ilatif's full-sized avatar

Imran Latif ilatif

View GitHub Profile
@ilatif
ilatif / links.textile
Created June 17, 2012 06:10 — forked from lucashungaro/links.textile
Links de referência utilizados em minha palestra
@ilatif
ilatif / array_flattener.rb
Created September 29, 2015 11:35
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]
class ArrayFlattener
# ArrayFlattener provides a method to flat nested array.
# For example, it can turn an array like [1, 2 [3, 4]] to [1, 2, 3, 4]
# Class method that can be called on ArrayFlattener that will convert nested array into flat array
def self.flatten(nested_array)
return [] if nested_array.length == 0
self._flatten(nested_array, [])
end
@ilatif
ilatif / customers_invitation.rb
Last active September 29, 2015 11:44
We have some customer records in a text file (customers.json) -- one customer per line, JSON-encoded. We want to invite any customer within 100km of our Dublin office (GPS coordinates 53.3381985, -6.2592576) for some food and drinks on us. Write a program that will read the full list of customers and output the names and user ids of matching cus…
require 'distance_calculator'
require 'json'
class CustomersInvitation
# CustomersInvitation provides methods to invite customers from a given list of customers
# which are x kms away from provided base location's coordinates.
attr_accessor :customers, :invited_customers, :base_latitude, :base_longitude
function largestRange(array) {
if (array.length === 1) {
return [array[0], array[0]];
}
var hash = {};
hash[array[0]] = [];
var current = array[0];
for (var i = 1; i < array.length; i++) {
var temp = array[i];
let profit = 0;
let profits = {};
function maxProfitWithKTransactions(prices, k) {
// Write your code here.
profit = 0;
mainProfit = 0;
profits = {};
let max = 0;
for (let i = 0; i < prices.length; i++) {
process(prices, i, max, k, 1);
<div>
<div class="first">
<div class="top first-color"></div>
<div class="right first-color"></div>
</div>
<div class="second">
<div class="top second-color"></div>
<div class="right second-color"></div>
</div>
</div>