question_id
int64
39
56.8k
question_title
stringlengths
3
54
question_content
stringlengths
88
4.02k
dataset
stringclasses
1 value
difficulty
stringclasses
3 values
java
dict
java15
dict
java8
dict
python
dict
test_cases
stringlengths
28
4.02M
max_retries
float64
1
3
⌀
20,188
Counting On a Tree
Taylor loves [trees](https://en.wikipedia.org/wiki/Tree_(graph_theory)), and this new challenge has him stumped! Consider a tree, $t$, consisting of $n$ nodes. Each node is numbered from $1$ to $n$, and each node $i$ has an integer, $c_i$, attached to it. A *query* on tree $t$ takes the form `w x y z`. To process a ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<Integer> c, List<List<Integer>> tree, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Pri...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static int[] nxt;\n static int[] succ;\n static int[] ptr;\n static int index = 1;\n\n static void addEdge(int u, int v) {\n nxt[index] = ptr[u];\n ptr[u] = index;\n succ[index++] = v;\n }\n\n static int timer = 0;\n ...
{ "solution": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nclass InputReader {\n\t \n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream...
{ "class_name": null, "func_sign": [ "solve(c, tree, queries)" ], "solution": "import sys\nfrom filecmp import cmp\nfrom os import linesep\nfrom time import time\nfrom collections import Counter\n\nmemoized_BIT_prevs = [list() for _ in range(10**5+1)]\nfor i in range(1,10**5+1):\n next = i + (i & -i)\n ...
eJzE3U2uNM2WLGQaMI9UtW8jfjw8whkJEkeiAdWAxuE26kpXQkiMmRFgj/k+iBkglSr9fO/eOzPD3dePLVu2/q//9n/4v/+3/+6/+R//j3/7X//5n//Lf/zbf//7tzHGb4x//PP8Xb/7N37Pb/7e3/dbv/P4nefvvH7n/TvH73x+5/yd7+/8fuf6Xcfvyu9cv+v+XeN3Pb9r/q73d32/a/3u43efvzt/8v7d43c/v3v+7vd3f797/cbxG+dvXL+Rd8zbP78xf+P9je831u85fs/5e67fc/+efKDn98zf8/6e7/es3zx+8/zN6zfv3xy/...
null
21,545
Company Retreat
The *LRT Company* has $n$ employees. Each employee has a unique ID number from $1$ to $n$, where the director's ID is number $1$. Every employee in the company has *exactly one* immediate supervisor &mdash; except the director, who has no supervisor. The company's employee hierarchy forms a tree of employee IDs that's ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> supervisors, List<List<Integer>> groups)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static final int logN = 17;\n static final int INF = 1000000000;\n s...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\nstatic final int logN = 17;\nstatic final int INF = 1000000000;\nstatic final int MOD = 1_000_000_007;\n\nstatic int[] nxtV;\nstatic int[] succV;\nstatic int[] ptrV;\nstatic int indexV = 1;\n\nstatic void addV(int u, int v) {\nnxtV[in...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n // Complete the solve function below.\n static int solve(int[] supervisors, int[][] groups) {\n //TODO kalau sempet\n return 0;\n }\n\n pr...
{ "class_name": null, "func_sign": [ "solve(supervisors, groups)" ], "solution": "#!/bin/python3\n\nimport os\nimport sys\n\n# Complete the solve function below.\ndef solve(supervisors, groups):\n n = len(supervisors)+1 \n mHeight = 1\n emps = [0]*n\n for i in range(n-1):\n emps[superviso...
eJxk3UGuLE2SHlYOxH0kaihwkO7mbmbJlRBgAxpIPdCkyUETECAI0F64UfqxS0IE1Ki8+Ksrouq9+PJmhp8wN/t//5f/8F//13/7b/7j//2P//Nf/vN/+dd//PvPP/ZnxT/9y3r/+v6P//vsf/qXvnd3+Kf9rezPO+Cus99/6NBfx98//H/n+He3z2/Oyf6uOefse2rNP6131vr/n9T7u/f8//fKPP3Z//h3n3/88//1n//5f//Xf/4//rf/9F/+9b//QW/9VmT907/84//5d5//6S+w7n//I6/P/sTnfO4nP/Xpz++z3v/C+6/2V/ys...
null
28,389
Electronics Shop
A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy *both* items, return $-1$. **Example** $b = 60$ $keyboards=[40, 50, 60]$ $...
hackerrank
Easy
{ "class_name": null, "func_sign": [ "static int getMoneySpent(int[] keyboards, int[] drives, int b)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void ...
null
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int s = in.nextInt();\n int n = in.nextInt();\n int...
{ "class_name": null, "func_sign": [ "getMoneySpent(keyboards, drives, b)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\ns,n,m = input().strip().split(' ')\ns,n,m = [int(s),int(n),int(m)]\na = [int(keyboards_temp) for keyboards_temp in input().strip().split(' ')]\nb = [int(pendrives_temp) for pendrives_...
eJztvUvuZE+2pUWDgRzddoHs/WAkSASiAdWgE1TjloSEkBgEzIIew2EyrO+zX6pUZP6hQKACKW7eTI/wcD9+jtm2/Vx77f/hP/yf/pf/9T/w//7T/zl/+M/+u3/6r3//q3/9z//0n3z/VIv/99Vv/vo9xxy3/PrdW+m1fGPtufp3by9zf6PuXutX6zhr/dO/+P7pX/63/+pf/pf//C//q//iv/nX//xztbvaKfXX73/67//F92//yDf5/1+/69e+/o1vfuvb3/nulx/isu2r/avjq/Or66v7q+er92vla/lO+1r/2vja/Nr62v7a+dr9...
null
17,892
Lisa's Workbook
Lisa just got a new math workbook. A workbook contains exercise problems, grouped into chapters. Lisa believes a problem to be *special* if its index (within a chapter) is the same as the page number where it's located. The format of Lisa's book is as follows: * There are $n$ chapters in Lisa's workbook, numbered f...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int workbook(int n, int k, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint ans = 0;\n\t\tfor (int i = 0, page = 1; i < n; i++) {\n\t\t\tint ...
{ "class_name": null, "func_sign": [ "workbook(n, k, arr)" ], "solution": "a=0\npg=[[]]\nx,y=map(int,input().split(' '))\nl=list(map(int,input().split(' ')))\nfor i in l:\n k = [[] for _ in range(100)]\n for j in range(i):\n k[j//y].append(j+1)\n for i in k:\n if i != []: \n ...
eJzdl82KJUUQhV249xWCux6k8j/TJxG84kJ7Ich1Fj0giOBD6Pt6vpN3QMopaLczU11UZ2VFRpw4cSL6zy///uWrL/zv2xc9fPf77efH+w+vt2/iNnKkdH/MEj1H1n1GijqjrhglyhGLx6Zdehepx1qR/VoLrcSIoR0xUnS9i3QckZs3NS2vhImZo6Vo2tejD3aPSC2GtvbIA6slx5jRWE4Ta3Ihaa3z2ZpR9KCjKi6uGjXjaJvRFxvk3uTsWCNWl+P3x+1d3F5+e//y4+vLTz/8+uH1Ge66/fEu/hV+6zHr/aFzKsfUQjhypjYcl4c6...
null
22,193
The Bomberman Game
<!-- Reference to Bomberman the game, whose bombs behave approximately as described. --> [Bomberman](https://en.wikipedia.org/wiki/Bomberman) lives in a rectangular grid. Each cell in the grid either contains a bomb or nothing at all. Each bomb can be planted in any cell of the grid but once planted, it will detonate...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<String> bomberMan(int n, List<String> grid)" ], "script_name": "Solution", "solution": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*; \nimport java.util.*;\nimp...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "bomberMan(n, grid)" ], "solution": "def printGrid(grid) :\n for row in grid :\n print(\"\".join(row))\n\nr, c, n = [int(i) for i in input().strip().split()]\nD = [['O' for i in range(c)] for j in range(r)]\n\nG = []\nfor _ in range(r) :\n G.append(list(inpu...
eJztfcuuJEcOnQH7Qy56LRDTklot+SdiZcCAZcxiRovZaGahAQYYDOCP8P/419xdGSTPYTDydSv6IZEt3crKjGAckoeMyEdV/Z//9j//x//7r//lf/37zd9+/cc/f3vz31/evP3x7cvbH356+fHbn39t0p4hQpvS/P9X65Xt9QPUKygmO3aPHMA9bc0DqlzqI5PG0YsyhyK293hQa3FEAHkSPy6ombUEr55TsuOrCyAOSSFxR0u4egeEJG+eFA2XM2mVjJtw8qTIbSM+QrU8ybl+U/MNVu13P+nVqOEG/NcRSxzqjYLITc05t0KSN2O/...
null
22,578
CamelCase
There is a sequence of words in [CamelCase](https://en.wikipedia.org/wiki/CamelCase) as a string of letters, $s$, having the following properties: * It is a concatenation of one or more *words* consisting of English letters. * All letters in the first word are *lowercase*. * For each of the subsequent words, the firs...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int camelcase(String s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\n\npublic class Solution {\n private BufferedReader in;\n private StringTokenizer line;\n private PrintWriter out;\n private boolean isDebug;\n\n public Solution(boolean isDebug) {\n this.isDebug = isDebug;\n }\n\n private static fina...
{ "class_name": null, "func_sign": [ "camelcase(s)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\ns = input().strip()\nans = 1\nfor i in s :\n if i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :\n ans += 1\nprint(ans)", "template": "#\n# Complete the 'camelcase' function below.\n#\n# The function is expe...
eJx0/MeqZd3arQcmKC/k8JdVUZIVqRbe+4gVRoKke+99Fwl56dnmRgXB4Ww2RHysGWN2876tPW2MPtb/7//5R/b/6f/xv/+f/2ViHv2//rf/9l96MuobJ7MvXfTc1qjgT7SMx3wKIbcME8auo8ZQ9GkqyurjND9lsI2vnVeboe/yUmteh7BzhHVJUOLMyb2xSfNBlHKul05xyeqzuJxXvnoopk4ly4qMhK51GqW5REtf9aS+oyI5PJ/sOGKEsMZ2N3SdW80VF1mk9R8qC9/3bHWdNGI2RFsRO1ehdxP0YWxueVzibpEnYYTcPGer2Fnh...
null
106
Candies
Alice is a kindergarten teacher. She wants to give some candies to the children in her class.  All the children sit in a line and each of them has a rating score according to his or her performance in the class.  Alice wants to give at least 1 candy to each child. If two children sit next to each other, then the one wi...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long candies(int n, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n\tprivate static int countMinCandies(int[] ratings) {\n\t\tint[] candies = new int[ra...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.stream.IntStream;\n\npublic class Solution {\n\t\n//\tInput \n//\tThe first line of the input is an integer N, the number of children in Alice's class. \n//\tEach of the following N lines conta...
{ "class_name": null, "func_sign": [ "candies(n, arr)" ], "solution": "N = int(input())\na = []\nwhile N>0:\n\ta.append(int(input()))\n\tN -= 1\nN = len(a)\nleft, right, num = [[0 for i in range(N)] for j in range(3)]\np = 1\nwhile p<N:\n\tif a[p] > a[p-1]:\n\t\tleft[p] = left[p-1] + 1\n\tp += 1\np = N-2\nw...
eJwtmDGOprcRRB3oBr4AMbFhkOwmm/RJDFiGAmkDJ2sFK0CAYcCHsO/r9zirYPXPN99Psqurq4rznx/+d//4h/ffXycf/vavj398/fW3bx9/aR9nnh+/zlprtTi3ess1Y7a7xu38W7N4PtZsY9672xmxg3fGPe28d8aqGq36yGh33Bst9siWvY/b9ui91ZqLp7dmttHHnC3ZKtqZMUabJ/fl+d6z1R58XjEy26nOgvPcxQLVL5+LdU/w3tqdE83bV8udl4+11+HxCraIxddn8Ju2bq/V5rgz2rjJWjvzsDULzxbl+3OPGO2c6LxfPEjK...
null
41
Pairs
Given an array of integers and a target value, determine the number of pairs of array elements that have a difference equal to the target value. **Example** $k = 1$ $arr = [1, 2, 3, 4]$ There are three values that differ by $k = 1$: $2-1 = 1$, $3-2 = 1$, and $4-3 = 1$. Return $3$. **Function Description...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int pairs(int k, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static int pairs(int[] a,int k...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.util.*;\nclass Solution\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tint k=in.nextInt();\n\t\tint a[]=new int[n];\n\t\tint count=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=in.nextInt();\n\t\tArrays.sort(a);\n\t\tfor(in...
{ "class_name": null, "func_sign": [ "pairs(k, arr)" ], "solution": "#!/usr/bin/py\n# Head ends here\ndef pairs(a,k):\n # a is the list of numbers and k is the difference value\n a.sort()\n left = 0\n right = 1\n answer = 0\n while right < len(a):\n val = a[right]-a[left]\n i...
eJyUnbmObsuWlTFweIvDtTFizuh5EiRKwoAycC4YhQRCSDw6Ef9e4xtRQhhIV/ekcmfmv5qIGbMZzf/+l//uf/zrf/Uv/v3//Nt//vt//W//9Ld/+9ffevlrjzbWP/w9eu+tzDrWX/fLXuqq+y99d3Z/OfiBFv5u9XcX313NP+C/256f9Q+s5MvhTxu+htH4tXy+O/0Xqj/NP1v9x1bxd30X1dc7nnvb/gFfb33+gj94Pl8mP9CfL4s/wt9t/u7q/lk/1OUvR/gHnst5bvP52ef5Pu/NnzZ9b82XU58re57Dc2/xD3//27/562//+N//...
null
3,242
Savita And Friends
After completing her final semester, Savita is back home. She is excited to meet all her friends. Her $N$ friends live in different houses spread across the city. There are $M$ roads connecting the houses. The road network formed is connected and does not contain self loops and multiple roads between same pair of ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Double> solve(int n, int k, List<List<Integer>> roads)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static final long INF = 1000000000000000000L;\n\n static class Edge {\...
{ "solution": "import java.io.*;\nimport java.text.DecimalFormat;\nimport java.text.NumberFormat;\nimport java.util.*;\n\npublic class Solution {\n\n static class Node {\n int src;\n int weight;\n\n public Node(int src, int weight) {\n this.src = src;\n this.weight = weight;\n }\n }\n\n stati...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.function.*;\n\n/**\n * Created by sunil on 5/21/16.\n */\npublic class Solution {\n\n public static class Edge implements Comparable<Edge> {\n\n final int from;\n final int to;\n final double wt;\n\n public Edge(int...
{ "class_name": null, "func_sign": [ "solve(n, k, roads)" ], "solution": "import heapq\ndef calc_dist(G, start):\n dist = [-1] * len(G)\n active = [(0, start)]\n while active:\n d, i = heapq.heappop(active)\n if dist[i] >= 0: continue\n dist[i] = d\n for j, e in G[i]:\n if ...
eJyEvcvKbd2ylmkhq97DYJUlaeeDV2FRcEIWMnchKyst7A2CCN6fN2U8T7T+L0wRl4pzzv/7xui9HeLwxhtv/Nf/49//t3/3r//Vf/jPf/t///4f/+Wf//Zvf3+rf/6+yq/W/Ys/1V/7jd1uK3/+3n79t06bdf35e/+N36mtrfj38Zu/VXtf48/f40+/2mbpNz7lt3+3tDbiz/t3fnfv1fqfv8effveOe+J376+W3yqj7h1fxtf+2jjjnPhbjU+K/zvu5UHij/3X5q01PiL+WMevtxPPFn8bvzp/9ZTB4/DH9Zunbn8vnmf/Wp+3xGPw...
null
19,024
Tree Flow
Recall that a tree is an undirected, connected acyclic graph. We have a weighted tree, $T$, with $n$ vertices; let $dist_{u, v}$ be the total sum of edge weights on the path between nodes $u$ and $v$. Let's consider all the matrices, $A_{u, v}$, such that: - $A_{u, v} = -A_{v, u}$ - $0 \le |A_{u, v}| \le dist_{u, v}$...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int treeFlow(int n, List<List<Integer>> tree)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static class Edge {\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n \n static class Edge {\n public int to;\n public long weight;\n public Edge(int to, int weight) {\n this.to = to;\n this.weight = weight;\n }\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n \n static class Edge {\n public int to;\n public long weight;\n public Edge(int to, int weight) {\n this.to = to;\n this.weight = weight;\n }\...
{ "class_name": null, "func_sign": [ "treeFlow(n, tree)" ], "solution": "import os\nimport sys\nimport heapq\n\n\ndef dfs(graph, start,dlength,EdgeDis):\n visited, stack = set(), [start]\n distances = [-1] * dlength\n distances[int(start) -1]=0\n \n while stack:\n vertex = stack.pop()\...
eJxsvcuuLTuSZaeGegL0DRvRroaTdHeS9SUCFIAaUjaqk8pGJlBAQYB+SP8oG8PWvnmX8QQiAse5ffmDTtpz2rT/93/+3/6///V/+Z/+9//xj//2r//2H//+j//684/e5/7nv7af/rPWft/rn//af8bPu1ab/Z//On7unzbedrV//uv988S/1xyTc96f3d8x/ff8We0e18111k9/45JxzfWzf+4eV+2Mt+vnHfsZnT+0uN+425N/6T/PFadN/zJ+1jX28n7t/tn3s7xWe36e3d4VD/j+tPdnjffi9/2nzZ/Z7rvH7fdPWz/zafcTF5s/...
null
3,585
Jim and his LAN Party
During the Steam Summer Sale, Jim's $N-1$ friends have purchased $M$ games, which are numbered from $1$ to $M$. The games are multiplayer. Jim has invited his friends to his basement where they will play by making a LAN-Party. Each friend has already decided the game he would like to play for the rest of the day. So ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> lanParty(List<Integer> games, List<List<Integer>> wires, int m)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimp...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n static int find(int[] uf, int x) {\n while (uf[x] != x) {\n uf[x] = uf[uf[x]];\n x = uf[x];\n }\n return x;\n }\n \n static void iota(int v[], int val) {\n for (int i = 0; i < v.length; i++) {\n v[i] ...
{ "solution": "import java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport ja...
{ "class_name": null, "func_sign": [ "lanParty(games, wires, m)" ], "solution": "import sys\n\nclass Vertex(object):\n def __init__(self, i, c, cc):\n self.i = i\n self.c = c\n self.cc = cc\n self.e = []\n\ndef merge_cc(cc, v, i, j, res, n, color_counts):\n to_rem = j if le...
eJxMvcuOLduSVUuBDwmdMgUfLx/ufAYlJJZEAbJAZZOFTAkJIfGH/BKjtW4eO8XNu9dZK2JO9/GwR7du3f7vv//P/+n//ft/91/+9z/+x1///K//8o//+POP96f/tPvPX+38N/+v+f/6n786/7/9M//89fzsP3+tn+fPX/Nn8LODf3j//DV+/2Hww4MfXvxD5x9ufq7zP/21f/yHn3/80//653/6b//yT//9v/7Pf/2XeoJ2fqdd55//z3/4+TcPNteYP2vNn/ne57PGeH5Gb+dv+s+c5/n6yH+v92c8109rz/nzPO9y/vf9M9dP69uf...
null
2,496
Sherlock and Cost
In this challenge, you will be given an array $B$ and must determine an array $A$. There is a special rule: For all $i$, $A[i] \le B[i]$. That is, $A[i]$ can be any number you choose such that $1 \le A[i] \le B[i]$. Your task is to select a series of $A[i]$ given $B[i]$ such that the sum of the absolute difference ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int cost(List<Integer> B)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStreamWriter;\...
{ "solution": "/*\n JAI MATA DI\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.sql.Array;\npublic class CP {\n static class FR{\n BufferedReader br;\n StringTokenizer st;\n public FR() {\n br = new BufferedReader(new In...
{ "solution": "import java.util.Scanner;\n\npublic class SherlockAndCost {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\t\tint T = in.nextInt();\n\n\t\twhile (T-- > 0) {\n\t\t\tint N = in.nextInt();\t\t\t\n\t\t\tint[] B = new int[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\...
{ "class_name": null, "func_sign": [ "cost(B)" ], "solution": "def cost(B) :\n c0,c1 = 0,0\n for i in range(1,len(B)) :\n c0,c1 = max(c0,c1+B[i-1]-1), max(c0+B[i]-1,c1+abs(B[i]-B[i-1]))\n return max(c0,c1)\n \n\n\n\n\nT = int(input())\n\nfor _ in range(T) :\n N = int(input())\n B = ...
eJztnM3OKzlTx1lwIdGsX6H42+ZKkBhgAbNgc3gX80pIgITELcD94vr9y+5O0sl5DrBgcWae5CTdbru+q1yuyr//+X/9x9/+Gf/91b/OD3/9L7/847c//un3X/7y9kv49Vu5//ot3O83e41uf8enMeyP7+Ptnb4++bf9cay/p1mfx/Wnb+vj84uVfv32yx9uv/z2z3/87e9//+0f/u6f/vS7o5L7vc+b//aH2yN+sR749fAwYcn7Y2r7Yz0gSOkBpvYOtLdAxRTiFVBh4pHzIzCCLTqk4+FmDM9j68d1Q+3pat08H5mo1mJTlMmadMvp...
null
36,029
K Factorization
At the time when Pythagoreanism was prevalent, people were also focused on different ways to factorize a number. In one class, Pythagoras asked his disciples to solve one such problem, _Reverse Factorization_. They were given a set of integer, $A = \{a_1, a_2, \cdots, a_K\}$, and an integer $N$. They need to find the ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> kFactorization(int n, List<Integer> A)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public stat...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n \n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int[] a = new int[k];\n for(int i = 0; i < k; i++) {\...
{ "class_name": null, "func_sign": [ "kFactorization(n, A)" ], "solution": "def getResult(n, a):\n \n if n is 1:\n return []\n \n for x in a:\n if n % x is 0:\n break\n else:\n return False\n \n for x in a:\n if n % x is 0:\n result = ge...
eJyVVLtOw0AQpEB8x8p1QLf3Pr6DAilGFJCCxqRIJCSExEfA/7Kzd5GClRjORRTZ3pnZmTl/Xn6vry70ur+TP+v34WXa7nfDLQ3WsaEwTpYcBUrEPE7DiobN23bztNs8P77ud+1VJkuRnCErIzo3fKzoCCu4ELgQ+3HygIrEmGBPHCiTNcTyK0Tslniu8eg3csrRB0F04ySogTgJiuApMkMYHgoH5x5YF3V3rxJVHZcuWS7YZEhmMNpkMWQFldOlxav4alpWLQZbeSoALdjViZuytQVR+CsqAZxRYMWEqAvgA4jkVkZQamQC7oFEiN0C...
2
1,637
Filling Jars
Animesh has $n$ empty candy jars, numbered from $1$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is described by $3$ integers, $a$, $b$, and $k$. Here, $a$ and $b$ are indices of the jars, and $k$ is the number of candies to be added inside each jar whose index lies between $a$ and $b$ (bo...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, List<List<Integer>> operations)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.Out...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.util.*;\nclass Solution\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tlong n,m,a,b,total=0,k;\n\t\tn=in.nextLong();\n\t\tm=in.nextLong();\n\t\twhile(m-->0)\n\t\t{\n\t\t\ta=in.nextLong();\n\t\t\tb=in.nextLong();\n\t\t\tk=in.nextLong();\n\t\t\t...
{ "class_name": null, "func_sign": [ "solve(n, operations)" ], "solution": "inp = [int(a) for a in input().split()]\ntot = 0\nfor i in range(inp[1]):\n inp1 = [int(a) for a in input().split()]\n tot += (inp1[1]-inp1[0]+1)*inp1[2]\nprint(int(tot/inp[0]))", "template": "#\n# Complete the 'solve' funct...
eJzEvcuqdV2yXWewH2SRRXMKc4770JMYnKCClAVVUqeQBwRC4Lf067i3FvNLGYTANR84mfnvf++15hyXuPTo0eP/+t/+j//9//5f/5f/87/+5T/9/V//7R9/+Xe/v7zP8/zmX//+/vxfz//3//WXf/n95W//5V//9h/+8bf/+O//87/94/tA/s1/+5ff/+srzjzP7PP3jvHXv7fnrt7Xb80+nvz3fkdvPZ+75xnnt87s7zN//Xnbc/Lj1lf+77fvs+/Jv59rvy0/P7PN3n6n7Xuf+7tj9Zbf73utdn776eOO5/eeZz283Xqfddpv56vf...
null
12,509
Digit Products
Let $D(X)$ be a function that calculates the digit product of $X$ in base $10$ without leading zeros. For instance: $D(0) = 0$ $D(234) = 2 \times 3 \times 4 = 24$ $D(104) = 1 \times 0 \times 4 = 0$ You are given three positive integers $A, B$ and $K$. Determine how many integers exist in the range $[A, B]$ whos...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(String a, String b, long k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\tstatic int digipro(int num){\n...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n int mod =...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint mod = 100000000...
{ "class_name": null, "func_sign": [ "solve(a, b, k)" ], "solution": "#!/bin/python3\n\nimport os\n\nMOD = 1000000007\n\ndef factor(k):\n d2 = 0\n while k % 2 == 0:\n d2 += 1\n k //= 2\n d3 = 0\n while k % 3 == 0:\n d3 += 1\n k //= 3\n d5 = 0\n while k % 5 == 0:...
eJy9ls2KJUUQhV248S2Sux4k/jNitr6E4IiI9sJNOzA9IIjgQ+h7uPP1/LJxI9NMNwVjFmTVrfw7cc6JqPv753/+/cVnj+3rv3j45tfbT/dv3z/cXq+bvrnfVuq9QiddZ0SlR9ymOnLvlup2rukJl6i9fY+bMpKblyulrKbCtlqmSfeb+9urdbv75e3dDw93P3738/uHf0/76vt3d0tfL7n99mr9F0XbZGwPU3HdUt4mU2WjNVIVDMw5d6lsY4qlMsQ8dY8tk0Ao1uXO86ZFXWRN5oxunq2BHHIFWlak7OUBH1mbvYdACV73rp0i7VGt...
null
2,584
Little Gaurav and Sequence
Little Gaurav is very fond of numbers and sequences. One day his teacher tells him to find a strange sequence. $$S = \sum_{i=0, 2^{i}\leq n}^\infty \sum_{j=0}^n 2^{2^{i}+2j}$$ Since this sequence looks a bit difficult, the teacher tells him to find the last digit of $S$. Little Gaurav is confused because h...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchExceptio...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\t\n\tstatic void solve() throws Exception {\n\t\tint t = nextInt();\n\t\tfor (int tt = 0; tt < t; ++tt) {\n\t\t\tlong n =...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "for _ in range(int(input())):\n n, sum, cur = int(input()), 0, 1\n while (cur <= n):\n sum+=pow(2, cur, 10)\n cur*=2\n sum = sum * (1 + (4 if n%2==1 else 0)) % 10\n print(sum)", "template": "#\n# Complete the 'solve'...
eJztvcuOZEuSZccBP6SQ40ZDj76VX0Kgg+CAXYOeJGtQDTRAEOBHkF/LSctactxhbmbuNzI5IyIrcMvDw+w8VEXluWXL//U//j//9v/+D/7vf/4v8cN/+j/+9l/+/m//9d//9j/9y9/2GL/+fvV1+pzzmr/+Xsu8zrmuNfi5X9dZrcfvr1l6q73W8uvvrfd5Zmktfr3a7G2vGj+eM3dba/OJs1sZ1+rx69F7fLPx4ypxxTIa19vxf2PsHb/vu7R9XfPi03W0+MyOa89WT9yJu9e5Sly581DXtUerpXL3uVY8dpn8vOc1di8Xtx+ljNHa...
null
32,958
The Hurdle Race
A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by $1$ unit for each dose. How many doses of the potion must the cha...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int hurdleRace(int k, List<Integer> height)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void m...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "hurdleRace(k, height)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn,k = input().strip().split(' ')\nn,k = [int(n),int(k)]\nheight = list(map(int, input().strip().split(' ')))\n# your code goes here\nprint(max(0, max(height) - k))", "template": "#\n# Complete th...
eJyVlj2OZEUQhDFwuUOq7RWq/x9ugIeJRCMMGAOnWWNWQkIrcQi4L1/E6wH0lh4N2zszT9X1KjMjIiPr98///OaLz/zv2695+O63y8+39x+eL1/FpbfY7XorUXe0FaVH7TFr9BElayUPPdcWs8TKUWrMHZOHFm3E7rweucRYeu5822P0KCXyjjJj18hJxzb2l2jRtx9jjFg7NqfzPp/VFXBvHUCQOiPXWOwnu8u7uDz9+v7px+enn3745cPzS+6Xj+/iX7XkFmtdb7MpObJpO2pSZpM8KKbG0AIVDbash+fO07kqcnIuAAwdXanSqAyS...
null
626
Snakes and Ladders: The Quickest Way Up
Markov takes out his [Snakes and Ladders](http://en.wikipedia.org/wiki/Snakes_and_Ladders) game, stares at the board and wonders: "If I can always roll the die to whatever number I want, what would be the least number of rolls to reach the destination?" **Rules** The game is played with a cubic die of $6$ faces ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int quickestWayUp(List<List<Integer>> ladders, List<List<Integer>> snakes)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.ArrayList;\nimport java.util.Lin...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static int getMinimum(int[] list) {\n int minimum = Integer.MAX_VALUE;\n for (int i = 0; i < list.length; i++) {\n if (list[i] > -1 && list[i] < minimum) {\n minimum = list[i];\n ...
{ "class_name": null, "func_sign": [ "quickestWayUp(ladders, snakes)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\n#\n# Complete the 'quickestWayUp' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts following par...
eJx9mk2OJUkRhFlwkFRvGaGM/whOgkQjFjALNg2LGQkJIXEIOCs7hJt9nq+a6aoZabqrul5lRLibm5tb5D9/+e///uoX/u+3/4kvfvf3T3/+8tcff/j0m+tT+fylxP/1avvzl3WV/vnLvpr+dVx1xg/K1Wv8ta8dP2rz6vHXKNdc8fFynfjk2teJX97rOvpZ/Oq84jf7vGp808+lBWa9yom/+jXvz18+fXd9+v5vf/3+jz98/6c//OXHH3Iz8fFP//ju+mp7LZ4bK7Rrx1dtXCse3GKhWH3M6+iJw5uYt7e04x9ju+e+TnxSH76vEv8w...
null
21,067
Luck Balance
Lena is preparing for an important coding competition that is preceded by a number of sequential preliminary contests. Initially, her luck balance is 0. She believes in "saving luck", and wants to check her theory. Each contest is described by two integers, $L[i]$ and $T[i]$: - $L[i]$ is the amount of luck associated ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int luckBalance(int k, List<List<Integer>> contests)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\npublic class Solution {\n\n public static void main(String[] args)...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "luckBalance(k, contests)" ], "solution": "N, K = map(int, input().strip().split())\n\nluck = 0\nimportant = []\n\nfor i in range(N):\n L, T = list(map(int, input().strip().split()))\n if T == 0:\n luck += L\n else:\n important.append(L)\n \...
eJzdmU+OZkkNxFlwkKLWA8pMp+1MToLEIBbQCzbNLGakkdBIHAKuxI474S9/kdVN1VRt2NGb19+r9yfTDkeE/f7+y3/++1e/OP9+96/6z+//9vyXz9/98P3zb5+ePZ66f/u517+n/u1ny+5P7dvPe/p4HPvg90q3x3G2fY7bzB/Xr23jcfSIOL/bPtdHtDz39R3nOOY6zx+xznPWOvdn+rnf+miP47Z9/j6y7ccxLc/zPJ2/j37+HtnmOc4877HwZB3jnPfB6xqX29JjH5fX+d7CWObkcdPOsdf7z/W2znbS85zfu59lRvbz3JjBsvd5...
null
500
Ice Cream Parlor
Two friends like to pool their money and go to the ice cream parlor. They always choose two distinct flavors and they spend all of their money. Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they have. **Example**. $m = 6$ $cost = [1, 3, 4, 5, 6]$ The two flav...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> icecreamParlor(int m, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public st...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint cases = Integer.parseInt(in.nextLine());\n\t\tfor(int c=0; c<cases; c++) {\n\t\t\tint K = Integer.parseInt(in.nextLine());\n\t\t\tin.nextLin...
{ "class_name": null, "func_sign": [ "icecreamParlor(m, arr)" ], "solution": "def main():\n # Loop through for each test.\n for _ in range(int(input())):\n dollars = int(input())\n numFlavors = int(input())\n flavors = [int(i) for i in input().split()]\n\n # Determine the c...
eJztncuOHMd2RT2wv8HTgxoTRrwf+hIDLkMDqQeapDhoAgIEAf4If7D3zuK9vhLZgvryVU0uohTqrlorIjIy4kRmdlbk//zrf/57/Nu//Nevl5+O128eL9/FpV+PvUe9Hv6vlLWirRQzzRo1tRZlrxGj5hItFf20S/OvKXIpOf4u9NnWs4Q/lNBK7s8Snl3CJxKuR20zq+n29WhVcJk7Rak1ydgjdikxW82x8qjR167SVlUmyukm9LKfJ/xZCbuVk78eufRxPdbSf3X0+FLJKPWLlf28ita7quj16K017UZ1rDmn+t5Wf+y9RC19h/um...
null
96
Liars
You have **N** soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have **M** sets of information about them. Each set of information tells you the number of liars among a certain range of your soldiers. Let **L** be the total number of your liar soldiers. Since you can't fin...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> liars(int n, List<List<Integer>> sets)" ], "script_name": "Solution", "solution": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\t/*\n\t * difference constraints\n\t * add new const...
{ "solution": "import java.io.BufferedWriter;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.AbstractMap;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.ut...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n private static final int MAX = 105;\n\tprivate static final int INF = Integer.MAX_VALUE;\n\tstatic int n;\n\tstatic int m;\n\tstatic int[] dis = new int[MAX];\n\tstatic boolean[] vis = new boolean[MAX];\n\tstatic HashMap<Integer,H...
{ "class_name": null, "func_sign": [ "liars(n, sets)" ], "solution": "from sys import stdin\nfrom math import inf\nfrom queue import Queue\n\ndef find_liars(num_soldiers, source_soldier, dest_soldier, edges):\n liars = [inf] * (num_soldiers + 1)\n liars[source_soldier] = 0\n\n for fodder in range(0, num_...
eJyVWUuOJUkRZMEpWIVqPUIR4fHlJEgUYgG9YFPMokcaCSHNIYY7suMKuJl55Muq6tcSo5FedGakh4d/zM29fvntv//7u9/wvz/+xxd/+ufL399+/Onryx/SSy2prte3klqqr2+Weiqvbz0t/Ez97LRT9i0l4X9fWCo9mS86FngyU834vuwEgRDkz+brGx7zQanYMnyR8arjkA6xlozSU2n4wF/7vqnjuK/hWLs9uGRaGjy9JlfJ/+2/I/ll8Faa7lSku2/kXV5+SC9ffv7xy1+/fvnbX/7x09ewAu/mb//1Q7rbpqfaoZov8LpyQZ1j...
null
80
Billboards
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $k$ consecutive billboards may be up at any given time. For example, if there are $n = 3$ billboards on Main street and $k = 1$, ADZEN must re...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int billboards(int k, List<Integer> revenue)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class Solution {\n\tpublic static void main(String args[]) throws Exception {\n\t\tScanner sc...
{ "solution": "import java.util.Scanner;\n\n\npublic class Solution {\n\n public static void main (String args[]) {\n Scanner sc = new Scanner(System.in);\n String line=sc.nextLine();\n String[] nk=line.split(\" \");\n int n=Integer.parseInt(nk[0]);\n int k=Integer.parseInt(nk[1]...
{ "solution": "\nimport java.util.ArrayDeque;\nimport java.util.Deque;\nimport java.util.Scanner;\n\npublic class Billboards {\n\n static int n;\n static int k;\n static long a[];\n static long f[];\n\n static long g(int i) {\n return f[i - 1] + a[i];\n }\n\n public static void main(String...
{ "class_name": null, "func_sign": [ "billboards(k, revenue)" ], "solution": "if __name__ == '__main__':\n \n NK = input().split(' ')\n N = int(NK[0])\n K = int(NK[1])\n\n profits = []\n\n for billboard in range(N):\n profits.append(int(input()))\n \n total = sum(profits)\n ...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
4,002
Covering the stains
There is a huge blanket on your bed but unfortunately it has **N** stains. You cover them using a single, rectangular silk cloth. The silk is expensive, which is why the rectangular piece needs to have the least area as possible. You love this blanket and decide to minimize the area covering the stains. You buy some ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int coveringStains(int k, List<List<Integer>> coordinates)" ], "script_name": "Solution", "solution": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays...
{ "solution": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Solution{\n public static final int MOD = (int) 1e9 + 7;\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n while(sc.hasNext(...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\n\npublic class Main {\n\nstatic int MOD = (int) 1e9 + 7;\n\npublic static void main(String[] args) throws IOException {\n int N, K, mask;\n int stains[][];\n int arr[];\n int DP[][][];\n i...
{ "class_name": null, "func_sign": [ "coveringStains(k, coordinates)" ], "solution": "def stain_combos(n, k):\n p = 1000000007\n if k < 0:\n return 0\n out = 1\n for i in range(n-k+1, n+1):\n out = (out * i) % p \n denom = 1\n for i in range(1, k+1):\n denom = (denom *...
eJyMvc2KNU2ypSeBLiSpcSPC/8LddSUCFWggnYEmRz3oBoEQ6G50m1rPY5HvV1RTcGrwVe43c+8dEe5uP8uWLft//4f/+f/7H//7/+5/+b//9n/8+3/+r//lb//Tz9/6z/P3f7+73fdnvM88f//30Z97fvrt6/37v//tP/387d/+r//8b//bf/m3//1//T//63/53vX87f/5Tz//8CmDTznnzafc/Zy82G2e/tPauCsv9rj7Z63x9P/wRzY+svV+np9+3rX/42987s8786XnPvtnzJ172mO946e/z5sLuOOs5+esdlpetNvnT662527X...
null
4,847
Candles Counting
Tim is visiting his grandma for two days and is bored due to the lack of the electricity over there. That's why he starts to play with grandma's colorful candle collection. He aligned the $N$ candles from left to right. The $i$th candle from the left has the height $H_i$ and the color $C_i$, an integer ranged from 1 t...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int candlesCounting(int k, List<List<Integer>> candles)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\...
{ "solution": "import java.util.Scanner;\n\npublic class HackerRankCandleCountingFenwick {\n private static final Scanner scanner = new Scanner(System.in);\n\n private static final long PLONG = (long) Math.pow(10, 9) + 7;\n private static final int PINT = (int) Math.pow(10, 9) + 7;\n\n public static class Fen...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class CandlesCounting {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int P = 1_000_000_007;\n\n\tint get(int[] f, int pos) {\n\t\tint ret = 0;\n\t\tfor (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {...
{ "class_name": null, "func_sign": [ "candlesCounting(k, candles)" ], "solution": "def calculate_candles_count(total_candles, color_count, candles_info):\n def read_count(T, index):\n sum_count = 0\n while index > 0:\n sum_count += T[index]\n sum_count %= 1000000007\n ...
eJxM3c2KJcGWJlYNhJ6juOMeHLP9d04/iUAXNJBq0JNSDapA0Aj0PAK9o9LdliWaBZnplhEnPnc3t+W29//9P/7P/8//+z/9D//Lf//Hf/u3f//P//jHf/2Xf3w/n8+/7H/+2/qX9c9/289X8XyVz1f1fNXPV/N89X2++j1frXPIe8x6D1rvUes9bL3HrffA9R653kPXe+x+j93n/3uP3e+x+z12v8fu99j9HrvfY/d7bLzHxntsnG/2PTbeY+M9Nt5j4z023mPjPTbfY/M9Nt9j8/yk77H5Hpvvsfkem++x+R5b77H1HlvvsfUeW+dj...
null
11,882
Mining
There are $n$ gold mines along a river, and each mine $i$ produces $w_i$ tons of gold. In order to collect the mined gold, we want to redistribute and consolidate it amongst exactly $k$ mines where it can be picked up by trucks. We do this according to the following rules: * You can move gold between any pair of mines...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int mining(int k, List<List<Integer>> mines)" ], "script_name": "Solution", "solution": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*; \nimport java.util.*;\nimport ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static long chase2(long dpij0, long dpij1, long[][] cost, int j0, int j1) {\n long l = j1 + 1;\n long h = cost.length;\n while (l < h) {\n int m = (int) (l + h >> 1);\n if (dpij0 + cost[j0][m] < dpij1 + cost[j1][m...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class CodeSprintJuly16qF {\n\n static int l, g;\n static long x[], w[];\n static long dp[][], cost[][], left[][], right[][];\n static long prefix[];\n static long inf = (long)1e17;\n \n public static void main(String args[]) {\n ...
{ "class_name": null, "func_sign": [ "mining(k, mines)" ], "solution": "minup = input(\"\")\r\nL = minup.split(\" \")\r\nn = int(L[0])\r\nk = int(L[1])\r\nlocation = []\r\nvalue = []\r\nfor i in range(n):\r\n a = input(\"\")\r\n L = a.split(\" \")\r\n location.append(int(L[0]))\r\n value.append...
eJyM3cvKNUlypeFu6Av5yLEGscwsDq4raWiBBlLRaFLSoAQCIejr6atsd7f1+i+lSNE1yPL8cofvk1mc1rMj/s//+J//+//+9//2v/71t3/48z/9819+++uf3yJ+6m/+/L7v/dZP5eXx/RPxePz91MPfx89z+fGffuK7PX5+vhgevz/fkMffz9ujcf287+dxzkd79nH/6OkZn2s+RrfHmq8mPc6frOHxfZ71ud657OXxmK+4n/XR9TM+xvnzfuHxPefxsprLXozHz5jD3/7q57c//cs//env/vKnv//bf/znv/AJ6fvit3/7q59/96mp...
null
24,512
XOR Matrix
Consider a zero-indexed matrix with $m$ rows and $n$ columns, where each row is filled _gradually_. Given the first row of the matrix, you can generate the elements in the subsequent rows using the following formula: * $a_{i,j} = a_{i-1,j} \oplus a_{i-1, j+1} \forall j: 0 \le j \le n-2$ * $a_{i, n-1} = a_{i-1, n-1} \o...
hackerrank
Hard
{ "class_name": null, "func_sign": [ "static int[] xorMatrix(int m, int[] first_row)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] ar...
null
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n\n\n Scanner in = new Scanner(System.in);\n\n int...
{ "class_name": null, "func_sign": [ "xorMatrix(m, first_row)" ], "solution": "n, m = map(int, input().split())\nar = tuple(map(int, input().split()))\ni = 1\nm -= 1\nwhile m:\n if m & 1:\n j = i % n\n ar = tuple(ar[pos] ^ ar[(pos + j) % n] for pos in range(n))\n m >>= 1\n i <<= 1\npr...
eJzs3d/KbUu2JXRBH2Ryruti/IkxYoRPIpjghZ4Lb7YlVEGBCD6nT2P7tVinVNIEKZVCqEpO5c691vfNMWNE9Oi99dZa/1/+i//qf/xf//P/7L/+n/7pv//rX//bf/NP/+Xvn97xe8ff/jqPf/l/v//0j//pH///9o9/++uf/tXvn/753/3rf/5v/80//3f/zf/wb//Nn+19/P6j/ifP9T//q9//4bhd5/u7nzWPYzz3fRzfcc3v/ttf8zu+d6z7/K38lXHd5/jNd37X+Zzrt9a7nvO4vt/55ofWNdZvfN+Xv3e9v+e773Gs986CvO+z...
null
2,385
Play on benders
General Iroh and Commandant Bumi are heading to the Republic City to stop a rebellion. But it's quite a long travel, so in the meantime they have started discussing about possible attacking plans. Right now, they're arguing about best ways for moving soldiers during the battle. Tired of not getting a final and concise ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String bendersPlay(int n, List<List<Integer>> paths, List<Integer> query)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static List<Integer> map[];\n static boolean visited[];\n static int order[];\n static int idx = 0;\n \n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n //Prin...
{ "class_name": null, "func_sign": [ "bendersPlay(n, paths, query)" ], "solution": "from functools import reduce\nfrom operator import xor\nfrom itertools import count\nfrom sys import stderr\n\ndef main():\n nvert, nedges = readints()\n children = [[] for _ in range(nvert+1)]\n parents = [[] for _...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
1,280
Coinage
The Indian bank issues coins in 4 denominations, ₹1, ₹2, ₹5 and ₹10. Given a limited supply of each of the above denominations, in how many ways can you sum them up to a total of ₹N? **Input Format** The first line contains an integer T (number of testcases). Each testcase contains 2 lines. The first line contain...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, List<Integer> coins)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution \n{\n \n public static int Wa...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution \n{\n \n public static int Ways(int sum,int one,int two,int five,int ten,int last)\n {\n if(last==1 && sum<=one) return 1;\n \n if(last==4)\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static long solve(int n, int A, int B, int C, int D) {\n long acc = 0;\n int maxD = Math.min(D, n / 10);\n for (int d = 0; d <= maxD; ++d) {\n int maxC = Math.min(C, (n - d * 10) / 5);\n ...
{ "class_name": null, "func_sign": [ "solve(n, coins)" ], "solution": "for i in range(int(input())):\n N = int(input())\n cs0 = tuple(map(int, input().split()))\n r = 0\n for i in range(min(cs0[3], N // 10) + 1):\n for j in range(min(cs0[2], (N - i * 10) // 5) + 1):\n cs = list...
eJylWc2ONDkR5MBrIFlzXiE7f+w0T4LEIA7Ld+Ay7GFXQkJIPAS8LxHp7pkqV/WyiF1Nz9cuVzozMjIyq+afv/7397/5Vf73+3f84w9/f/vLxw8//fj2u/LW/P2jxcDHaFpctcxZ2sCCqbx/qImWwR8vXtv7xxRcitajWIvSo5Xo9v4hs8NE014segltpffA7RM2rGK3i5U2a4mJZdH5/jGijtIrdsYoM2A7hnN3kyJtlvAoYjVPw3J4L1J5CTcoHcGxNk0Kbtc6i9DyjM6PCh8QR5dafKbDuGbdpRhcHNXgJm5XRm8SXnqjAYTJjSKV...
null
2,543
Choose and Calculate
Animesh and Mohit are playing a game. They have $N$ balls in front of them. All the balls are numbered, not necessarily in any order. Animesh picks a set of $K$ balls from the lot each time, checks this set, puts it back into the lot, and repeats this process until all possible selections have been made. At each draw, ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> balls, int k)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util....
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\tstatic final long MOD = (long) (1e9 + 7);\n\tstatic long f[];\n\t\n\tstatic void solve() throws Exception {\n\t\tint n =...
{ "class_name": null, "func_sign": [ "solve(balls, k)" ], "solution": "P = 10**9 + 7\n\nn, k = map(int, input().split())\na = sorted(map(int, input().split()))\n\ninv = [0, 1]\nfor i in range(2, n + 1):\n\tinv.append(P - P // i * inv[P % i] % P)\n \ncomb = 1\nans = 0\nfor pick in range(k - 1, n):\n an...
eJw03TuyLTtzHGAasjiKFf8IGv0CWiNRBGkzgg5DhmTR4bQ0O+WX2CQZ0rnn7EcvNFCoysrM+q//8b/+7f/98z/9y3/+49//43//3//zj//5+8dYz3H8xrne+1//4/6O+1jf73zzt/c1528d4z3u8Yzfe87vO+93/ub1PNd7XPP33vd9fM98fvN5r/u4rvs3xn0d67nP3/3ky8/vu37vmuM8jvs3b1+18g3vMeaV/8wv+778f3PN373e8xzHNfzd+zxr3r/3va7nW8Mvu+azjvv7jXm838jT/J7nOK+ZH/gb9xjzefKg1/2895Hf/Hvm...
null
3,517
Towers
One day John had to take care of his little nephew Jim. He was very busy, so he gave Jim a big bag full of building bricks. The bricks are of various heights: at most 15 different heights. For each height, the bag contains infinitely many bricks. <br> Now, Jim’s task is to build every possible tower of height $N$ fr...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long n, List<Integer> heights)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static Reader in;\n private static PrintWriter out;\n private static int...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static Reader in;\n private static PrintWriter out;\n private static int mod = 1000000007;\n \n \n public static void main (String [] args) throws IOException {\n in = new Reader ();\n ou...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int P = 1_000_000_007;\n\tstatic final long P2 = (long) P * P;\n\n\tstatic int[][] mul(int[][] a, int[][] b) {\n\t\tint n = a.length;\n\...
{ "class_name": null, "func_sign": [ "solve(n, heights)" ], "solution": "MOD = 10**9+7\n\ndef mul(A,B) :\n return [[sum([A[i][k]*B[k][j] for k in range(len(A[0]))]) % MOD for j in range(len(B[0]))] for i in range(len(A))]\n\ndef pow(A,e) :\n P = [[1 if i == j else 0 for j in range(len(A[0]))] for i in...
eJyllE1qHDEQhb2I71H02hjVj0pVOUkgE7JIZpFN24sZMISAD+HcKbtcKVXyGIwaNdhpxDAMo0+v3nvqxw+//15f9efTn/jy+efyY70/n5aPsBgd1lgIGJ/LDSzHh/vjt9Px+9e78+nyH9aqbMuvG3i1kfWwSizg2Arzza0amQ6brcWReWwFBwIs0CAlADIYIEIFlCnSGdlMN9QaPxbvshIVwMDPp+IQRlQGiLDH0yGWwkLJFKGFpWkjGRjNa1MLFXxYuz0NNEEVJObKSTnmth3XRJy4hO8DGY2KWyEPegTwrC+OCNh8UhIpTVlogJF6...
null
2,538
Sherlock and Geometry
Watson gives a circle and a triangle in a 2-dimensional plane to Sherlock. Sherlock has to tell if they intersect/touch each other. The circle is centered at $(x_c,y_c)$ and has radius $R$. **Input Format** The first line contains $T$, the number of test cases. Each test case consists of $x_c$, $y_c$ and $R$...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String solve(int x, int y, int r, List<Integer> t1, List<Integer> t2, List<Integer> t3)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWr...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Solution {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = ...
{ "solution": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.*;\n\npublic class Solution {\n\tprivate static final int mod = (int)1e9+7;\n\n\tfinal Random random = new Random(0);\n\tfinal IOFast io = new IOFast();\n\n\t/// MAIN CODE\n\tpublic void run() throws IOExcep...
{ "class_name": null, "func_sign": [ "solve(x, y, r, t1, t2, t3)" ], "solution": "from fractions import Fraction as F\n\nt = int(input())\n\ndef check(x1, y1, x2, y2, r):\n x, y = x1, y1\n dx = x2 - x\n dy = y2 - y\n A = dx**2 + dy**2\n halfB = x * dx + y * dy\n opt = F(-halfB, A)\n if ...
eJylVLGOFDEMpUB8hzX1BdlOnMTX00JBA2IRBWxBM1yxJyGdkPgI+Cw6PojnzA53oD3Q7G2RvMyOn59f7Pn6+PvPJ4/G79UPgDc308f56vowXdIku9kykzTHwp53s3uhkq3s5mLeKKn2GlhJBpouaNp/vtq/P+w/vPt0fTgSvX72cvpyQX9SVwar5kItN3DgUMR2c5JaMnnrgFkFj73JNmbJlamyUJcWLI4isnbezY0zSRXFO5U7uW4jbtIpiWuDJwytrVcqLXskYeukZngreS2wRtw2ylZzmNCd4AAccTZSrIAdiVKtQY7MnbK3so0c...
null
3,586
Jim and the Challenge
Hey buddy, How are you? Last night I saw you programming on Hackerrank in my burger restauraunt. So I wonder if you can help me out on a problem I've been struggling with for like 10 hours. It is called "The Challenge" and for some reasons the online judge always gives me TLE (Time Limit Exceeded). My code and the im...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int d, List<List<Integer>> points)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport jav...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\n\npublic class D {\n static InputStream is;\n static PrintWriter out;\n ...
{ "solution": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelpe...
{ "class_name": null, "func_sign": [ "solve(d, points)" ], "solution": "#!python3\n\nmodval = 1000000009\n\ndef fst(a): return a[0]\ndef snd(a): return a[1]\ndef tail(a): return a[1:]\ndef prodM(a):\n t = 1\n for i in range(len(a)):\n t *= a[i]\n t %= modval\n return t\ndef sumM(a):\n...
eJx0/U2udUuXpAtRoAU0AG1F+R5p+r87TaAFSIREAbJAJbiFvBISQqLp2POM9eVFgSILeeI75333XmtO9/Fjw8zG/+d/+3/6P/7v/vf/m//z/+vf/u//8T//L//93/4Pf/82/ua//0f73jrz77497t8/59111t8/e7xv55+trTHfv//HPve74+/M9rX598/a7Y3vb573Zv7nnfvd79//Y7Xe+5efdUbrf2t//csfWtOfNOdZ7d//49/+p79/+2//z//5v/1f//t/+7/9X/4f/8t//32WNs7LT9nt3/7f/9Pf/89n7H/j3/9jvrO+9Xe+...
null
1,636
Array Manipulation
Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array. **Example** $n = 10$ $queries = [[1, 5, 3], [4, 8, 7], [6, 9, 1]$ Q...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long arrayManipulation(int n, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java....
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": " /*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n \n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.uti...
{ "class_name": null, "func_sign": [ "arrayManipulation(n, queries)" ], "solution": "N,M = [int(_) for _ in input().split(' ')]\n\nIs = {}\nfor m in range(M) :\n a,b,k = [int(_) for _ in input().strip().split(' ')]\n if k == 0 :\n continue\n Is[a] = Is.get(a,0) + k\n Is[b+1] = Is.get(b+1,...
eJx0vbuudU2QZYUBNq9wVDZGXldm8g74SJSEAW3gNBjdEhJC4tGZY8T+ARUqRFXXd/5z9l4rL3GZMWPG//Vf/vf/3X/9X/0X/8P/8S//y3/83/7zf/qX//bvX8b7W+df/2P/G+fv3q/te+bLv9vf+P5ev/2d275//Y/nr4+/8Vo/s9/8u6+//v7yr6+3/Mq//sfFL7x5v3n2yr/zH9ff1+Yep598w/c3+t+3v3vHbP673795eztj7XzgWH/5/99t4xtv5AsO/15r7Pbu7P7Ab7x3f+PmE/bf+Tunv5vfyH+f+ed997w8U76/97/8/2OP...
null
8,136
Largest Rectangle
*Skyline Real Estate Developers* is planning to demolish a number of old, unoccupied buildings and construct a shopping mall in their place. Your task is to find the largest solid area in which the mall can be constructed. There are a number of buildings in a certain two-dimensional landscape. Each building has a heig...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long largestRectangle(List<Integer> h)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tstatic boolean[] valid;\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(...
{ "solution": "import java.util.Scanner;\nimport java.util.Stack;\n\npublic class h \n{\n public static void main(String[] args)\n {\n Scanner o = new Scanner(System.in);\n int n = o.nextInt();\n int[] j = new int[n];\n for (int i = 0; i<n; i++)\n {\n j[i] = o.nextI...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\n\n\npublic class Solution\n{\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 64 * 1024);\n\n final in...
{ "class_name": null, "func_sign": [ "largestRectangle(h)" ], "solution": "\ndef solve(H) :\n s,i,m = [],0,0\n while i < len(H) :\n if not s or H[i] > H[s[-1]] :\n s.append(i)\n i += 1\n else :\n t = s.pop()\n a = H[t] * ((i - s[-1] -1) if s e...
eJx83b+uLMGS3WcaAvgKMhPXplHZ9Ser+CQERICGOIacEY0hIEgQwEfn+lbuEUhHA5xec+89uc7e3dFVWfHLiPhv/8t/+F//73/7b/63/+cf/8c//5f/+i//+PfjH+/3H//5Pb7n+cZz3fObY837d63xPM/1u8Z7vuv9jfv4zfsZv/O+5zPWe//usY57vnP8fs88s/r9/dY1zuecWX0f9xfL636f+Y37i8017sdfyurnu98x17F+Z/7L41yRGe+YPb/nvce7zvXmHzi+/DPzO+M473k9WfR9a473u491jO86v+Mez73OyDXXWs/4vue4...
null
73
Subsequence Weighting
A subsequence of a sequence is a sequence which is obtained by deleting zero or more elements from the sequence.  You are given a sequence `A` in which every element is a pair of integers  i.e  `A` = _[(a<sub>1</sub>, w<sub>1</sub>), (a<sub>2</sub>, w<sub>2</sub>),..., (a<sub>N</sub>, w<sub>N</sub>)]_. For a subseqen...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> a, List<Integer> w)" ], "script_name": "Solution", "solution": "import java.util.Map.Entry;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.SortedMap;\nimport java.util.TreeMap...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n // Complete the solve function below.\n static final int N = 200005;\nstatic long[] max = new long[N];\n\nstatic long getMax(int x) {\n long maxw=0;\n f...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Solution soln = new Solution();\n soln.run();\n }\n\n private void run() {\n try (Scanner scanner = new Scanner(System.in)) {\n int numTestCases...
{ "class_name": null, "func_sign": [ "solve(a, w)" ], "solution": "import sys\nimport bisect\n\nfor t in range(int(sys.stdin.readline().strip())):\n sys.stdin.readline()\n a_list = [int(x) for x in sys.stdin.readline().strip().split(\" \")]\n w_list = [int(x) for x in sys.stdin.readline().strip().s...
eJw03TmyJeuSpNciMJAtOQLvmxoJRPAmAOYKiCoKDAjwNeWy9fm5+bKJjDhnb/e/sUZNTe3/+z/+z///f63/7f/6f//r//7n//mf/+O//vvvv87//LPv73/+ud79uJfreX/P+27vft3771y3Zzvv6/itz7Vc+3Jcv/N69vU9rvd3PMv+nr/9fa79vrf9dyz7fu73uf6udb23Zb3P33a863pe7/qbD9+vZz1/x7q86/Eu86f5xPnybfmty/G817ksv+M6j2dbr9+63cc+z7H9nm1/5uf3+bTtXs/9OBbftW2nv1uX65qffO7fcaz3/h73...
null
2,413
Roy and alpha-beta trees
Roy has taken a liking to the [Binary Search Trees](https://en.wikipedia.org/wiki/Binary_search_tree)(*BST*). He is interested in knowing the number of ways an array $A$ of $N$ integers can be arranged to form a *BST*. Thus, he tries a few combinations, and notes down the numbers at the odd levels and the numbers at th...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(int alpha, int beta, List<Integer> a)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n final static long MOD = 1000000009;\n\n public static void solve(Input in, Pr...
{ "solution": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nclass ANKBST02_solver {\n long go(int lo, int hi, int odd) {\n if (lo > hi) {\n return 0;\n }\n if (dp[lo][hi][odd] == -1) {\n long ans = 0;\n for (int root = lo; r...
{ "solution": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nclass solve {\n long go(int lo, int hi, int odd) {\n if (lo > hi) {\n return 0;\n }\n if (dp[lo][hi][odd] == -1) {\n long ans = 0;\n for (int root = lo; root <= hi;...
{ "class_name": null, "func_sign": [ "solve(alpha, beta, a)" ], "solution": "MOD = 10**9 + 9\ndef compute_catalan(N):\n global MOD\n catalan = [0]*(N+1)\n catalan[0] = 1\n for i in range(1, N):\n for j in range(i):\n catalan[i] += catalan[j]*catalan[i-j-1]\n catalan[i] %...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
4,940
Taxicab Driver's Problem
Burger Town is a city that consists of $N$ special junctions and $N - 1$ pathways. There is exactly one shortest path between each pair of junctions. Junction $i$ is located at $(x_i, y_i)$ and the distance between two junctions $i, j$ is defined by the Taxicab geometry. Tim has recently afforded a taxicab to work as...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long h, long v, List<List<Integer>> junctions, List<List<Integer>> edges)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static class Pair implements Comparable<Pair> {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\nstatic class Pair implements Comparable<Pair> {\nlong fi;\nlong se;\n\npublic Pair(long fi, long se) {\nthis.fi = fi;\nthis.se = se;\n}\n\n@Override\npublic int compareTo(Pair o) {\nif (fi != o.fi) {\nreturn fi > o.fi ? 1 : -1;\n}\nif...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static class Pair implements Comparable<Pair> {\n long fi;\n long se;\n \n public Pair(long fi, long se) {\n this.fi = fi;\n this.se = se;\n }\n\n @Override\n public int compareTo(Pair o) {\n if (...
{ "class_name": null, "func_sign": [ "solve(h, v, junctions, edges)" ], "solution": "from collections import namedtuple\nimport bisect\n\nDistTuple = namedtuple('distance', ['h', 'v'])\n\n\ndef insort_right(arr, dist, hv):\n x_key = dist.h if hv == 'h' else dist.v\n lo = 0\n hi = len(arr)\n whil...
eJzsvcuKbkm2pSeBHuQn2yWw+0VPIlCAGtJpqJOqRhUUCIEeXeMbw3yH7zzpkAeqGdEI335Z61/LbNq8jjnm//c//a//89/+x//hf/t//vZ//f0//9f/8rf/5fO32s+nzjbGnGuOzz760vuef/x93rPr+Kw62mh//H2vPcb+1N13129PbWfOz1lj1PPH3/s4V5eP0vrof/x9rblr/5y277r67d69zc/Vj0vRt63NvT6jFv2V7tzLPf3T6riFb++Z7XzWOXWuP/5+9Ue3fu5cq+m3/bR59Rh16Msffx9j6a/0GKXdyueuMpvufGrRU93R...
null
29,530
Climbing the Leaderboard
An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses [Dense Ranking](https://en.wikipedia.org/wiki/Ranking#Dense_ranking_.28.221223.22_ranking.29), so its leaderboard works like this: - The player with the highest score is ranked number $1$ on the leaderboard. ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> climbingLeaderboard(List<Integer> ranked, List<Integer> player)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solu...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\n/**\n * Created by aurel on 16.10.2016.\n */\npublic class ClimbingTheLeaderboard {\n\n public static void main(String[] args) {\n InputReader in = new StreamInputReader(System.in, 2048);\n PrintWriter out = new PrintWriter(new BufferedOutputSt...
{ "class_name": null, "func_sign": [ "climbingLeaderboard(ranked, player)" ], "solution": "#!/bin/python3\n\nn = int(input().strip())\nscores = list(reversed(sorted(list(set([int(scores_temp) for scores_temp in input().strip().split(' ')])))))\nm = int(input().strip())\nalice = [int(alice_temp) for alice_te...
eJzs3U2OLDmSLegevIUYYpwDUkn9q5U00AnUoCoHNYnKQRZQQKGAXlpvpPfS5xOza9c9IjLxuvtd82uABlQYct3dTMxU5ZBC4aHw//wf//v//X/9j//t//ivX/7t17/+x99++afbL0trf/61t2//3S71Ui/1Ui/1Ui/1Ur9S/fOvS+S8/zfH7aGt2zdtW75pR39qx1M7v2nn/kH7Kb7YL3+6/fKX//zrX/7lb3/513/+9//427doLF/5j67+P3H98t9/un0I7NbzmHntedzeV7Y3lvnGsryxtPeUdFvvKdubynxTWd5U2nvKfrypbG8q...
null
22,869
Designer PDF Viewer
When a contiguous block of text is selected in a PDF viewer, the selection is highlighted with a blue rectangle. In this PDF viewer, each word is highlighted independently. For example: ![PDF-highighting.png](https://s3.amazonaws.com/hr-challenge-images/22869/1471640108-6c01750b16-PDF-highighting.png) There is a lis...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int designerPdfViewer(List<Integer> h, String word)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public stati...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'designerPdfViewer' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts following parameters:\n * 1. INTEGER_ARRAY h\n * 2. STRING word\n */\n\n public static int ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class _101HackAug16qA {\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int a[] = in.nextIntArray(26);\n char s[] = in.readStrin...
{ "class_name": null, "func_sign": [ "designerPdfViewer(h, word)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nh = [int(h_temp) for h_temp in input().strip().split(' ')]\nword = input().strip()\nprint(len(word) * max(h[ord(l)-ord('a')] for l in word))", "template": "#\n# Complete the 'designerPdfView...
eJy1VdFumzAU3cOk/YbFczUVY+xqXzJpnioSSEOSOckKbZpp0j5i+9K97WnXx5dUhbiBh3IFNgbOuefca/Hr/Z9/H97h+PyXJl9+JLXbtU3ySSRKaJEKg8hwSjpzoTD6Jwr3mu5zClq1bn+wLrkSSXXYVfOmKm+3bcN4qUp+XokXBOEzH55KgsRDK1w9tKZ5SqHpGT23brEqW1c+3C/iROZ6QBQy1KzEU4X8JdYMqwjqfEqpdauiiku56TGEb71DIfWQsoIUJA4+jTc0vWk8QzMr2t36qYnS5PqMYxISNBxDqlwQyZFBbHCPhFr3EJdx...
null
17,610
Non-Divisible Subset
Given a set of distinct integers, print the size of a maximal subset of $S$ where the sum of any $2$ numbers in $S'$ is *not* evenly divisible by $k$. **Example** $S = [19, 10, 12, 10, 24, 25, 22]$ $k = 4$ One of the arrays that can be created is $S'[0] = [10, 12, 25]$. Another is $S'[1] = [19, 22, 24]$. After t...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int nonDivisibleSubset(int k, List<Integer> s)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\ni...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n int...
{ "class_name": null, "func_sign": [ "nonDivisibleSubset(k, s)" ], "solution": "read = lambda: map(int, input().split())\n\nn, k = read()\na = list(read())\ncnt = [0] * k\nfor x in a:\n cnt[x % k] += 1\n \nans = min(cnt[0], 1)\nfor rem in range(1, (k + 1) // 2):\n ans += max(cnt[rem], cnt[k - rem])...
eJxM3UuuLc2SHGY2OJCF22YjH5ERmRwJARWghlQNdUpsFAEBBAFC89UcaJ/FvoCKAP9zz9l7rXxEeLibm5n/z//4X/6///c//of/7b//4//6t//63/79H//594/395z/8m/PGvca53P+7jW/8xj39XufOc/7u+dvXN+xjud7f2PdY+bnrt/zPm/+dYzfut/7+uZ3/a7rPu5zPPNf/u0f/+n3j3/9f/7rv/4f//6v/+f//n//t3//57flX/7Hf/r9/77/e9/1e9e//Nu5vuP41np/PvVcd/601ljnPR4fvcY4juP5jWPlSlb+7h3PPddz...
null
26,114
Fraudulent Activity Notifications
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is *greater than or equal to* $2 \times $ the client's [median](https://en.wikipedia.org/wiki/Median) spending for a trailing number of days, they send the cli...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int activityNotifications(List<Integer> expenditure, int d)" ], "script_name": "Solution", "solution": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author jin\n */\npublic class Sol...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n int[] cnt;\n\n int med(int d) {\n int[] a = Arrays.copyOf(cnt, cnt.length);\n int r = d / 2;\n if (d % 2 == 1) {\n r++;\n }\n int re...
{ "class_name": null, "func_sign": [ "activityNotifications(expenditure, d)" ], "solution": "from bisect import bisect_left, insort_left\n\nn, d = map(int, input().split())\nt = list(map(int, input().split()))\nnoti = 0\n\nlastd = sorted(t[:d])\ndef med():\n return lastd[d//2] if d % 2 == 1 else ((lastd[...
eJztvcuuJcmylU2DBwntNkJ+v/AkSBSiAadBp6BxkH7pFxIPAY/DU9Gjhdv4hsecWVm5dYRo1q7MvXKtFTPCw93cLsOGmf+3f/4//vf//Gf637/+X+cf/+b//9t//P0//5d//Nu/ev7WR35K+u33OZ89nrWfPOb5259c0pNXefI+/z4X5d2e/aynjvPt+Tvr+Xp+3c5V5xNpPee6Wp5+flbW+WF9Rlx+bn++K/s59018tJ3rz8/3uUOJm6cnnnUuqfMp4zzlfLfnuV88tpy/OYZ1HrTPvc/Px1M3d4mHnWfm8cSv41/t/KY2/V36Lt4q...
null
26,945
Hackerland Radio Transmitters
Hackerland is a one-dimensional city with houses aligned at integral locations along a road. The Mayor wants to install radio transmitters on the roofs of the city's houses. Each transmitter has a fixed range meaning it can transmit a signal to all houses within that number of units distance away. Given a map of Hacke...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int hackerlandRadioTransmitters(List<Integer> x, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public s...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class UnivCodesprint2016qA {\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int n = in.nextInt();\n int k = in.nextInt();\n ...
{ "class_name": null, "func_sign": [ "hackerlandRadioTransmitters(x, k)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn,k = input().strip().split(' ')\nn,k = [int(n),int(k)]\nx = [int(x_temp) for x_temp in input().strip().split(' ')]\n\nx.sort()\n\ns = set(x)\nminx = x[0]\nmaxx = x[-1]\nd = dict(zip(ra...
eJxEvUuSZUusXKcGR6ARHHsjCMQ/OBKZkRNg5xkbUosddjVrYS3sLHXK7q3KPGd/IhCAw93xv//L//X//p//5f/4b//rP/7Hf/7P/+f//o//+vuP6Ku933mz3f/+n3FfxK+P1+6vn7XXb504vznuXb958p9/vb05fmNFn7/T1v2NES3/s+e/zd75udfa7+z967vd8ZvrzvYb78382TfP/eXHtPyxMVb7Pf5znBfjF73lb0c76/xizT1/M3b/zbtXfnTbO36jx4z8m5NXOUbbj189+YN77/HrfZ6d/31u/lZ+fP7r7Ct/8rYTvxjnbi6x...
null
60
Problem solving
There are N problems numbered 1..N which you need to complete. You've arranged the problems in increasing difficulty order, and the i<sup>th</sup> problem has estimated difficulty level *i*. You have also assigned a rating *vi* to each problem. Problems with similar *vi* values are similar in nature. On each day, you w...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int problemSolving(int k, List<Integer> v)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tprivate void solution() throws IOException {\n\t\tint ts = in.nextInt();\n\t\twhile (ts-- > ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n private static final class Data {\n\n private final int index;\n private final int value;\n\n private boolean visited = false;\n private int match = -1;\n\n private Data(int i, int v) {\n ...
{ "class_name": null, "func_sign": [ "problemSolving(k, v)" ], "solution": "G = []\nV = []\nM = []\n\ndef find(v):\n for u in G[v]:\n if not V[u]:\n V[u] = True\n if M[u]==-1 or find(M[u]):\n M[u] = v\n return True\n return False\n\n\nt = int(input())\nfor _ in range(t):\n n, k...
eJztm8uqp0tSxR34IB81biQz8hoOfA7BEgd6Bk7KHpwGQYR+iPY9nPl6rt+Kr9q262ywEcHBPpxd+/L/Lplxj7Uif/vn//Yff/Vn/u+v/10//M2/fPnHb7/+zc9f/vL5sr9+6/2Jdb5+y9ueftezdzwR5+H3OOfZMZ+795NHf5/9OVs3zXgOtw5dvp+ZunWsZ+qSvnVJPn3lM3TRvvrreZYeuo7+cp+zti7IZ01dNZ6uV6229eh4xjzPae0ZZ2kpz7p6fA49IPUgXR39ST339qlL23P12jvOE7olpp66uXXr8/7cZ4+lFbbnxPj67ejJ...
null
105
Greedy Florist
A group of friends want to buy a bouquet of flowers. The florist wants to maximize his number of *new* customers and the money he makes. To do this, he decides he'll multiply the price of each flower by the number of that customer's previously purchased flowers plus $1$. The first flower will be original price, $(0+...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static int getMinimumCost(int k, int[] c)" ], "script_name": "Solution", "solution": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @auth...
null
{ "solution": "import java.io.*;\nimport java.util.*;\n\nclass Solution\n{\n\tprivate static BufferedReader in;\n\tprivate static PrintStream out;\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tin=new BufferedReader(new InputStreamReader(System.in));\n\t\tout= new PrintStream(new BufferedOutpu...
{ "class_name": null, "func_sign": [ "getMinimumCost(k, c)" ], "solution": "N, k = [int(i) for i in input().split(' ')]\nci = [int(i) for i in input().split(' ')] \n\nci.sort()\n\nif N<len(ci):\n\tN = len(ci)\n\ntotalCount, perPerson, curRound, totalAmount = 0, 0, 0, 0\npFlower = len(ci) - 1\nwhile totalCou...
eJztmL2OZEkRhcdAPAH4qbFXKP8iI5MnQaIRBoyB06wxKyGhlfYh4Hnh+7LGAHVXW1hod6eru6ruzYyMOHHOifvTL/75y19/uv/97l+/+vTp93///JfX73/4+vm35XO2ssfL6245Zy0588Qpu55RD+/q6lky61qrLN7FLGdm7Ci71Tm9so09WCIzdzmr19XK6bk7N5wR97t5di1rj7OO73LuEr3xtsTZM/k11sledtY+s6xRa+fKqHP0csZsrZbR6jil1dqy9B05S4/IWmad+/ht55NVzylz+/kefZfWd2YZEXX48Sotxpl8fHb3Hq4b...
null
20,732
Beautiful Triplets
Given a sequence of integers $a$, a triplet $(a[i],a[j],a[k])$ is beautiful if: * $i<j<k$ * $a[j]-a[i] = a[k]-a[j] = d$ Given an increasing sequenc of integers and the value of $d$, count the number of beautiful triplets in the sequence. **Example** $arr = [2, 2, 3, 4, 5]$ $d = 1$ There are three beautifu...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int beautifulTriplets(int d, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static vo...
{ "solution": "import java.util.*;\n\npublic class BeautifulTriplets {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int d = sc.nextInt();\n int count = 0;\n HashSet<Integer> set = new HashSet<>();\n for(int i =...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "beautifulTriplets(d, arr)" ], "solution": "n, d = map(int, input().split())\na = list(map(int, input().split()))\ncnt = {}\nleft = []\nfor x in a:\n left.append(cnt.get(x-d, 0))\n if x not in cnt:\n cnt[x] = 0\n cnt[x] += 1\nleft = left[::-1]\ncnt = {}\n...
eJzs3b+ufE12l3ECX0hrYge9q9afKq4ECUsE4ACCwYEtIVlIXAHXTD1P7X6FNHJCypt0YE4xM2fV7/TuT3/XWv/r7/7Df/vff/fv/uO//uW//vWf/uWf//LvP3+Jzs/T//DX7+f5jM/8xCc/9enP+uzPc/6Pz+cZn2d+nvg85yfr/PDnWZ9nf8b3M86Z8RnzM+Iz8jPqM/oz1mfsz/x+5vOZ5//L+ZnxmfmZ9Zn9mesz9ye+n3g+MT5x/hPjE/mJ+kR/Yn1if/L7yeeT45Pzk+e/UH6yPtmfXJ/cn/p+6vnU+NT8VHzq/PetT/Wn1qf2...
null
19,049
Synchronous Shopping
Bitville is a seaside city that has a number of shopping centers connected by bidirectional roads, each of which has a travel time associated with it. Each of the shopping centers may have a fishmonger who sells one or more kinds of fish. Two cats, *Big Cat* and *Little Cat*, are at shopping center $1$ (each of the c...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int shop(int n, int k, List<String> centers, List<List<Integer>> roads)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java....
{ "solution": "import java.util.*;\n\npublic class SynchronousShopping {\n\n private static class Truple {\n int dist;\n int next;\n int fish;\n\n public Truple(int dist, int next, int fish) {\n this.dist = dist;\n this.next = next;\n this.fish = fish;\n...
{ "solution": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\n\npublic class HR_synchronous_shopping {\n\n static int k;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int m = in.nex...
{ "class_name": null, "func_sign": [ "shop(n, k, centers, roads)" ], "solution": "from heapq import *\nfrom itertools import *\nfrom sys import stderr\n\ndef main():\n nvert, nedge, setsize = readints()\n vertexhas = []\n for _ in range(nvert):\n nelts, *elts = readints()\n assert nel...
eJycvcuuLEuTrQUSD5Kq9mmE391p8hRILIkGVIPOz2nUkZAQEo+Oj29YREbmzJxrF9JftdfMS2SEu7ldhw37f/+H/zn/T//9f/e//N//9n/867/+t//4t//x8W/lkR/5z7/SI/35V34k/9v/79H0UtF//u2/PP7t3/+v//rv/9t//Pv//r/+n//tP+LL6dhv/T//5XG7XpvtMdt66K2yr1f4V9OVH+MxH+vPv+qjPfr+Y+ny+7U//5q8fb7Oh/pDP133C5MrTK5Vzw/E9fXK0OX3XfKGXk76/v7v4qolrnv/0oyb8rvj/L0aF1n6ufzj...
null
24,358
Jumping Rooks
Nina has an $n \times n$ chessboard and $k$ jumping rooks. Every cell of the chessboard is either *blocked* or *free*, and Nina can only put a *single* rook in any *free* cell. Two jumping rooks beat each other if they are either in the same row or in the same column *and* all cells between them are free (note that i...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int jumpingRooks(int k, List<String> board)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport j...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class C {\n InputStream is;\n PrintWriter ...
{ "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter ou...
{ "class_name": null, "func_sign": [ "jumpingRooks(k, board)" ], "solution": "#!/bin/python3\n\nimport os\nimport sys\n\n# Complete the jumpingRooks function below.\n\n# Read input values\nn, k = map(int, input().split())\nchess = [[i for i in input()] for _ in range(n)]\n\ndef getVal(c):\n \"\"\"Calcula...
eJztWsuOHUUMZcGHtMbbyLp9H3MZNvwGEkEsYBZshiwmEhJC4iPgr9jxQ8x01fE5rqqe3JvwEulOMunusl32sV1Vds8vn/72xxefLNeXvz/dfPXTzfcPb94+3nw+3Rx20/z6wV68tvFt/Onyf3n+j27c3zFO/ptX0839j2/uv328/+6bH94+1uTePY38/GqSdD+epvn2PBa45l9Xcu9u5MmV3DuejsW9WNeThkRvX79+SGIWgpZI3i7KJKmtNq7jIHdfjXa9iqk+FIVXzsmK7uvWEhRId9oD4flHQmYkWMmTcitR5d2tL3+eyTtMvOHo...
3
12,233
Travel in HackerLand
HackerLand is a country with $n$ beautiful cities and $m$ undirected roads. Like every other beautiful country, HackerLand has traffic jams. Each road has a *crowd value*. The crowd value of a path is defined as the maximum crowd value for all roads in the path. For example, if the crowd values for all roads are $[1, ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int travel(List<Integer> t, List<List<Integer>> roads, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "//package codesprint;\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class travelinhacker {\n\n\tstatic int N = 100...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static TreeSet<Integer>[] all;\n static int ind;\n\n static void swapAll(int root_A, int root_B) {\n TreeSet<Integer> tmp = all[root_A];\n all[root_A] = all[root_B];\n all[root_B] = tmp;\n }\n\n \n static class Disjoin...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.List;\n...
{ "class_name": null, "func_sign": [ "travel(t, roads, queries)" ], "solution": "from collections import defaultdict\nimport heapq\n\ndef root(ids, i):\n while ids[i] != i:\n ids[i] = ids[ids[i]]\n i = ids[i]\n return i\n\ndef union(queries, blds, ids, p, q):\n i = root(ids, p)\n j...
eJztnc2uZctylWnwHizdBi0bzfzP5EmQKEQD3KBzccOWkJAlPwS8L+MbI+f2uXWqzrWvjYWQj05p77XXXHPmT/yMGBEZ62//9f/+t3/7r/zff/g3+uU//s/f/bff/+Vf/9Xv/v3nd6V8Sv+cb78vn/ppn/75g5/ffl8/5fnUds58vv1+fsanjXbK/Pb7o6vabnX2b7/f/n2OU/hdt9vrPPpdHz2f0tqqnQcs3auNUvn9fPYYvS1f1D5lzlL0gks++xm17m+/9zDWevzp56OhnqfOx5/X69V3a4VR7c+eZTx+iJ7PbRg3g9Fz9NfiD2eS...
null
3,349
Alex vs Fedor
In order to entertain themselves during the long flight, Alex and Fedor invented the following very simple two players game. The game is: - First, Alex draws some graph with bidirectional weighted edges. There are possibly multiple edges (probably, with different or same weights) in this graph. - Then Fedor picks s...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String alexFedor(int graphNodes, List<Integer> graphFrom, List<Integer> graphTo, List<Integer> graphWeight)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayLi...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Solution {\n\n static class EdgeNode implements Comparable<EdgeNode> {\n int u;\n int v;\n int w;\n\n EdgeNode(int u, int v, int w) {\n this.u = u;\n this.v = v;\n this.w = w;\n }\n\n ...
{ "solution": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws NumberFormatException, IOException {\n //\t long start = System.currentTimeMillis();\n //\t System.out.println(getSpa...
{ "class_name": null, "func_sign": [ "alexFedor(graph_nodes, graph_from, graph_to, graph_weight)" ], "solution": "#!/bin/python3\n\nimport os\nimport sys\nfrom decimal import *\n\n#\n# Complete the alexFedor function below.\n#\n\n#\n# For the weighted graph, <name>:\n#\n# 1. The number of nodes is <name>_no...
eJzFWcuOJbcNzSJ/kU2h10ZGpCiR9JcEyARZJLPIZuLFGAgQGMhHxP+bcyRV3dL1dKfHG9twF6WrB99HpP/z+5/jD78b//xJQPz53y//+PzDj19evj9epB8SHz/LoYfwUw/9+LkedtjHz3a0o0uqeSuFP3bO6uFc40fwY0ce4iVbWgmM2yHlqFwlcjRsKocoJ/yQevSWXUNzLrRDWmnFurnwJGnzcvLEBTgjs5fqUfvHz8kN+B3n4kQw8vLd8fLpXz98+tuXT3//6z9//HJK9CHl5afvjruQuCynkHUKaUW1eXOObEqFNSI1mngauQAT...
null
3,187
Largest Permutation
You are given an unordered array of unique integers incrementing from $1$. You can swap any two elements a limited number of times. Determine the largest lexicographical value array that can be created by executing no more than the limited number of swaps. **Example** $arr=[1,2,3,4]$ $k=1$ The followi...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> largestPermutation(int k, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n publi...
{ "solution": "\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class problem13 {\n\npublic static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int k = input.nextInt();\n int[] a = new int[n];\n int[...
{ "solution": "import java.io.*;\n\npublic class HR_worst_permutation {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n long k = in.nextLong();\n int[] p = new int[n];\n int[] invP = new int[n];\n for (int i = 0; i < n; ++i) ...
{ "class_name": null, "func_sign": [ "largestPermutation(k, arr)" ], "solution": "n, k = map(int, input().split())\np = list(map(lambda s: int(s) - 1, input().split()))\n\nwhere = [-1] * n\nfor i, x in enumerate(p):\n where[x] = i\n \nfor i in range(n):\n if k == 0:\n break\n if p[i] != n...
eJxMnbvOdUlyXGXI0VsctE2j7hc+iQAOQEMaQ86IxhCQIBDgc/HpVGvFboDGTHf///edsy9VWZkRkZH//l//+3/83//2X/7p//3xv/72L//69z/+8fdHrWP8+rlltL7qX/62R/u1dn5n7vfH43fO+dVa+m+d/uu1/mp5vzBK+61W+Zv6m/v+zpq/NtfvlPNb7wfm2r96y2/N8+v9feT7gPH+qq9f3+d3+2+/z5zvJxdf8j53Xb50/mav74vr777fbu/n5u7vO993tVl+s473ne8Saznrt/v7mPO+ZKzfaFzneD/2/qPu32zvh95vvAt8...
null
21,552
Goodland Electricity
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $1$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int pylons(int k, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(Str...
{ "solution": "import java.util.*;\npublic class GoodLand {\n public static int goodland(int[] a,int k) {\n int min_towers = 0;\n int village = 0;\n int provider = village + k - 1;\n while(village < a.length) { \n if(a[provider] == 1) {\n village = p...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i...
{ "class_name": null, "func_sign": [ "pylons(k, arr)" ], "solution": "from sys import stderr\n\n[n, k], c = map(int, input().split()), list(map(int, input().split()))\n# k += 1\nans, last = 0, 0\nwhile last < n:\n i = max([last - k] + [j for j in range(max(0, last - k + 1), min(n, last + k)) if c[j]])\n ...
eJztWcuOFDkQ5MCHlPo8ILuqH8Bhv2MlZsUB5sBl4DBISAiJj9jV3vZbqaZ3piszItJ2dfUgUI81/fAjMzLyYbv629N//vvjyY+/P/8dP7z+snp/+/HT3epVt+pTN1zf5i53qdyub1dX3erm88ebt3c37958+HT3v5RneRz6etVNBOeh73L/4iB7L/346lty7wcsfn4qfK+Ry0Z5Xwp0KXRTDq2E8ZPkDqlbv+zy2GvJzxOhFa6azMoP7xaghrQGSLvd0K2H7QGUFeiEQt90fgSPGTvl1fsTR5B570XEYKUmIgnjwMvnbrJr2Wh2fdnI...
null
1,049
Angry Children 2
Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimize the cumulative difference in the number of candies in the packet...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long angryChildren(int k, List<Integer> packets)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static long cur...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n \n long[] packets = new long[n];\n \n for (int i = ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner sc = new Scanner(System.in);\n int numPack =...
{ "class_name": null, "func_sign": [ "angryChildren(k, packets)" ], "solution": "n = int(input())\nk = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\na.sort()\nps = [0]\nfor i in range(n):\n ps.append(ps[-1] + a[i])\ncur = 0\nfor i in range(k):\n cur += i * a[i] - ps[i]\nans = c...
eJztncuuLtlylWnwINZpI5SRM688CRKFaIAbdA40jISELPEQ8Gz0aPMYjO8bubEpU5YlhERjlct59tq18v/zEjMuY4yI+Z//8X/97//jH/nPP/9v+cO/+E9/+rd//vf/4a/+9M/+4k/Pb3++f/vzbO+825k/Pc92nefzvvzx2s7nXvzx2rdznje/sPbtyk/v9duf33nmvXNC/vY9z/vd1vrtz/t2v8e+v/njn/7JX/zpL//jv//Lf/1Xf/lv/tW/+w9/9X3nfbxrv9d69j/99T/5i791Mfmg/Htcz3qv691zXfe6cm13rvLYcn3Hfh75...
null
28,833
Queen's Attack II
You will be given a square chess board with one queen and a number of obstacles placed on it. Determine how many squares the queen can attack. A [queen](https://en.wikipedia.org/wiki/Queen_%28chess%29) is standing on an $n \times n$ [chessboard](https://en.wikipedia.org/wiki/Chess). The chess board's rows are numbe...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int queensAttack(int n, int k, int r_q, int c_q, List<List<Integer>> obstacles)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class So...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\ni...
{ "class_name": null, "func_sign": [ "queensAttack(n, k, r_q, c_q, obstacles)" ], "solution": "#!/bin/python3\n\nn, k = map(int, input().split())\nrQueen, cQueen = map(int, input().split())\nobstacles = set()\nfor _ in range(k):\n rObs, cObs = map(int, input().split())\n obstacles.add((rObs, cObs))\na...
eJzsvbvOLT2SHTiGHuSg7DaSd1JPMsAUIEMqQ06rjWpAgNCA3mtebmJdMneIPQWMMaYE6DRr/ZH55c5kkHFZEfyf/+H//Lf/+z/8H//X//jLf/3nf/nXv//lP/75Sxt/yvrrP9f5p/Dfyn8b/+38d/z1nwv/I/5p+Kfjn0Fs8YLNCw4uaA8uaOXPTLf7/v3LP/35y9/++7/87T///W//5T/9t3/9ux9ixIV/+bd/+pOfq7U/z1//ec4/5x9eVp5S/92FpfDCM/6M/Q+vbOv/5cL4gRu/sPlnNjxx44/SS8CPxD8d/wyN8I4gN773NPHT...
null
22,662
Fighting Pits
Meereen is famous for its fighting pits where fighters fight each other to the death. Initially, there are $n$ fighters and each fighter has a strength value. The $n$ fighters are divided into $k$ teams, and each fighter belongs exactly one team. For each fight, the Great Masters of Meereen choose two teams, $x$ and $...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> fightingPits(int k, List<List<Integer>> fighters, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npu...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class Solution {\n\n static class Team {\n int sum = 0;\n final List<Integer> p = new ArrayList<>();\n\n void add(int power) {\n p.add(power);\n sum += power;\n }\n...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int K = 500;\n\n\tint[] sz;\n\tList<Integer>[] teamsLst;\n\tint[][] teams;\n\n\tHashMap<Long, int[][]> map = new HashMap<>();\n\n\tint k;\n\n\t...
{ "class_name": null, "func_sign": [ "fightingPits(k, fighters, queries)" ], "solution": "from collections import defaultdict\n\ndef readints():\n return [int(x) for x in input().strip().split()]\n\n\nclass Team():\n def __init__(self, id, strengths):\n self.id = id\n self.strengths = so...
eJydVctqHTEM7SKLfoaYdShjW/IjH9FdodAJXbR30c00ixsolEA+Iv3fSsdmuPO6ndvcgG3ZPkeWjjSvd38+vX+Hv88fdfLld/djfHo+dw/URdLfMOYYiIcxciA/jC46MzqfyA1jkmLGlM3myeEEuYi1I3bFTjlq56YTnns70d1Td/r1dPp2Pn3/+vP53Ijtim6+3NOFN4ESCSCGEZ4whQnRk6+rYNtz4z6Jngmg8iu2qEjKxgIIG4yRMeTkzBiyLSKnyoyDjtrmcj1NdrzxW05we07qweeirTj3GLiFNni+grtANLfsBZFxuT5hCheG...
null
8,947
Components in a graph
There are $2 \times N$ nodes in an undirected graph, and a number of edges connecting some nodes. In each edge, the first value will be between $1$ and $N$, inclusive. The second node will be between $N+1$ and $2 \times N$, inclusive. Given a list of edges, determine the size of the smallest and largest connected co...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> componentsInGraph(List<List<Integer>> gb)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n // Each it...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n Scanner scanner = new Scanner(System.in);\n int n = ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n Set<Node> groups = new HashSet<>(n / 2);\n Node[] nodes = new Node[n * 2];\n for (int...
{ "class_name": null, "func_sign": [ "componentsInGraph(gb)" ], "solution": "class UF:\n def __init__(self, size):\n self.parent = [i for i in range(size + 1)]\n self.size = [1] * (size + 1)\n \n def _parent(self, a):\n while self.parent[a] != a:\n self.parent[a]...
eJzsvb2ubruOntlBd+C7mNhxBYPk+PWVNOACHNgncFKu4BRgoGDAl97iS43BZ+6DU6hKG0rW+taa3+T4kfSKpB5R/+f//n//9T/9P//Xf/nXP/7HP/3zv/z1j//888f+j/9kP/c//pP/nPz0xz/8/PGX//XPf/lvf/3Lf/+v//Nf/jq/7T/+x//+hx/8vudvxfzj3/1b9ozfsB/f9It55b3+Mf96fvyof8X3r7u+OH7Lxl/nj+e/7veL+bOjfrT9MmX1jfpRX+XfuluLP92uLvxzjl+N+NnHKxvXu8abGv837MT5sz95f5d//1dfGBff...
null