This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * google_Dividing_A_Plane_Of_Points_Into_Two_Equal_Halves | |
| * | |
| * @author yifenliu | |
| */ | |
| import java.util.ArrayList; | |
| import java.util.Collections; | |
| import java.util.List; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.setrecursionlimit(10000) | |
| DIFF=0 | |
| def solve(): | |
| pass | |
| def reconstruct(node, visited, adj, tree): | |
| visited[node] = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ Queue.Queue | |
| """ | |
| from Queue import Queue | |
| import threading | |
| import time | |
| import urllib2 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |