Skip to content

Instantly share code, notes, and snippets.

View yekmer's full-sized avatar

Yekmer Simsek yekmer

View GitHub Profile
@yekmer
yekmer / NestedArrays.java
Created February 4, 2014 20:58
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]
package com.yekmer.interview.intercom;
import java.util.LinkedList;
import java.util.Queue;
public class NestedArrays {
public static void main(String[] args) {
//sample for this output [[1,2,[3]],4] -> [1,2,3,4]
Object[] objArr = new Object[2];
@yekmer
yekmer / TopNumbers.java
Created February 4, 2014 20:30
Write a program, topN, that given an arbitrarily large file and a number, N, containing individual numbers on each line (e.g. 200Gb file), will output the largest N numbers, highest first. Tell me about the run time/space complexity of it, and whether you think there's room for improvement in your approach.
package com.yekmer.interview.intercom;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.PriorityQueue;
import java.util.Stack;
public class TopNumbers {
public static void main(String[] args) {
public class DeepestDepth {
static DeepestDepth ts = new DeepestDepth();
static Node maxNode;
static int maxDepth = 0;
public static void main(String[] args) {
Node l1221 = ts.new Node(null, null, 8);
Node l122 = ts.new Node(null, l1221, 4);
Node l121 = ts.new Node(null, null, 7);
@yekmer
yekmer / PrintLevel.java
Last active January 4, 2016 15:09
Solution for print all values at a specific depth in BT, you can see sample BT visualisation here http://www.geeksforgeeks.org/sum-numbers-formed-root-leaf-paths/
public class PrintLevel {
static PrintLevel ts = new PrintLevel();
public static void main(String[] args) {
Node l122 = ts.new Node(null, null, 4);
Node l121 = ts.new Node(null, null, 7);
Node r12 = ts.new Node(null, null, 4);
Node l12 = ts.new Node(l122, l121, 5);
Node l11 = ts.new Node(null, null, 2);
class SwapLinkedList {
static SwapLinkedList sll = new SwapLinkedList();
public static void main(String[] args) {
// 1->2->3->4->5->6
Node node6 = sll.new Node(null, 6);
Node node5 = sll.new Node(node6, 5);
Node node4 = sll.new Node(node5, 4);
Node node3 = sll.new Node(node4, 3);
Node node2 = sll.new Node(node3, 2);
Node root = sll.new Node(node2, 1);
@yekmer
yekmer / ChessPath.java
Last active January 4, 2016 12:59
Solution for a question, that there is a chesstable 4x4, you are starting from left lower corner to right upper corner. You should print all alternative paths to go, and solution should be recursive? (There are 2 different solutions below. 2nd solution below is a simple search algorithm, 1st solution is a simpler DFS solution)
public class ChessPath {
private static int length = 4;
public static void main(String[] args) {
String headStr = "";
getPath(1, 0, false, headStr);
getPath(0, 1, true, headStr);
}
public static void getPath(int xC, int yC, boolean upD, String path) {
if(xC == length || yC == length) return;
@yekmer
yekmer / Palindrome.java
Created January 25, 2014 21:41
Check if a string is palindrome?
public class Palindrome {
public static void main(String[] args) {
String st = "abcecba";
System.out.println(isPalindrome(st));
}
public static boolean isPalindrome(String st) {
for(int i = 0; i < st.length() - i - 1; i++) {
if(st.charAt(i) != st.charAt(st.length() - 1 - i)) {
package com.yekmer.geeksforgeeks;
class TreeSum {
static TreeSum ts;
static int sum = 0;
public static void main(String[] args) {
ts = new TreeSum();
Node l122 = ts.new Node(null, null, 4);
public static Node lca(Node node, int a, int b) {
while (node != null) {
if(a > node.value && b > node.value) {
node = node.right;
} else if (a < node.value && b < node.value) {
node = node.left;
} else {
return node;
}
}
@yekmer
yekmer / MaskedImageView.java
Created January 20, 2014 21:33
This is an imageview extension to create a masked imageview
import java.io.InputStream;
import java.net.URL;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;