Skip to content

Instantly share code, notes, and snippets.

View monkeylyf's full-sized avatar

Yifeng Liu monkeylyf

  • Google
  • Bay area
View GitHub Profile
"""hackerrank_Lexicographic_Steps
https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps
"""
def factorial(n, step):
res = 1
count = 0
for i in reversed(xrange(1, n + 1)):
res *= i
"""hackerrank_Girlfriend_and_Necklace.py
https://www.hackerrank.com/contests/w8/challenges/gneck
"""
def is_good_necklace(s, l):
"""
"""
for i in xrange(len(s) - l + 1):
subseq = s[i:i + l]
/**
* Write a Java method that takes a String of text and inserts newline characters
* ('\n') so that each line of text has at most maxCharsPerLine characters (not
* counting the newline).
*
* It may also be necessary to delete some spaces.
*
* The method should obey the following rules:
*
* 1. Words should never be broken up, unless a word has more than maxCharsPerLine
@monkeylyf
monkeylyf / consecutive_subseq
Created July 2, 2014 03:06
hackkerrank consecutive subseq
from collections import Counter
def solve(arr, n, k):
acc = [ None ] * n
for i, val in enumerate(arr):
acc[i] = val % k if i == 0 else (acc[i - 1] + val) % k
res = 0
count = Counter(acc)
object Solution {
def main(args: Array[String]) = {
val NM = io.StdIn.readLine.split(" ")
val N = NM(0).toInt
val M = NM(1).toLong
val appetite = io.StdIn.readLine.split(" ").map(x => x.toInt)
val factor = io.StdIn.readLine.split(" ").map(x => x.toInt)
println(solve(appetite, factor, M))
}
@monkeylyf
monkeylyf / google_Dividing_A_Plane_Of_Points_Into_Two_Equal_Halves.java
Created June 19, 2014 20:50
Given a list of point, find two point whose line cuts the plane into two halves and each half has the same number of the points.
/**
* google_Dividing_A_Plane_Of_Points_Into_Two_Equal_Halves
*
* @author yifenliu
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import sys
sys.setrecursionlimit(10000)
DIFF=0
def solve():
pass
def reconstruct(node, visited, adj, tree):
visited[node] = True
def small(A, B, K, t):
pair = 0
for a in xrange(A):
for b in xrange(B):
if a & b < K:
pair += 1
print 'Case #{0}: {1}'.format(t, pair)
""" Queue.Queue
"""
from Queue import Queue
import threading
import time
import urllib2
object Solution {
def main(args:Array[String]) = {
val T = readLine().toInt
val xs = readLine().split(" ").map(_.toInt).toList.sortWith(_ > _)
val s = xs.sum
val N = readLine().toInt
for (_ <- 0 until N) {
//val sum = readLine().toLong = sum match {