Skip to content

Instantly share code, notes, and snippets.

View Bekt's full-sized avatar
👨‍🍳
making things happen

Kanat Bekt Bekt

👨‍🍳
making things happen
View GitHub Profile
@Bekt
Bekt / ruzzle.py
Created March 22, 2014 21:37
Solver for the popular game Ruzzle
#!/usr/bin/env python3
'''Ruzzle Solver
__author__ = 'github.com/Bekt'
__date__ = 3/22/2014
'''
import sys
from collections import defaultdict
@Bekt
Bekt / Main.java
Created December 18, 2013 07:24
Algorithm homework-3 solution.
import java.util.*;
import java.util.Map.Entry;
import java.util.AbstractMap.SimpleEntry;
import static java.lang.Integer.*;
import static java.lang.Math.min;
public class Main {
static class Vertex implements Comparable<Vertex> {
int id, distance = MAX_VALUE;
@Bekt
Bekt / Main.java
Created November 23, 2013 23:49
Algorithms homework assignment #2 solution.
import java.util.*;
import static java.lang.Math.min;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int distance = in.nextInt(), n = in.nextInt();
int[] costs = new int[distance + 1];
Arrays.fill(costs, Integer.MAX_VALUE / 2);
@Bekt
Bekt / Two.java
Created September 25, 2013 05:10
// Twitter Codibility Screening
public class Two {
public int solution(int[] A) {
int evens = getEvensCount(A);
long totalPairs = nChooseK(evens, 2) + nChooseK(A.length - evens, 2);
return totalPairs > 1000000000 ? -1 : (int) totalPairs;
}
import java.util.*;
import java.io.*;
public class C2 {
static Scanner in;
static BufferedWriter out;
long[] palin = new long[40];
public static void main(String[] args) throws Exception {
in = new Scanner(new File("c2.in"));
@Bekt
Bekt / C1.java
Created April 15, 2013 01:58
Code Jam 2013, Problem C (small input)
import java.util.*;
import java.io.*;
public class C1 {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("c1.in"));
int[] palin = {1, 4, 9, 121, 484};
int t = in.nextInt();
for(int i=1; i<=t; i++) {
@Bekt
Bekt / Reversed.java
Created April 10, 2013 17:08
This problem is a simpler one, so you can give it a shot right now. Write a function which, given a sentence like this: Coding for Interviews contains too many gifs. Returns the sentence with the order of the words reversed, like so: gifs. many too contains Interviews for Coding The catch is: your function should use O(1) space. What is your alg…
//NOTE: did not test AT ALL
//Time: O(N*k), k = length of the longest word in the sentence
//Space: O(1)
public class Reversed {
public static void main(String[] args) {
String sent = "Coding for Interviews contains too many gifs.";
reverse(sent);
}
@Bekt
Bekt / FindMin.java
Last active December 11, 2015 21:18
import java.util.*;
import java.io.*;
//2013 Facebook Hacker Cup Qualification Round
//Problem 3: Find the Min http://www.facebook.com/hackercup/problems.php?pid=494433657264959&round=185564241586420
public class FindMin {
static Scanner in;
public static void main(String[] args) throws Exception {
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
//2013 Facebook Hacker Cup Qualification Round
//Problem 2: Balanced Smileys https://www.facebook.com/hackercup/problems.php?pid=403525256396727&round=185564241586420
public class Balanced {
static Scanner in;
import java.util.*;
import java.io.*;
//2013 Facebook Hacker Cup Qualification Round
//Problem 1: Beautiful strings https://www.facebook.com/hackercup/problems.php?pid=475986555798659&round=185564241586420
public class Beautiful {
static Scanner in;
public static void main(String[] args) throws Exception {