Skip to content

Instantly share code, notes, and snippets.

@KodeSeeker
KodeSeeker / SingleChildTrimmer.java
Created July 4, 2023 19:47
Daily Coding Problem #1444
/**
Good morning! Here's your coding interview problem for today.
This problem was asked by Yahoo.
Recall that a full binary tree is one in which each node is either a leaf node, or has two children. Given a binary tree, convert it to a full one by removing nodes with only one child.
For example, given the following tree:
@KodeSeeker
KodeSeeker / QuickSelect.java
Created January 6, 2019 19:29 — forked from unnikked/QuickSelect.java
A basic implementation of quickselect algorithm in Java. Intentionally unused generics.
import java.util.Arrays;
/**
* quickselect is a selection algorithm to find the kth smallest element in an
* unordered list. Like quicksort, it is efficient in practice and has good
* average-case performance, but has poor worst-case performance. Quickselect
* and variants is the selection algorithm most often used in efficient
* real-world implementations.
*
* Quickselect uses the same overall approach as quicksort, choosing one
@KodeSeeker
KodeSeeker / ThreeSumSmaller.java
Created September 30, 2018 22:25
ThreeSumSmaller.java
import java.util.Arrays;
/**
* Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n
* that satisfy the condition nums[i] + nums[j] + nums[k] < target.
* <p>
* For example, given nums = [-2, 0, 1, 3], and target = 2.
* Return 2. Because there are two triplets which sums are less than 2:
* <p>
* [-2, 0, 1]
@KodeSeeker
KodeSeeker / TwoSumFileStructure.java
Created September 29, 2018 22:31
Design and implement a TwoSum class. It should support the following operations: add and find.
/**
Design and implement a TwoSum class. It should support the following operations: add and find.
add - Add the number to an internal data structure. find - Find if there exists any pair of numbers which sum is equal to the value.
For example,
add(1); add(3); add(5);
find(4) -> true
find(7) -> false
**/
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
public List<Integer> spiralOrder(List<ArrayList<Integer>> a){
if( a == null || a.isEmpty()) {
return null;
}
// base case 3x3 then tweak
int startRow = 0;
int startCol = 0;
int endRow= a.size();
@KodeSeeker
KodeSeeker / The Technical Interview Cheat Sheet.md
Last active June 28, 2018 06:44 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@KodeSeeker
KodeSeeker / UIDToDate.java
Created April 20, 2015 23:11
Cassandra convert from UID to Date
public static void main (String... args){
UUID uid = UUIDs.timeBased();
long time = getTimeFromUUID(uid);
Date date = new Date(time);
System.out.println(date);
}
static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
public static long getTimeFromUUID(UUID uuid) {
@KodeSeeker
KodeSeeker / SimpleSingleton.java
Created September 7, 2014 02:43
SimpleSingleton
public class Singleton
{
private Singleton singleton;
//make the constructor protected- to defeat instantiation.
protected Singleton(){}
public static Singleton getInstance() {
if(singleton == null) {
@KodeSeeker
KodeSeeker / PostFixtoInfix.java
Last active August 29, 2015 14:05
Postfix to Infix Notation
/**
* Convert from Postfix to Infix Notation
* Infix to Postfix :https://gist.github.com/KodeSeeker/f776c5477c3be3f43a77
* Algo:
* 1) Walk through postfix expression
* 2) If input is a num then push to stack.
* 3) If the input is a operator then pop the last two operatonds from stack and perform operation. Push result back onto stack.
*
* Error condition : if you see a operator and there arent 2 operands in the left in the stack.
*