Skip to content

Instantly share code, notes, and snippets.

View ekeitho's full-sized avatar

Keith Abdulla ekeitho

View GitHub Profile
@ekeitho
ekeitho / longestpalindrome.kt
Created July 9, 2018 22:26
Longest Palindrome
fun longestPalindrome(input: String) : String {
var start = 0;
var maxLength = 1
fun expandAroundCenter(str : String, left: Int, right: Int) {
var low = left;
var high = right
while(low >= 0 && high < str.length && str[low] == str[high]) {
if (high - low + 1 > maxLength) {
@ekeitho
ekeitho / addTwoNums.kt
Created December 13, 2017 04:05
Add To Numbers LeetCode in Kotlin
/**
* https://leetcode.com/problems/add-two-numbers/description/
*
* Definition for singly-linked list.
* class ListNode(var `val`: Int = 0) {
* var next: ListNode? = null
* }
*/
class Solution {
fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {
@ekeitho
ekeitho / perm2.kt
Created December 7, 2017 17:10
Question: if you have a collection of numbers which could contain duplicates, return all unique permutations of the collection
class testing1234 {
@Test
fun yo() {
val testArray = IntArray(3)
testArray.set(0, 1)
testArray.set(1, 2)
testArray.set(2, 1)
println(permute(testArray))
@ekeitho
ekeitho / nqueens.kt
Last active November 25, 2017 17:00
nqueens - 2^N problem (going through each perm) (no back track) (skip row on success)
package i_introduction._0_Hello_World
import org.junit.Test
import kotlin.collections.ArrayList
class nqueens() {
@Test
fun yo() {
@ekeitho
ekeitho / findsets.kt
Created November 20, 2017 21:25
Find Sum Subsets
package hackerrank
import org.junit.Test
import java.util.*
import kotlin.collections.ArrayList
class sumsets {
@Test fun yo() {
val lists = findSubsets(Arrays.asList(1,2,3,5), 5)
println(lists)
@ekeitho
ekeitho / knapsack.kt
Created October 11, 2017 19:49
Knapsack 0/1 DP in Kotlin
class __00_Knapsack {
val array = arrayOf(Pair(1,1), Pair(3,4), Pair(4,5), Pair(5,7))
@Test fun yo() {
val row1: IntArray = intArrayOf(0, 0, 0, 0, 0, 0, 0, 0);
val row2: IntArray = intArrayOf(0, 0, 0, 0, 0, 0, 0, 0);
val row3: IntArray = intArrayOf(0, 0, 0, 0, 0, 0, 0, 0);
val row4: IntArray = intArrayOf(0, 0, 0, 0, 0, 0, 0, 0);
@ekeitho
ekeitho / practice.jsx
Created April 25, 2017 01:20
just messing with RXJavascript and React
/*
<!DOCTYPE html>
<html>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<script src="//fb.me/react-0.13.1.js"></script>
<div id="root">
</div>
</body>
@ekeitho
ekeitho / MainActivity.java
Last active December 5, 2016 23:01
part_eight
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initial setup
View headerView = Utils.createDynamicView(this);
int viewResource = R.layout.footer_view;
// setting STATE tells us how to set up our logic
@ekeitho
ekeitho / MainActivity.java
Created December 5, 2016 19:54
part_seven
// we want the header to span the full width
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(STATE) {
case HEADER:
if (position == 0) {
return spanCount;
}
return 1;
@ekeitho
ekeitho / MainActivity.java
Last active December 5, 2016 20:02
part_six
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int padding = Utils.dpToPx(getResources(), 16);
if (position == 0 && (STATE == HEADER || STATE == BOTH)) {
outRect.left = padding;
outRect.right = padding;
outRect.top = padding;