Skip to content

Instantly share code, notes, and snippets.

View kylelong's full-sized avatar
🌴
On vacation

Kyle Long kylelong

🌴
On vacation
View GitHub Profile
@kylelong
kylelong / maxRange.rb
Last active June 9, 2019 05:01
6/2/19 Cassido's interview question of the week
#Given an array of integers, find the maximum range between two elements in the array.
def maxRange(arr)
return arr.max.abs - arr.min.abs
end
puts maxRange([2,2,1,3]) #2
puts maxRange([0]) #0
puts maxRange([4,3,5,7,1,7,7,6]) #6
@kylelong
kylelong / division.rb
Created June 3, 2019 05:04
Cassido's interview question for week of 5/26/19 - Implement integer division
=begin
Integer dvision for a / b
@param a first number
@param b second number
@return a / b
=end
def divide(a, b)
sign = (a < 0) ^ (b < 0) ? -1 : 1
a = a.abs
b = b.abs
@kylelong
kylelong / lastUnique.java
Last active May 22, 2019 03:56
Cassido's interview question of the week 5/19/19 - Find the last non-repeating character in a given string.
import java.util.HashMap;
/**
* Created by kylel95 on 5/21/19.
* Find the last non-repeating character in a given string.
*/
public class lastUnique {
public static void main(String [] args){
String s = "candy canes do taste yummy";
@kylelong
kylelong / trailing.rb
Created March 29, 2019 22:34
Cassido's interview question of the week (3/24/19)
#Given an integer N, find the number of trailing zeroes
# in the base 16 representation of the factorial of N.
def trailing(number)
num = factorial(number).to_s(16)
length = num.length
chars = num.split('')
count = 0
for c in num.split('').reverse()
if(c == '0')
count += 1
@kylelong
kylelong / squarecubed.js
Last active March 21, 2019 17:28
Cassido's newsletter interview question of the week 3/18
let nums = []
function squareCubeNums(num){
for(var i = 1; i <= num; i++){nums[i] = i;}
//Check for perfect square && check for perfect cube
nums = nums.filter(number => Math.floor(Math.sqrt(number)) - Math.sqrt(number) == 0 && Math.pow(Math.round(Math.pow(number, 1/3)), 3) == number);
console.log(nums);
}
squareCubeNums(64);
@kylelong
kylelong / phonePad.java
Created March 3, 2019 03:34
Cassido's weekly newsletter interview question of the week 2/24/19
import java.util.*;
/**
* Created by kylel95 on 3/1/19.
*/
public class phonePad {
public static void main(String [] args){
String s = "123456";
perm1(makeString(s));
}
@kylelong
kylelong / removeOdd.java
Created February 24, 2019 06:43
Week of 2/17/19 Cassido's interview question of the week
/**
* Created by Kyle Long on 2/24/19.
*/
public class removeOdd {
public static void main(String [] args){
System.out.println(removeForOdd(new int[]{2,4,6,7,8}));
System.out.println(removeForOdd(new int[]{4,4,4}));
System.out.println(removeForOdd(new int[]{1,2,3,4,5,6,7}));
}
@kylelong
kylelong / charsToPalindrome.java
Last active February 13, 2019 05:05
Cassido's weekly interview problem (2/10/19)
/**
* Created by Kyle Long on 2/12/19.
*/
public class charsToPalindrome {
public static void main(String [] args){
String s = "hi"; //hi -> hih or ihi
String s1 = "xx"; //already palindrome
String s2 = "race"; //racecar
String s3 = "abcdabc"; //not possible to convert into a palindrome
System.out.println(makeAPal(s));
@kylelong
kylelong / foop.txt
Last active February 10, 2019 00:03
Functional & Object Oriented Programming
Functional Programming
----------------------
Throughout our daily or weekly lives, we often do several tasks repeatedly. For example, brushing your teeth,
introducing yourself to a stranger, making your bed, etc. It would be very convenient if we could snap our fingers
and say, "Make my bed" after every night’s rest. Unfortunately, this is not (yet) the case. Well, in programming, there are
task that programmers know they will have to do over and over again. Maybe calculating the number of days until Christmas, checking if a number is prime, counting letters in a word, etc. It is often very useful to create functions or blocks of reusable code that a program can invoke to execute a this consistent task instead of writing out the code every single time. Instead of writing code and figuring out the logic everytime, functions can be created. For example, static int numOfLetters(String s) { return s.length();}, calculate how long the word (string) s is. Instead of having to rememver the syntax (s.length()), a p
@kylelong
kylelong / repeatedSubString.java
Created January 22, 2019 19:55
Week 1/20/19 of Cassido's newsletter
import java.util.regex.*;
/**
* Created by kylel95 on 1/22/19.
*/
public class repeatedSubString {
public static void main(String [] args){
System.out.println(repeat("pi", "pipipipi"));
System.out.println(repeat("danger", "cassidy"));