question_id
int64
41
56.8k
question_title
stringlengths
5
37
question_content
stringlengths
206
4.02k
dataset
stringclasses
1 value
difficulty
stringclasses
3 values
java
dict
java15
dict
java8
dict
python
dict
test_cases
stringlengths
28
2.49M
max_retries
float64
1
3
⌀
63
String Similarity
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3. Calculate the sum of similarities of a string S with each of it's suffixes....
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int stringSimilarity(String s)" ], "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-- > 0) {\n\t\t\t...
{ "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.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n static class SuffixArray {\n private char str[];\n private int MAX_LOG = 30;\n private int n, nr0[], nr1[], rank[][], index[], step, cnt;\n\n private int M;\n private int minusOneHea...
{ "class_name": null, "func_sign": [ "stringSimilarity(s)" ], "solution": "# Z Algorithm\n# Followed demo from:\n# http://www.utdallas.edu/~besp/demo/John2010/z-algorithm.htm\n# to implement\n\nif __name__ == '__main__':\n N = int(input())\n \n for line in range(N):\n string = input()\n ...
eJzsfMmuJMt1pBba6Cv6odZckCJakPglAroAwed5np0Q0J/eFhfaNbTXwg3EIVlVNzPS/RwbIjzv//3Hf/f/65/+4f/8/ZeJefRff/vj119+xxBTLq+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sorr7zyyiuvvPLKK6+88sor...
null
1,031
Pseudo-Isomorphic Substrings
Two strings A and B, consisting of small English alphabet letters are called pseudo-isomorphic if - Their lengths are equal - For every pair (i,j), where 1 <= i < j <= |A|, B[i] = B[j], iff A[i] = A[j] - For every pair (i,j), where 1 <= i < j <= |A|, B[i] != B[j] iff A[i] != A[j] Naturally, we use 1-indexation in ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> pseudoIsomorphicSubstrings(String s)" ], "script_name": "Solution", "solution": "/* HackerRank Template v0.21 by Sergey Esipenko\n * \n * v0.21\n * - fixed RuntimeError\n * */\n\nimport java.io.*;\nimport java.math.*;\nimport java.ut...
{ "solution": "import java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n \npublic class PseudoIsomorphicSubstrings {\n \n public static class ST {\n \n public static class Node {\n private final int valuesFromRootCount;\n private final Map<Integer, Edge> edges;\n ...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Locale;\nimport ja...
{ "class_name": null, "func_sign": [ "pseudoIsomorphicSubstrings(s)" ], "solution": "s = input()\n\nprevs = dict()\na = []\nfor i in range(len(s)):\n if s[i] in prevs:\n a.append(i - prevs[s[i]])\n else:\n a.append(i + 1)\n prevs[s[i]] = i\n\nclass Node:\n def __init__(self, **d):\...
eJy8fcnOw0rTFgtugt2vb83Cc3dzJUgcCcWZ7MSJEyex4yAk7oZr4O54Br+IJSvO0Tmp127bPVTXXNX/49//5//1P//Dv/sv/+1f/f3xef/rP/3bv3bt/4d///Uf/+1fx+/juH8fD/91/Ly3b+f/3It/7uU/9+qfe/3PvfnnHv65x3/u6Z97nuE/3M/RIEeLHE1ytMnRKEerHM1ytCvQruB70K5AuwLtCrQr0K5AuwLtCrQr0a5Eu5IfRLsS7Uq0K9GuRLsS7Uq0q9CuQrsK7Sr2DO0qtKvQrkK7Cu0qtKvRrka7Gu1qtKs5BLSr0a5G...
null
33,387
KnightL on a Chessboard
$KnightL$ is a chess piece that moves in an `L` shape. We define the possible moves of $KnightL(a, b)$ as any movement from some position $(x_1, y_1)$ to some $(x_2, y_2)$ satisfying either of the following: - $x_2 = x_1 \pm a$ and $y_2 = y_1 \pm b$, or - $x_2 = x_1 \pm b$ and $y_2 = y_1 \pm a$ Note that $(a, b)$...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<List<Integer>> knightlOnAChessboard(int n)" ], "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": "DNE", "template": "class Result {\n\n /*\n * Complete the 'knightlOnAChessboard' function below.\n *\n * The function is expected to return a 2D_INTEGER_ARRAY.\n * The function accepts INTEGER n as parameter.\n */\n\n public static List<List<Integer>> knightlOnAChessboard(in...
{ "solution": "\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n private final Scanner in;\n private final PrintStream out = System.out;\n\n public static void main(String[] args) throws Exception {\n Solution solution = null;\n tr...
{ "class_name": null, "func_sign": [ "knightlOnAChessboard(n)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn = int(input().strip())\n# your code goes here\nA=[]\nfor a in range(1,n):\n B=[]\n for b in range(1,n):\n P={(0,0)}\n c=0\n f=True\n V=set()\n while f:\...
eJztWs2O5DQQ5sCDtOa8QXHZcdI8CRIDHGAOXIY97EpICImHgPfFVV+V4yR2fmaEEKi3s5m04ypXlevX1X98+dcLfSH/vvk+PXz729PPrx8/f3r6+vZEw/Pr04fb08uvH19+/PTy0w+/fP5kr8LNxZsjvqb0ifK1T08hfSZ5E2/U31y40cRvfEyTQvp2C9Pt+XUFzfc0lF4T3xgFL0F8j3xLqPgut8DwBXDE8kFpCLyo00FdRx7sb7oEgRJOuMlyCTw/6gr5kebHdD2/ZvDOCd+yZHoGgp75Tt+oBy8yrbwYAWifRGTT4hkfKp5ZatGW...
null
14,104
Short Palindrome
Consider a string, $s$, of $n$ lowercase English letters where each character, $s_i$ ($0 \le i \lt n)$, denotes the letter at index $i$ in $s$. We define an $(a, b, c, d)$ palindromic tuple of $s$ to be a sequence of indices in $s$ satisfying the following criteria: * $s_a = s_d$, meaning the characters located at ind...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int shortPalindrome(String s)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n\n\tpublic static final int MOD = 1000000000 + 7;\n\n public static void main(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.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": [ "shortPalindrome(s)" ], "solution": "mod = 10**9 + 7\n\ndef sum_multi(A,B):\n return A[0]*B[0] + A[1]*B[1] + A[2]*B[2] + A[3]*B[3] + A[4]*B[4] + A[5]*B[5] + A[6]*B[6] + A[7]*B[7] + A[8]*B[8] + A[9]*B[9] + A[10]*B[10] + A[11]*B[11] + A[12]*B[12] + A[13]*B[13] + A[14]*B...
eJwcnEmy5FoRRBkwZBFYLYOVYMYobt/3PRM2xEZYFa40mvq/Xr5M6UaE+3HpKv/z13/+779/+8u//v3HpjLHn3/8/Q8rZoRsbr5lZ3F4TEpek8SYfV+r5duqXiqHuRH2znwur00ON3nFn9PMlOq0457Mpc5kkC28V7xcVdXeYg06eC1nLcPawLOTJj9mqMj4wlrbNh4vF80OE1a/SdqX19E6tb7lsjF713O5ZqkWQrnzqclT8ZW3O4zaW4Y1WgzihRvbbaF2nWRvlcs6SAmauyzN6E0z16lnTJFmKZ7HWqbF24ceZjWjcudI6FnfNnHr...
null
13,331
Beautiful Quadruples
We call an quadruple of positive integers, $(W, X, Y, Z)$, *beautiful* if the following condition is true: $$W \oplus X \oplus Y \oplus Z \neq 0$$ **Note:** $\oplus$ is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operator. Given $A$, $B$, $C$, and $D$, count the number of *beautiful* quadr...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static int beautifulQuadruples(int a, int b, int c, int d)" ], "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...
null
{ "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 D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "beautifulQuadruples(a, b, c, d)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nA,B,C,D = input().strip().split(' ')\ntemp = [int(A),int(B),int(C),int(D)]\ntemp.sort()\nA,B,C,D=temp\n\ntot=[0]*4100\n\ntree=[([0]*3100).copy() for i in range(4100)]\ncnt=[([0]*3100).cop...
eJydlE1q3EAQhbNITuFNobUx9f/jkxgck0Uyi2wmXowhEAw+hH1fl5yBcXqiJkQtNb3Q+/p1vZKePr4snz68XTcXvbj9tXzf3z8clmtYKDBAGYhZgYzw8365hGX383739bD79uXHw+H4plBqlDmGL4+X8I4R1VJqDgsVUGRsQtxNJdIrTAaKu7QBLjBcIaGbEEpJQ9X2wgOkXWDbQAG2XgXZJqXQlDHVi2ygsKEDsztEP6Q28YLVDI3eTXHASCgwRRM8q13VpC7KicxV5eORGN3AU6ArD6mybUUwUsi0mEZGqcEaTkTXVnGScoQkqplp...
null
3,470
Absolute Element Sums
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $x$, and is performed as follows: 1. Add $x$ to each element of the array, permanently modifying it for any future queries. 2. Find the absolute value of each element in the array and print the sum of the absolute...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> playingWithNumbers(List<Integer> arr, List<Integer> queries)" ], "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.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\";\n...
{ "solution": "import java.io.*;\nimport java.util.*;\n\n/**\n * Created by witalia on 12.12.14.\n */\npublic class Solution {\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\...
{ "class_name": null, "func_sign": [ "playingWithNumbers(arr, queries)" ], "solution": "from collections import Counter\n\ndef q(arr, queries):\n positive_n = [el for el in arr if el >= 0]\n negative_n = [el for el in arr if el < 0]\n pos_size = len(positive_n)\n neg_size = len(negative_n)\n ...
eJzsvcuubDuynueG3sHdiWqfBAbvpJ7DDQMqQA2pGuqUTqMOIEAwYL+54/9+5m3OXHvtOjbsDneh1owcOQYHGQzG5Y8g8//8D//7//W//a//y3/6n3/5b3//13/7x1/+49df8hX//fXvN/394p9DHvKQhzzkIQ95yEMe8pCHPOQhD3nIQx7ykIc85CEPechDHvKQhzzkIQ95yEMe8pCHPOQhD3nIQx7ykIc85CEPechDHvKQhzzkIQ95yEMe8pCHPOQhD3nIQx7ykIc85CEPechDHvKQhzzkIQ95yEMe8pCHPOQhD3nIQx7ykIc85CEP...
null
774
Subset Component
You are given an array with $n$ $64$-bit integers: $d[0], d[1], ..., d[n - 1]$. BIT(x, i) = (x >> i) & 1, where $B(x, i)$ is the $i^{th}$ lower bit of $x$ in binary form. If we regard every bit as a vertex of a graph G, there is an undirected edge between vertices $i$ and $j$ if there is a value $k$ such that BIT(d[k...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int findConnectedComponents(List<Long> d)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.BigInteger;\n\npublic class Solution {\n\n static int col = 0;\n static long[] a;\n\n public static void solve(Input in...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n private static int findConnectedComponents(long[] nums) {\n Result result = new Result();\n ...
{ "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 Solution{\n\tstatic InputStream is;\n\tsta...
{ "class_name": null, "func_sign": [ "findConnectedComponents(d)" ], "solution": "from functools import reduce\nfrom operator import or_\n\ndef get_integers():\n from sys import stdin\n return int(stdin.readline().strip()), sorted(map(int, stdin.readline().strip().split()))\n\ndef dec(s):\n return ...
eJyVls1uHUUQhVmw5CFaXkeo/rs7T4JEEAvIgo1hkUhICImHgPflq7GdXDMeK/hK1r0z1d1Vp8451X99/c/bb746/r5zvnz/x90v9799/HD3dtxpvLvPuSXWthi23SXnnEMlUnm4bXiKxdbpQ1WlZHqtYTJlL5XcQ5PXe2rKMJaJz+Bh8T/Cdr9fhKWpsquY+iJ4qM1gz60+dk5xTrKhM+eaZanv7u/ejLv3v//2/qcP73/+8dePHx4TzloRk9d/vhk3deS7e022JznhcDbJCM5LKeqSIZcb6jY5bedsN/hcp6F2WqSbVR6mewIbaZAN...
null
5,595
Dijkstra: Shortest Reach 2
Given an undirected graph and a starting node, determine the lengths of the shortest paths from the starting node to all other nodes in the graph. If a node is unreachable, its distance is -1. Nodes will be numbered consecutively from $1$ to $n$, and edges will have varying distances or lengths. For example, consid...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> shortestReach(int n, List<List<Integer>> edges, int s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Node implements Comp...
{ "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.ArrayList;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\npublic class Solution {\n\tstatic class Pair {\n\t\tint vertex = 0;\n\t\tint dist = Integer.MAX_VALUE;\n\n\t\n\t}\n\n\tpublic static void main(String[] ar...
{ "class_name": null, "func_sign": [ "shortestReach(n, edges, s)" ], "solution": "import heapq\n\ndef find(V,N,S):\n dist=[-1 for x in range(N)]\n visited=[False for x in range(N)]\n Q=[(0,S)] #use a priority queue\n dist[S]=0\n while Q:\n mindist,minv=heapq.heappop(Q)\n if not ...
eJy0vcuqbVuXrWXi+B6DSJ+A3nq7+ySCP5jQg5gJTZwDggg+uvX7Sp9/CGJOg4jYe+015xi9t0u9lFpqqf/nf/hv/+v/6T/8V//d//4v//O//a//5T//y3/z+5fxj3/r/df/8W/v/L3n18fb2z/+bf1a+913jfuPf2u/89vrGbt+pn56999860fa/o3xG3us5S/Xf7/9nPqbsX7r+Y331r+fXxu/O9f1t3+jPvX0e+rX72/t39xz1He386tfas9u9X3vb9UHjOd969EOP7X789Rf7F/fv3bPnvUdv/m7qz/1QKv9dj3jrP+pX6iPbfX1...
null
28,277
Real Estate Broker
You are a real estate broker in ancient Knossos. You have $m$ unsold houses, and each house $j$ has an area, $x_j$, and a minimum price, $y_j$. You also have $n$ clients, and each client $i$ wants a house with an area greater than $a_i$ and a price less than or equal to $p_i$. Each client can buy *at most* one house, ...
hackerrank
Hard
{ "class_name": null, "func_sign": [ "static int realEstateBroker(int[][] clients, int[][] houses)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\npublic class e {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out ...
null
{ "solution": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\n/*\nbr = new BufferedReader(new FileReader(\"input.txt\"));\npw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nbr = new Buf...
{ "class_name": null, "func_sign": [ "realEstateBroker(clients, houses)" ], "solution": "# Enter your code here. Read input from STDIN. Print output to STDOUT\nimport sys\n\ndef kuhn(v):\n global house, used, buyers\n if used[v]: \n return False\n used[v] = True\n for buyer in buyers[v]:\...
eJzsvcuqLUuapacCPYgT7WrY/aInEShAjapEqBOqRhYUCIGeSs+n8X02dyIyiCIL1FBDGeTZ56w9l093c7P/Osb4/8///n/8X/6vf/ff/U//+1/+17/9p//8z3/5H76/tG/+9W93t9PaLeerfZV1bs0PZ+u1lL2/1XefZY7117+N0tu69+xvtLturev89W911dvXXPVb+4y+271//dtqu87Zyv72ab31kQ+Oecus8+SD8/bRZs0Hey65W1/fWeuU1Wo++Jd///3ln/7Lf/qn//DP//Qf/+f/7T//8+9ea/7m//j33//j7mvh9uuXG/3r...
null
22,036
Demanding Money
Killgrave wants to use his mind control powers to get money from the Justice League superheroes living in $N$ houses in Happy Harbor that are numbered sequentially from $1$ to $N$. There are $M$ roads, and each road $j$ connects two different houses, $A_j$ and $B_j$. Each superhero house $i$ (where $1 \le i \le N$) has...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> demandingMoney(List<Integer> money, List<List<Integer>> roads)" ], "script_name": "Solution", "solution": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashMap;\nimport ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n /*\n * Complete the demandingMoney function below.\n */\n private static long maxMoney = Integer.MIN_VALUE;\n private static Map<Long, Long> soluti...
{ "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 D2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\...
{ "class_name": null, "func_sign": [ "demandingMoney(money, roads)" ], "solution": "\ndef solve(C,G) :\n minLost = {}\n def getMinLost(housesToVisit) :\n# print(\"getMinLost %s :\" % str(housesToVisit))\n if not housesToVisit :\n return 0,1\n \n key = frozenset(h...
eJyNW0uObEkNZcBCQm/cQjccf1aCRCEG0AMmjx50S0ioJRYBK2LGqgj7HPvem596j5dkZmVVxsdhHx8fR//rt//53/qN/e8P/91v/vjPL3/7+tMvP3/5ffoiI7WPr2WmOpLUVGoaklpLcugnuen7UtLIaR5JJI2Zxn5TUm1p1bRKyjn1oe/b/m1NvSbJH19XymuPm6R/fK0pi77Px8fXnGTP9+WH9OXHf/z0419+/vGvf/77Lz9zMVnmTPnLrz+kywqnfa/k1Hra62y2wr0w2UMNHXbqU9Whpz7td5LKx9eehv7Y9cem7/ZnQ//k3eT9...
null
14,770
Find the Path
You are given a table, $a$, with $n$ rows and $m$ columns. The top-left corner of the table has coordinates $(0,0)$, and the bottom-right corner has coordinates $(n-1, m-1)$. The $i^{th}$ cell contains integer $a_{i,j}$. A path in the table is a sequence of cells $(r_1,c_1), (r_2,c_2), \ldots, (r_k,c_k)$ such that for...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> shortestPath(List<List<Integer>> a, List<List<Integer>> queries)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nim...
{ "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 C {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solve(...
{ "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 C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "shortestPath(a, queries)" ], "solution": "import sys\nfrom heapq import *\n\nnum_rows = 0\nnum_cols = 0\nnum_queries = 0\ntable = []\nquery_dict = {}\nquery_results = []\nshortest_paths = []\nvisited = []\n\n\ndef read_input():\n global num_rows, num_cols, num_querie...
eJx8ncuuNEuSlRkw4S1CNe6B3y88CRJHYgA1YFL0oFtCQi3xvrwEtr5lkZlVRaEj/WfvnZERHu7mdnNby/73v/9P//Z//sO/+8//60///S///K//8qf/+PypPvWPv9S92x9/6X/8pTz89//64U//9Pzpz//zn//8X//lz//tv/yPf/2X9/t89fvvn/7tn56f249n/vGXtu962hrnaa23p+05nlpGPK+OGp+c0p969oxP2o1/ajyuldbj8hGXn7ufNu5T14yxtrr1wdKFtz3ncIMV94pv1Wc8TW9U4n/9iSfEneOHoY9qvEh/Pxr6gQ/1...
null
32,644
Organizing Containers of Balls
David has several containers, each with a number of balls in it. He has just enough containers to sort each type of ball he has into its own container. David wants to sort the balls using his sort method. David wants to perform some number of swap operations such that: * Each container contains only balls of the sa...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String organizingContainers(List<List<Integer>> container)" ], "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": "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": [ "organizingContainers(container)" ], "solution": "#!/bin/python3\n\nimport sys\nfrom collections import Counter\n\n\nq = int(input().strip())\nfor a0 in range(q):\n n = int(input().strip())\n M = []\n for M_i in range(n):\n M_t = [int(M_temp) for M_temp in...
eJztnNuOG0UQhrngQVq+jlAf58Ab5I5LJBaBgBWKlGxWSiIhISQeAt6Ch+T/u8f2jE87tudQveqtrHdm3Kev66+qdi7899f//v7fV/Hn+59x8cOfm3dPz18+b75VG//wZB6e7MMTLrxyyihca1xYhScB954XeKyCCrGlqytlDXu1rbKhwRN2gbGd6f3ZvFGbxz+eH3/9/PjbTx+/fO7m/O7jp0/vfnn/+PD09sPzyetti81fb9TRYjl+nENzlu7VpPn3j9JfXHVr6x6ZYcv9ALuWZtdyx7S76U/U65jap5bDyfRwzEF3c9i95ZY6FYJy...
null
1,331
Service Lane
A driver is driving on the freeway. The check engine light of his vehicle is on, and the driver wants to get service immediately. Luckily, a service lane runs parallel to the highway. It varies in width along its length. ![Paradise Highway](https://hr-testcases.s3.amazonaws.com/1331) You will be given an array of wid...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> serviceLane(int n, List<List<Integer>> cases)" ], "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 publ...
{ "solution": "import java.util.*;\n\npublic class ServiceLane {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int t = sc.nextInt();\n int[] arr = new int[n];\n for(int i = 0; i < n; i++) {\n arr[i] = sc.nex...
{ "solution": "import java.util.Scanner;\nimport java.util.ArrayList;\n\npublic class Solution {\n public static void main (String[] args) {\n Scanner stdin = new Scanner(System.in);\n int freewayLength = stdin.nextInt();\n int numTestCases = stdin.nextInt();\n ArrayList<Integer> freewa...
{ "class_name": null, "func_sign": [ "serviceLane(n, cases)" ], "solution": "import sys\n\nN, T = [int( item ) for item in next( sys.stdin ).split()]\nW = [int( item ) for item in next( sys.stdin ).split()]\nfor line in sys.stdin:\n i, j = [int( item ) for item in line.split()]\n print( min( W[i:j+1] ...
eJzsu8tuJVu6neeG4ecI7PZpcM651iKprl/CgAtQQ6qGOlunUQcQIAjQC/qdHMEscnzfmJF1BLthwz5g7UwyYl7+y7j8ZCX/+//8v/2v/8f/8j/97//1j//05z//y9/++HfHH58fH8fH51/+HMc65jHO/9b5Mb4+Gz9fr6+36+9P18+qX5/Nn53fu8bXu+/V6+9/53meLN05/n7S+LnVe7/Xf0cx//7V/Nm7dML3HevnxPFz2vrZ3VkmltzxnVn2rrp7anfOzd6hPbk/kX6vT01Si4ksGBlP6c+ZYyrAr7/7k6i+s134ej9n/OxZWMtq...
null
13,512
Ema's Supercomputer
Ema built a quantum computer! Help her test its capabilities by solving the problem below. ------ Given a grid of size $n \times m$, each cell in the grid is either $good$ or $bad$. A *valid* plus is defined here as the crossing of two segments (horizontal and vertical) of equal lengths. These lengths must be odd, a...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int twoPluses(List<String> grid)" ], "script_name": "Solution", "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\n p...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static int twoPluses(String[] grid) {\n int n = grid.length;\n int m = grid[0].length();\n ...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class ProblemC {\n BufferedReader rd;\n\n ProblemC() throws IOException {\n rd = new BufferedReader(new InputStreamReader(System.in));\n compute();\n ...
{ "class_name": null, "func_sign": [ "twoPluses(grid)" ], "solution": "\ndef solve(y, x, y1, x1, l):\n i = 0\n s = True\n t = True\n ans = []\n while True:\n if s:\n a = l[y + i][x] if y + i < len(l) else \"B\"\n b = l[y - i][x] if 0 <= y - i else \"B\"\n ...
eJzlVr1OwzAQZmDhLazMFWrSpAHGW+4VkAAxQAeW0iGVkBASDwEvwsbbEd+f7aRuk5lEdS7n+/N3n51+nn//XpzRdfvTC3fvxct2t++KG1eUlVvdbwHAD9gP6CXEROclpIFmIRmKhSs2b7vNU7d5fnzddxq4+Fi4OFHjWorsLx/OPzkDsNBnoMReT2WwjRjLlDfhMkErkjjsJgFB45AAkQ1NZWqumkHRjSuXFIjToMhocliPiIBmD0cy1cNMfR98KoJAkEGU5aLhBqrndMMSMKyUEQPxTWwUQ1sJg88zASXSZ8q/OtDdmiNyt0wejdY/...
null
16,411
Larry's Array
Larry has been given a permutation of a sequence of natural numbers incrementing from $1$ as an array. He must determine whether the array can be sorted using the following operation any number of times: - Choose any $3$ consecutive indices and rotate their elements in such a way that $A B C\ \rightarrow B C A\ \ri...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String larrysArray(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 static int[] aux;\n \n ...
{ "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": [ "larrysArray(A)" ], "solution": "import copy\n\nt = int(input())\n\nfor z in range(t):\n input()\n realList = [int(n) for n in input().split()]\n sortedList = copy.copy(realList)\n sortedList.sort()\n listLen = len(sortedList)\n for i in range(listLen -...
eJztnLvOZklyXWXoQQ7aHggn75n06ZIGHQpqSYY0Bp0WjSFAgCDAh5Deix5fR7FW5Fdd3dNVwzHkaTDVdfm/S57MyIgdO3bEv/zH//Nv/+0/+L+//df4w3/5px/+7qe//4c//PAXzw/lx59a/P8pT/3xpx9+9/zw+3/8+9//jz/8/n/+9//1D3+4r/nPf/k38bN//t3zy/eV943/PPVpT3/GM5/17Oc85X1KeUp9Snxqf8p4ynzKesp+ynnq+9R4T31qe2p/6njqfOp66n7qedr7tPK0+Mj2tP608bT5tPW0/bTz9Pfp5en16fGN/enj...
null
33,299
HackerRank in a String!
We say that a string contains the word `hackerrank` if a [subsequence](https://en.wikipedia.org/wiki/Subsequence) of its characters spell the word `hackerrank`. Remeber that a subsequence maintains the order of characters selected from a sequence. More formally, let $p[0], p[1], \cdots, p[9]$ be the respective ind...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String hackerrankInString(String s)" ], "script_name": "Solution", "solution": "import java.util.Scanner;\n\npublic class LCS {\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tint q ...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'hackerrankInString' function below.\n *\n * The function is expected to return a STRING.\n * The function accepts STRING s as parameter.\n */\n\n public static String hackerrankInString(String s) {\n // Write your...
{ "solution": "import java.util.*;\nimport java.io.*;\npublic class Main {\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int q = Integer.parseInt(br.readLine());\n for (int test = 1; test <= q; test++) ...
{ "class_name": null, "func_sign": [ "hackerrankInString(s)" ], "solution": "#!/bin/python3\n\nimport sys\nimport re\n\nq = int(input().strip())\nfor a0 in range(q):\n s = input().strip()\n \n pattern = \".*h.*a.*c.*k.*e.*r.*r.*a.*n.*k.*\"\n m = re.search(pattern, s)\n if m is not None:\n ...
eJyMvMuu7Li2pncM+EEOdrsaokjq4n51yw13bHgCBsWreL9IoijDgF/Cz2c/h1secVAFuKrOMZzYSGSuvdaMCGqM//++CEX+7//t//Hf/F//9C9//Y//9//5T//0P/+v/zhjvq9//Hf//A9E/6Ln93Esx3rSO79jHm+9+EXGIPq+rDFuLy9ejGjh/p6UlnO/c/gqO4UfbEtJzqc9wkdxKqnyc+euye84qvIOawl/kMXzkk/qvGMarev32hU/1hSOTbka/dvDPBcx1R2taHqvnoQ+mMTbodrd8js7ktybgg2Ob9HGx/LNvzZx8bznIal8...
null
360
Quicksort 1 - Partition
The previous challenges covered [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort), which is a simple and intuitive sorting algorithm with a running time of $O(n^2)$. In these next few challenges, we're covering a *divide-and-conquer* algorithm called [Quicksort](https://en.wikipedia.org/wiki/Quicksort) (al...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> quickSort(List<Integer> arr)" ], "script_name": "Solution", "solution": "\n\n/* Head ends here */\nimport java.util.*;\npublic class Solution {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\...
{ "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.ArrayList;\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 Buffe...
{ "class_name": null, "func_sign": [ "quickSort(arr)" ], "solution": "size = int(input())\narray = input().split(\" \")\narr = ['None'] * size\nfor i in range(size):\n arr[i] = int(array[i])\np = arr[0]\nless = [ ]\nmore = [ ]\nfor i in range(size):\n if arr[i] < p:\n less.append(arr[i])\n e...
eJztnUuOJFmSXTngQgw5biNM/0+5EgJMgoNmDchBsgfVAAGiAS6CXBu3QznnPrWfm3t4fKoyspmNrkiPcPuoPn1P5MqVKyL/69/+n//2f/+N//cf/rF++I//85f/+ts//fNff/n3p1+Wbfz1t3ObhtM0jqdtWE7n+u8+7afzOq+nNp3Ow+VyqX+d+aNeN6zr6byM9cLGT+Ow1Uta/bLxsn0YT+dt2U7LNtTL1u207/XDtvOqpdUL6lXjMtcP83Qapvk0z3zSfFr25dT4y3qZ6t310esw8bL1NC/1yUu9dr3sp72+er3U9V4aX1zX2Lig...
null
33,549
Separate the Numbers
A numeric string, $s$, is *beautiful* if it can be split into a sequence of two or more positive integers, $a[1],a[2], \ldots ,a[n]$, satisfying the following conditions: 1. $a[i]-a[i-1]=1$ for any $1 < i \le n$ (i.e., each element in the sequence is $1$ more than the previous element). 2. *No $a[i]$ contains a leadin...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static void separateNumbers(String s)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * @author Aydar Gizatullin a.k.a. lightning95, aydar.gizatullin@gmail.com\n * Created on 17.02.17.\n */\n...
{ "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": "\nimport java.util.*;\nimport java.io.*;\n\npublic class University_Codesprint_2_B {\n\n\tstatic BufferedReader br;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\t\n\tpublic static void main (String[] args) throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in))...
{ "class_name": null, "func_sign": [ "separateNumbers(s)" ], "solution": "for _ in range(int(input())):\n s = input().strip()\n n = len(s)\n x = ''\n for i in s[:-1]:\n x += i\n y = int(x)\n z = ''\n while len(z) < n:\n z += str(y)\n y += 1\n ...
eJytlr1unFUQhilouAtr6wjN35mZQ08LBRSgLKIAF2mWFImEhCJxEXC/PPMZJQivnRhi2f6Od8+cM+/PvOvfP/3z+WefHF/ffcvi+W+nF5eXr1+dvrg51fkiLktky7ZekckrGUtWZ7auZWo7sttk+aoM3+dL72oR7dKp1PPFIndQLO6amxO0RNi3kgKR4oDc4rpCyruVV3T1+eIuWy3cM72KN8+X07Ob0+2vL29/enX784+/vH71d59ffX2+XP85vXl28w9AnLprV+XKEJ0utwCD5srPlzAaMm7lVxqP5A9JlkphxQasLRDRsUtJ+k7Z...
null
6,568
Funny String
In this challenge, you will determine whether a string is *funny* or not. To determine whether a string is funny, create a copy of the string in reverse e.g. $abc \rightarrow cba$. Iterating through each string, compare the absolute difference in the [ascii](https://en.wikipedia.org/wiki/ASCII) values of the characte...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String funnyString(String s)" ], "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.InputMism...
{ "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 public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int lines = sc.nextInt();\n sc.nextLine();\n outer:\n for(int i = 0; i < lines; i++) {\n String s = sc...
{ "class_name": null, "func_sign": [ "funnyString(s)" ], "solution": "def isFunny(s):\n for i in range(1, len(s)):\n if abs(s[i] - s[i-1]) != abs(s[-i-1] - s[-i]): return False\n return True\n \n\nif __name__ == \"__main__\":\n num_cases = int(input());\n for case in range(num_cases):\...
eJztvNeOxNyaHeYLP8jg3PhGEJiD75hzznQbBnPOmYYAP4R1rVc1f2NsCEfWaPIZ+fS30OhifdVVmzusb63qTf4f/+N//Pf/6X/4vyP8n74H/8v//qdmnI/9T//z3/wJ/BmPuzjrObuHIuvqcm2q9E7yYty7657b4V3OLi/7ZV2Xqt7TcmjaedzXujreuezrcxvSLW+v/tib65rbrZ+ucbymfmvn62r2o7/afEuH7az7cn6Pql73cW6boUz3uvrjXfsy787lHdr5vrp9LPLkTqtmLesuK4Y7m+uzuI+f8U//7m/+VNxzke1F/r9Nx/63...
null
4,099
Alternating Characters
You are given a string containing characters $A$ and $B$ only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. Your task is to find the minimum number of required deletions. **Example** $s = ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int alternatingCharacters(String s)" ], "script_name": "Solution", "solution": "import java.util.Scanner;\npublic class Solution {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n...
{ "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.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\tString s...
{ "class_name": null, "func_sign": [ "alternatingCharacters(s)" ], "solution": "def f(s):\n return sum(1 for c1, c2 in zip(s, s[1:]) if c1 == c2)\n\nt = int(input())\nfor _ in range(t):\n print(f(input()))", "template": "#\n# Complete the 'alternatingCharacters' function below.\n#\n# The function is...
eJx0lD2yZUuTFREYCNbGCBBBihwFZjABlDYEkFCYHrPCur8Kd499qqveq3vP2Znxs5av/X///X/9f//lP/67//Z//ul//PP//N//65/+83/4p//03//5zb/8/dd/3r/8fP/y81//nfnHN/vjXx/8+fCPx/vhH3cmV//8Ojn2j4Lz8ss/Cr2h257e797bs2/P7iUq0sG/k1l2JCab2Wn/dODn/OPPP3qMi3QrvxiKWvOMgmor4ewCrPqm8k3KZ8rz7x8/Xt35c5uuqvfn+XfUaL139+JYqK2O0PtnPXFaTP3TLxNEyM8Qntbx1YOTa71/...
null
21,083
Highest Value Palindrome
Palindromes are strings that read the same from the left or right, for example <em>madam</em> or <em>0110</em>. You will be given a string representation of a number and a maximum number of changes you can make. Alter the string, one digit at a time, to create the string representation of the largest number possi...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String highestValuePalindrome(String s, int n, int k)" ], "script_name": "Solution", "solution": "import java.util.Scanner;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n\...
{ "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": "\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": [ "highestValuePalindrome(s, n, k)" ], "solution": "n, k = map(int, input().split())\ns = list(input())\n\nf = 0\nfor i in range(n // 2): f += s[i] != s[n - 1 - i]\n\nif f > k: print(-1)\nelse:\n for i in range(n // 2):\n if s[i] != s[n - 1 - i]:\n f -...
eJzs3cuqbtmW3XeB9SDBKcsw7xe9g+sGB7hgZUGVsAopEAiD31Ev5P77zxXGhPOkcBqBCnuTnIzYsdb3zcsYffTeemut/5//+n/+L//T//Cv/pf//Ld//8d/+I//+Ld/+9vf7t/W9fc/luPcj/f6/Y+//Zvf/vYP/+k//MP/9o//8O/+1//9P/7jz0+935+//R//5rf/x+/uv22//7Fex9//teuvv/L+dv7+x/ts5/pc7/PPfd+zPv/EN66/re+x3r//sa/7eS73uTzXsmzvdqzX+m7X/rznsvuBf/5O/t6fv37f/dt7Xdtc87PN83m2...
null
17,338
Bear and Steady Gene
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\text{A}$, $\text{C}$, $\text{T}$, and $\text{G}$. It is considered to be *steady* if each of the four letters occurs exactly $\frac{n}{4}$ times. For example, $\text{GACT}$ and $\text{AAGTGCCT}$ are both steady g...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int steadyGene(String gene)" ], "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[] arg...
{ "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 B {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\t\n\tstatic final String GENES = \"ACGT\";\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tString s = nextToken();\n\t\tint[] a = new int[n...
{ "class_name": null, "func_sign": [ "steadyGene(gene)" ], "solution": "\ndef solve(S,n) :\n count = {}\n for c in S :\n count[c] = count.get(c,0) + 1\n\n for c in count :\n if count[c] > n//4 :\n count[c] = count[c]-n//4\n else :\n count[c] = 0\n\n if ...
eJykmrGutVtyVQnIeAmrYwfYEkYgEZQqqBeoAAlLBNABSeOgLSEhJN6W1+DsGmOufVqIqNvu2/f+95y9v2+tWlVzjrn+97/8j//h//yrf/Gf/ucf/tuf/umf//yHf/83f/j7f/MP//in+iv/03/lf+av/M/+lf/5xz/94W//5g9//B//9Mf/8uc//tf//N//+c+uzr/++Tf/62//5td6/d3f/yxX7/vq/++v/sP/+6v/7t/+3d/9/HH3rVjNVs3U/Hza5xP75x9//my7fv778381n//r+vnBz1/75y/7+ffzWa/++d/5/PbnH/bzfz9/...
null
66
Find Strings
A substring is defined as a contiguous sequence of one or more characters in the string. More information on substrings can be found [here](http://en.wikipedia.org/wiki/Substring "Substring"). <br> You are given *n* strings w[1], w[2], ......, w[n]. Let S[i] denote the set of all distinct substrings of the string w[i...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<String> findStrings(List<String> w, List<Integer> queries)" ], "script_name": "Solution", "solution": "\nimport java.io.* ;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport static java.lang.Math.* ;\nimport static java.util.Arrays.*...
{ "solution": "import java.io.* ;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport static java.lang.Math.* ;\nimport static java.util.Arrays.* ;\n\npublic class Solution {\n public static void main(String[] args) {\n new Solution().solveProblem();\n out.close();\n }\n stati...
{ "solution": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class Solution \n{\n\tstatic int sa[],rank[],lcp[];\n\tpublic static void main(String args[])throws IOException\n\t{\n\t\tBufferedReader br=...
{ "class_name": null, "func_sign": [ "findStrings(w, queries)" ], "solution": "import sys\ndata = sys.stdin.readlines() \n\ndef get_suffixes(string):\n suffixes = set()\n string_len = len(string)\n for index in range(0, string_len):\n suffixes.add(string[index: string_len])\n r...
eJztfduO7DiWnQ34Qxr1PDDifvGbgXkZwPCjYcBpGLxJJEVSFCleRMOAP8I/5y/wb3hRWT0YdHfVTPdUd9U5qdh1spQKhcR9W2ttZWbE//53//X//r9/+2/+2//8QTmf1h/+w+9+ON8+nNW0xXmhrbk4EtZcMHWyha7WjlGo1ZZAFz5J49IkiCdxImkwLRmyljgyI7VcS+NLVWHwyigtnG5qyVxx73wcMxV0G9zgtbfJ22byMi2pNRU+nFLZzXab/LIZGhJfsoy0ri5LMSvf+LyOwg55C06weajRb3ktkys81JVOKo6OC7rYNjKXk2N1...
null
21,767
Gridland Metro
The city of Gridland is represented as an $n \times m$ matrix where the rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$. Gridland has a network of train tracks that always run in straight horizontal lines along a row. In other words, the start and end points of a train track are $(r, c1)...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int gridlandMetro(int n, int m, int k, List<List<Integer>> track)" ], "script_name": "Solution", "solution": "/*\n * Code Author: Akshay Miterani\n * DA-IICT\n */\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimpor...
{ "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": "\nimport 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 C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"...
{ "class_name": null, "func_sign": [ "gridlandMetro(n, m, k, track)" ], "solution": "from collections import defaultdict\n\nn, m, k = map(int, input().split())\n\ntracks = defaultdict(list)\nfor _ in range(k):\n row, c1, c2 = map(int, input().split())\n tracks[row].append((c1, -1))\n tracks[row].ap...
eJzsvUuuLTuuLWYDbsjCLb+C/h+3xIAP4IJ9C66kX+E+wIBhwN11L8wxBknF2nlPC5wnc0ux5pwRIVH8DFIS9f/8D//T/9v++//uf/6//u1//8d//W//8W//48+/1braTzvt7p86+1//uMcu7IP11z9G6T9t9Hb0/V//mHfYd7es8dc/2rDb+rTb/Ms+8GXdtdlT+rLP7XLGt7tPfrvK/esftY7zU5s9KL4+/eLrM/bC19PacFcv+eyJZ88y7cu2f87o2aazD+6cpR9roH2Jh+S3dTb0ZozZ/vrHqvVn4FHRnbnsy3G2Xd/Wfu6478ba...
null
27,771
Minimum Loss
Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss. **Example** $price = [20, 15, 8, 2, 12]$ Her minimum loss is incurred by purchasing in y...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int minimumLoss(List<Long> price)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\npublic class b {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new Pri...
{ "solution": "import java.util.*;\n\npublic class hello\n{\n public static void main(String []args)\n {\n Scanner sc=new Scanner(System.in);\n \n int x=sc.nextInt();\n long a[]=new long[x];\n \n HashMap <Long,Integer> map=new HashMap<Long,Integer>();\n \n ...
{ "solution": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\n/*\nbr = new BufferedReader(new FileReader(\"input.txt\"));\npw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nbr = new Buf...
{ "class_name": null, "func_sign": [ "minimumLoss(price)" ], "solution": "n=int(input())\n\nl = [int(item) for item in input().split()]\nl2 = l.copy()\nd={}\nfor i in range(len(l)):\n d[l[i]] = i\nl = sorted(l)\nm = float(\"inf\")\nfor i in range(len(l)-1):\n if d[l[i+1]] < d[l[i]] : m = min(m,l[i + 1...
eJx03c+Krd+yJmQb9ryJw2lXY/yZMyKGVyJYYENLsHOsRgmCCN6Cd+x63vlbBxtajcwPag4Oe7+xV2Y+X4yI/+u//u/+5//7v/mv/vv/41//l3/7z//bf/nX//Zf/vXz3vuP//Zda/2Lx3/583Q8taePp6+n8nQ9jaf952k7MU5sJ8aJ7cQ4sZ0YJ7YT48Rxop04TrQTx4l24jjRThwn2onrRDlxnSgnrhPlxHWinLhOlBMfJ75OfJz4OvFx4uvEx4mvEx8nvk58nfg48XXi48TXiY8TXyc+Tnyd+DhRTlwnyonrRDlxnSgnrhPlxHWi...
null
458
Missing Numbers
Given two arrays of integers, find which elements in the second array are missing from the first array. **Example** $arr = [7, 2, 5, 3, 5, 3]$ $brr = [7, 2, 5, 4, 6, 3, 5, 3]$ The $brr$ array is the orginal list. The numbers missing are $[4, 6]$. **Notes** * If a number occurs multiple times in the lists, ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> missingNumbers(List<Integer> arr, List<Integer> brr)" ], "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 ...
{ "solution": "import java.util.*;\npublic class hello\n{\n public static void main(String []args)\n {\n Scanner sc=new Scanner(System.in);\n \n int x=sc.nextInt();\n \n // HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();\n \n int f1[]=new int[10001];\...
{ "solution": "import java.util.*;\n\n/**\n * Created by Bruno on 05/08/2014.\n */\npublic class Solution {\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n\n //Construct A\n int n = scan.nextInt();\n Map<Integer, Integer> A = new HashMap<>(n);\n ...
{ "class_name": null, "func_sign": [ "missingNumbers(arr, brr)" ], "solution": "n = int(input())\nA = [int(i) for i in input().split()]\nm = int(input())\nB = [int(i) for i in input().split()]\nvals = {}\nfor i in A:\n if i not in vals:\n vals[i] = -1\n else:\n vals[i] -= 1\nfor i in B:\...
eJzsvcuO7TqyJNiD7v8InPEdiKKeNerPaKA3UIOqHNRk9x3kBQooFNDD/uxeorubGRmkQrEfJ09mBe65K1csSXz4w9zcSWr/v//7//V//n//x//2f/+PP/7b93//j7//8Z/e/ji289v39JbOt/n13/qW0tuyvq3HW97f9reU33J6e/39+t/1+un1+bq8pOu+1/fX9bRftyzndU96m68Pu7ZcD75azOf13+uvZX+b92jnLO28eng1vl7dv5pa8tXOq4n9+niNJ1+t5XL51dCars7KQF//+3p8TqVrG8Z63b2UIb9uuL6UgeUynHX19pPd...
null
1,629
Cut the Tree
There is an undirected tree where each vertex is numbered from $1$ to $n$, and each contains a data value. The *sum* of a tree is the sum of all its nodes' data values. If an edge is cut, two smaller trees are formed. The *difference* between two trees is the absolute value of the difference in their sums. Given ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int cutTheTree(List<Integer> data, List<List<Integer>> edges)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Ar...
{ "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.*;\n\npublic class Solution {\n static class TreeNode{\n int value;\n int number;\n ArrayList<TreeNode> children;\n public TreeNode(int value,int number){\n this.value = value;\n this.number = number;\n children = new Arra...
{ "class_name": null, "func_sign": [ "cutTheTree(data, edges)" ], "solution": "from collections import deque\n\nclass Node(object):\n def __init__(self,index,value):\n self.index = index\n self.value = value\n self.children = set()\n self.parent = None\n self.value_of_s...
eJzsncvKNUl2nj0wvo5NjXuQccg46EoMLtBAqoE8KPWgGwRCoKv1dTie5439dSPTMxtsMFLXF3/uzMjIiHVeb6z49//8X//7//gv/+m//esv//T7H//8p1/+7vPL/vX3+ZZPKZ/Vn/O/8Vm1fdpz/s7xaXN99vv++nv51F9/r5/26+/t03/9vX9e/jn45+TXdbr57F/+8Pnlt3/542//8Kff/vHv//nPf7rvqKWeZ375tz98/urFvb3nybrm563vZ6/6We28//20eprzvOG8+x31U+b7mbOc28bn/P+7+qedu89o32d/3k8v/bPH49+3...
null
11,782
Gena Playing Hanoi
The [Tower of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) is a famous game consisting of $3$ rods and a number of discs of incrementally different diameters. The puzzle starts with the discs neatly stacked on one rod, ordered by ascending size with the smallest disc at the top. The game's objective is to move ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int hanoi(List<Integer> posts)" ], "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 int[] readIntArray3...
{ "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": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter ...
{ "class_name": null, "func_sign": [ "hanoi(posts)" ], "solution": "#!/bin/python3\n\nimport sys\n\ndef getRod(position, disc):\n return (position>>(disc*2))&3\n\ndef setRod(position, disc, rod):\n position = position & ~(3<<(disc*2)) | (rod<<(disc*2))\n return position\n\ndef getPosition(rods):\n ...
eJylU0sOgjAQdcFBJl0TQz+CeBKNGE2UhRt0AYmJIfEQel9nKAuc0koCkwKLeZ95bV/R5xQtume7w5/9U1yre1OLDYisqCRoLIXLgCoqEYMoH/fyXJeX462p+0aZijaGATIlpOmQiPXjNMOhREhHsXZkViADgJXrS4N1hm+/L46TOI+3OxlzhQKTx+hyVpRw5yuQcz4vr9w6IyH5V0ybOSFgZyBfdwwVyIu3y4QCc2qytzWdgp/yh8BPqNW2+Q2Wl8A4KSa0ZxrY8hPwTSQCBU75CfihsQSkKmHw9WcwRmD66Ky6CV4nnYn28F5+AfbG...
null
28,492
Red Knight's Shortest Path
In ordinary chess, the pieces are only of two colors, black and white. In our version of chess, we are including new pieces with unique movements. One of the most powerful pieces in this version is the *red knight*. The red knight can move to six different positions based on its current position (UpperLeft, UpperRig...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end)" ], "script_name": "Solution", "solution": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\ni...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'printShortestPath' function below.\n *\n * The function accepts following parameters:\n * 1. INTEGER n\n * 2. INTEGER i_start\n * 3. INTEGER j_start\n * 4. INTEGER i_end\n * 5. INTEGER j_end\n */\n\...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n \n static String[] sym = {\"UR\", \"UL\", \"R\", \"LR\", \"LL\", \"L\"};\n static int[] di = {-2, -2, 0, 2, 2, 0};\n static int[] dj = {1, -1, 2, 1, -1, -...
{ "class_name": null, "func_sign": [ "printShortestPath(n, i_start, j_start, i_end, j_end)" ], "solution": "from collections import deque\n\nsurround = [(-2, -1, \"UL\"), (-2, 1, \"UR\"), (0, 2, \"R\"), (2, 1, \"LR\"), (2, -1, \"LL\"), (0, -2, \"L\")]\n\ndef printShortestPath(n, i_start, j_start, i_end, j_e...
eJydlM1KxDAUhV3oexyyHiQ3f218A6ErQRCsCGoXA2OmMB0QRPAh9H09cboQh5ZpmhYK7Zd77slJPs+/64uz3+tO+HL/rtap3w/qCqpqk0eAhbRJraC6t757HrqXx+1+GH+xbbptwKE+VviD+jYZgm4GvX7tt7vd+mnT/WNZ1pLV0MvZOrMBgrCcNSwskXWlgpTwkU07mJoCjFvOO5omEAenYXyBb6zvuGB5xaoC/SIsGiJrw9DCAgViTZtqmAjrEKctsFR6g+WjOek+jiKjxCjO6MlyJlmSM1Ek2zD/E1sgbwK73Mhw0CwwhVtA5wws...
null
784
Journey to the Moon
The member states of the UN are planning to send $2$ people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut ID's. Each pair is made of astronauts from the same country. Determine how many pairs of astronauts from different countries they can choose from. __...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int journeyToMoon(int n, List<List<Integer>> astronaut)" ], "script_name": "Solution", "solution": "\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n publi...
{ "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.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.LinkedList;\n\npublic class Solution {\n\n static boolean[] visited;\n static int N, L;\n stat...
{ "class_name": null, "func_sign": [ "journeyToMoon(n, astronaut)" ], "solution": "#!/usr/bin/env python\n\nimport sys\n\n\nif __name__ == '__main__':\n N, I = list(map(int, sys.stdin.readline().split()))\n \n # Count astronauts from different countries\n astronauts = [-1] * N\n countries = [...
eJws3Tuu7tqWXGsZMlWIibRl/Bx8qyQCdCogZ0MQ7rXkqOjqX+NxIhugZMyuXGPHWpOdQf7f//zf//d//S//6X/8n//4n//8r/////uP//b3H9v5+/3+tpHfv/4Z+Nc/29/61z/73/Gvf46/81//XH/3v/65/55//fPO/9r8P8//kv+t9bft8z/2v23+N7fzb7vmf1x/2/xvb8/f9s7/eP/WXLDGcBzX+ltzwTr+1riu82/NBev+W+O8nr81F+y/v32s9+1vN8L+t4/1fvztc8F+/e1jvd9/+1ywv3/HWB+/v2MuONbfMdbHDG3q8+8Y...
null
5,580
Breadth First Search: Shortest Reach
Consider an undirected graph where each edge weighs 6 units. Each of the nodes is labeled consecutively from 1 to n. You will be given a number of queries. For each query, you will be given a list of edges describing an undirected graph. After you create a representation of the graph, you must determine and report ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> bfs(int n, int m, List<List<Integer>> edges, int 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 ...
{ "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": "\nimport java.util.*;\npublic class BreadthFirstShortestSearch {\n public static void main(String[] args){\n Scanner input = new Scanner(System.in);\n int test = input.nextInt();\n while(test > 0){\n int n = input.nextInt();\n int m = input.nextInt();\n ...
{ "class_name": null, "func_sign": [ "bfs(n, m, edges, s)" ], "solution": "class Graph(object):\n def __init__(self, N, M):\n self.N, self.M = N, M\n self.alist = {key:list() for key in range(1, N+1)}\n for index in range(M):\n t, h = [int(value) for value in input().split...
eJzsvcuKLtmT5SeEHuSjxl3g++rueg+BQAEaSD3QpNSDbhAIgR5ADy1f67fM42Sek3Xrqv7nIMlDRGTE55d9sduyZbb/3//hf/6f/r///r/7X/7vv/s//uE//Zf//Hf/4+fv2tc/9Pnp5/76h/bp+jL0ZerL0hf/4dSXS19ufWmHvzZ/9UXNVzVf1nxd84XNVzZf2nxt97Xd13Zf231tf67tenj/+KelL1tfTn259OXWFz28++HdD+9+ePfDux/e/fDuh3c/vPvh3Q/vfnj3w7sf3v3w8fGXpS9bX059ufTl1hc9d/i5w88dfu7wc4ef...
null
5,686
Kruskal (MST): Really Special Subtree
Given an undirected weighted connected graph, find the Really Special SubTree in it. The Really Special SubTree is defined as a subgraph consisting of all the nodes in the graph and: * There is only one exclusive path from a node to every other node. * The subgraph is of minimum overall weight (sum of all edges) amo...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int kruskals(int gNodes, List<Integer> gFrom, List<Integer> gTo, List<Integer> gWeight)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass E...
{ "solution": "import java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class KruskalMSTReallySpecialSubtree {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n EdgeWeightedGraph ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solution {\n\n private StreamTokenizer in;\n private PrintWriter out;\n\n private int[] parent;\n private int[] rank;\n\n class Edge {\n public int v;\n public int u;\n public int cost;\n\n ...
{ "class_name": null, "func_sign": [ "kruskals(g_nodes, g_from, g_to, g_weight)" ], "solution": "import os\nclass DisjointSet:\n def __init__(self, n):\n # Initialize parent and rank for union-find\n self.parent = [i for i in range(n)]\n self.rank = [0] * n\n\n def find(self, u):\...
eJxE/U2y7MyOdAd/DXW+rkaw7R0BIxi/0kRkpjsBdcrUkFrqaOjCWs48da3qPMjcmcwgGUQgAHfH//s//W//8//6/////e//z//4P/7r//y//6//8b/8/Y/+PM/fqn/+81/tr/+9Zb3/+a8y/vbZffznv96/8ff2/ZY5/ubfuHve//zX/Ft/a7e3/+e/1t/+G3O/9bX9d/7aPafePX/3b5zd/vNf9689f3u+49RPPH+t/a3VnzpGWa3/nX6fVS/6X3vr/+5TP4Q1/sZz65hltPm37+On5l9bf3OtUQcuq+2/+byMuKxWPz6nLxhGjXo9...
null
54
Clique
A clique in a graph is set of nodes such that there is an edge between any two distinct nodes in the set. Finding the largest clique in a graph is a computationally difficult problem. Currently no polynomial time algorithm is known for solving this. However, you wonder what is the minimum size of the largest clique in...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int clique(int n, int m)" ], "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.InputMismatch...
{ "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 input = new Scanner(System.in);\n int t = input.nextInt();\n for(int c=0;c<t;c++){\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static int getMaxNonMCliqueEdgeNumber(int n,int k)\n {\n int g1 = n%k ;\n int g2 = k - g1 ;\n int sz1 = n/k + 1 ;\n int sz2 = n/k ;\n int ret = g1*sz1*g2*sz2 + g1*(g1-1)*sz1*sz1/2 + g2*(g2-1)*sz2*sz2/2 ;\n ...
{ "class_name": null, "func_sign": [ "clique(n, m)" ], "solution": "import math\ndef s1(n, m):\n ga = n%m\n gb = m-ga\n sa = n//m+1\n sb = n//m\n return ga*gb*sa*sb+ga*(ga-1)*sa*sa//2+gb*(gb-1)*sb*sb//2\ndef s(n,c):\n l = 1\n h = n+1\n while l+1 < h:\n m = l+(h-l)//2\n ...
eJyVVstuXUUQZMGSBTu2I68Rmn538yVIGLGALNiYLBIJCSHxEfC/VM2Nrxw71yjRie058+qurqo+f3/57zdffXH+/fA1/vjxz7vfHt6+f3f3/boTv3+wTl+RnZX3DxM6S8V8pDlXkitmb9+Y87Dlsq1K9P4ho5aMa90/VOfS3nsCq2brstIww3m+x5d4jpZgDu+wsM22z/1DY7yk9tgOHBiZOFG8zRtbK3CQqkVbNhbvwd7YNeocTuny3TVu9w933667N3+8ffPLuze//vz7+3cf0sOhl0fs8kseX1zGyDDOo3d/fbue4oL5ToQOAFrH...
null
93
Matrix
The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will attack. Neo has to destroy roads connecting cities with machines in order ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int minTime(List<List<Integer>> roads, List<Integer> machines)" ], "script_name": "Solution", "solution": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\tstatic class Foo51 {\n\t\tstatic class No...
{ "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.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\n\n...
{ "class_name": null, "func_sign": [ "minTime(roads, machines)" ], "solution": "def leader(x):\n if P[x]==x:\n return P[x]\n if P[x]==x+10**5:\n return P[x]\n P[x] = leader(P[x])\n return P[x]\n\ndef same(x, y):\n return leader(x)==leader(y)\n\ndef canJoin(x, y):\n return not(leader(x)>=10**5 an...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
1
17,340
Recording Episodes
Dave is a die-hard fan of a show called "HackerRank", in which a young programmer uses her problem-solving abilities to solve crimes. He splurged on a Digital Video Recorder (DVR) so that he can record HackerRank episodes and watch them later. Luckily, Dave managed to get his hands on schedules for all the episodes in ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> episodeRecording(List<List<Integer>> episodes)" ], "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 pub...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static class Graph {\n int[] ptr;\n int[] nxt;\n int[] suc;\n int index = 1;\n\n public Graph(int nodes, int egges) {\n ptr = new int[nodes];\n nxt = new int[egges];\n suc = new int[egges];\n }\n\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 F {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "episodeRecording(episodes)" ], "solution": "#True if two intervals interesects\ndef has_intersection(I1,I2):\n if I1[0] >= I2[0] and I1[0] <= I2[1]: return True\n if I1[1] >= I2[0] and I1[1] <= I2[1]: return True\n if I2[0] >= I1[0] and I2[0] <= I1[1]: return T...
eJx9vc2uLcmSVU2DBwnddgmF/7vzJEgkogHVoJNUo0pCQkg06NGFl+NpsDHMY9eFzHO/u77DqZN7rxUrwt3cbNqc0/77v/zf//P//Av/v3/zP+Iv//a//uU//f4P//SPf/nXz1/qb7/39dvv5W3vU0Y/TynvfMra47ff96jl2evtzz5rPqfW89vvZ7X2nLXij1N2/NF4i3esp49znl7q+/Rd+m+/j1HPM8tpzzh9PnP197ffay/taaXWp+7ZnnpOfHot833qGPOpbcZ/WS0+aNbx7P0+Kz6l9LfFj7X46Dr3ip+I62n9jR8bp8Z7l/U+...
null
42
Quadrant Queries
There are $n$ points on a plane. Each point $p[i]$ is described by $[x[i], y[i]]$, where $1 \le i \le n$. There are three types of queries needed:  1. `X i j` Reflect all points in the inclusive range between points $p[i]$ and $p[j]$ along the $x$-axis. 2. `Y i j` Reflect all points in the inclusive range betwe...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static void quadrants(List<List<Integer>> p, List<String> queries)" ], "script_name": "Solution", "solution": "/* Enter your code here. Read input from STDIN. Print output to STDOUT */\n\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class Solution {\n private static final int[] BC = new int[1<<16];\n public static void main(String[] argv) throws Exception {\n prep();\n BufferedReade...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static int[] arr;\n static class SegmentTree {\n public int[] c;\n public int start, end;\n public boolean lazyx, lazyy;\n public SegmentTree left,right;\n public SegmentTree(int st...
{ "class_name": null, "func_sign": [ "quadrants(p, queries)" ], "solution": "#!/usr/env python\n\nimport bisect\nfrom math import sqrt\n\n_Rx = [ 3, 2, 1, 0 ]\n_Ry = [ 1, 0, 3, 2 ]\n\ndef create_test( N, Q, fp):\n from random import randint as rand\n r = [ ( rand(-2, 2), rand(-2, 2) ) for i in range( N) ]...
eJzsvcuOJEuyZUeA/BBHjXtg+lblNMacnwQLIAHyDjgp9uA20ABBgJ9OWUvUIvPUrazb3TMCRBVOeoRbuJvpQ1Qee2/5f/6HP/6n//W//+/+5//rL//H3/7jf/rXv/yPn7+M569/K5/617/VT//r39pn/vVv/bP/+rfxKfHO/JR4a31KvLc/Jd48nxLvludT+cP4y3i/1E+NC0r71Lii9E/lkvFpXDI/jUvWp3HJ/jQuOZ8Wl9Tn0+OSWj6dG4g7iEtq+/S4pPZP55Lx4Q7r/AwuWZ/BJfszuOR8RlzSns+MS1r5zLik1c/kQeJJ4pLW...
null
1,090
HackerX
**Update:** A slight modification in the problem statement (see below) Evil Nation A is angry and plans to launch **N** guided-missiles at the peaceful Nation B in an attempt to wipe out all of Nation B's people. Nation A's missile _i_ will arrive in nation B at time t<sub>i</sub>. Missile _i_ communicates with its ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int missileDefend(List<List<Integer>> missiles)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n static class Point implements Comparable<Point> {\n int x, y;\n\n ...
{ "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 Point implements Comparable<Point> {\n int x, y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n ...
{ "solution": "//package hackerrank;\n\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\nimport java.util.stream.IntStream;\n\n/**\n * Created by raggzy on 4/17/2016.\n * OOOh this was hard.\n * 1. Build graph i,j <=> fj-fi <= j-i. This transforms in...
{ "class_name": null, "func_sign": [ "missileDefend(missiles)" ], "solution": "n = int(input())\n\ninp = (map(int, input().split()) for i in range(n))\n\np = sorted(list((a + b, a - b) for a, b in inp))\n\na = list(y for x, y in p)\n\nd = []\nfor x in a:\n\tlow, high = -1, len(d) # >, <=\n\twhile high - low...
eJx0vcuuLUuSXaeGPmQr29WI8LfzSwToAmyQ2WAnWY0sgABBQJ8uG2PGPiBKqATyXPe1Y8WK8Ie5PaZN+3//z//7//pn+z/+n//5t//2j3/9t3/+7T/9/O396x/z5+29/fWPv/3Lz9/+/j/+9e//5Z9//6//+b//2z9/r/jb//qXn//tG+Ovf7Sfud+9abT3vfXd/jPOucebrXb2f3i38e/u1jp3efszXu5y5mz3r3+Mnzl6rz+t+tPZl8a5/a3fvj977v389Y/3+Wn9PPW39/25a45ZrfYz7jubrbrn5br+s049U7Xmzz7vS2v/3HbP...
null
6,788
Number List
Sam is playing with an array, $A$, of $N$ positive integers. Sam writes a list, $S$, containing all $A$'s *[contiguous](https://en.wikipedia.org/wiki/Contiguity#Computer_science) subarrays*, and then replaces each subarray with its respective *maximum element*. For example, consider the following $A$ where $N=3$: $A ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> a, 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.ArrayList;\nimport java.util.A...
{ "solution": "import java.io.*;\n\npublic class HR_number_list {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int tests = in.nextInt();\n for (int test = 0; test < tests; ++test) {\n int n = in.nextInt();\n int k = in.nextInt();\n lo...
{ "solution": "import java.io.*;\n\npublic class HR_number_list {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int tests = in.nextInt();\n for (int test = 0; test < tests; ++test) {\n int n = in.nextInt();\n int k = in.nextInt();\n lo...
{ "class_name": null, "func_sign": [ "solve(a, k)" ], "solution": "def f(a, k):\n bad = 0\n streak = 0\n for x in a:\n if x > k:\n streak = 0\n else:\n streak += 1\n bad += streak\n return len(a) * (len(a) + 1) // 2 - bad\n\nt = int(input())\nfor _ ...
eJx03Uuu7crWHGYXXHAzJm5ZBTKTTJJqiQFfwAVbBVWuVZAAA4IBN8w9ciccX+T6BcOApSudfc5ea04yH+MRI0aM//O//x//7//rf/jv/qf/+o//+K//9F/+8z/+/e8f1z//dd73/buO57yu9Yx//utb1/rGeK/fXOd7z2vO3zPXO99njd83vnce3/f8nue77u/4Xetd3/WM8zfveTzfWvn577mu+1r3Lz9+fdfx/p7rWfe8Hx97zXONY/7u5z3X/N582P3lG05/mt/5nCNfNdd3zvPMB3/fd5zXmY9b45l5mHn93jdfeY5r/c779Ynj...
null
2,573
Power Calculation
Help Shashank in calculating the value of $S$, which is given as follows. Since the value of $S$ can be very large, he only wants the last 2 digits of $S$. $$S = 1^N + 2^N + 3^N + \cdots + K^N$$ **Input Format** The first line contains an integer $T$ i.e. number of the test cases. The next $T$ lines will each con...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String solve(long k, long n)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static Reader in;\n public static PrintWriter out;\n \n public static long mod_exp(long b, long e,...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static Reader in;\n public static PrintWriter out;\n \n public static long mod_exp(long b, long e, long mod) {\n long r = 1;\n while (e > 0) {\n if ((e & 1) == 1) r = (r * b) % mod;\n b = (b * b) % mod;\n ...
{ "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(k, n)" ], "solution": "t = int(input())\nfor _ in range(t):\n k, n = map(int, input().split())\n k += 1\n full = sum(pow(i, n, 100) for i in range(100)) % 100\n tail = sum(pow(i, n, 100) for i in range(k % 100)) % 100\n ans = (full * (k // 100) + ta...
eJzt3cGupLmRpulZ9IUc5LowcKPRSGNdSQOjQS2qtOiNSgsJKKBRwFzBrHo5Fzv0UEpvyVMZ3onAu/MEMjIi8j+/OWkk/ePq+X/+23////7f//Z//F//86f/8Yc//vlPP/3z10/9uz/U3PMxYs59Rs61vno+djwe+2T3WDN/94ezcs37Nz3HPqseX/vMnPGoXmP2iPW7P8zu+7/77PvHjMf8yhx778yKteKx9u/+MGrXI/ccj7PmWPnVt1zMdf96Pu6r49tniXkeY+yxHvdnvyqiR9+/fKwet/rv/rD2yr4/suep2DG+ouvcH1p7zjWr...
null
13,642
Dynamic Array
- Declare a 2-dimensional array, $arr$, of $n$ empty arrays. All arrays are zero indexed. - Declare an integer, $lastAnswer$, and initialize it to $0$. - There are $2$ types of queries, given as an array of strings for you to parse: 1. Query: `1 x y` 1. Let $idx = ( \ (x \oplus lastAnswer) \ \% \ n \ )$. ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> dynamicArray(int n, 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\n// Dynamic Array\npublic class 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 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 in = new Scanner(System.in);\n int n = in.ne...
{ "class_name": null, "func_sign": [ "dynamicArray(n, queries)" ], "solution": "n, q = map(int, input().split())\nl = [[] for _ in range(n)]\n\nlatsans = 0\nfor _ in range(q):\n a, x, y = map(int, input().split())\n if a == 1:\n l[(x^latsans)%n].append(y)\n else:\n t = (x^latsans)%n\n...
eJzU/cuqdd+u5YkZ7AdZnHIW+v2ST2LwARfsKGQlMgoRYDAGP4IfLh/I7Sepz6F9vDeRWciC40Dw3+tba84xetelSWqS/t//p//z/+d/+T/+H/4v/89/+5/+83/5b//13/7Hv39rc//Nff/9P9e/teYte5byN+a6Y621+fHd9ZQx7virq7Y72vj3/9z+Rqunzt7mX9+t60/5Mb+8e+1jnL+zVtvjdPvx6Lu0ddf5G6W20U+v/LiuVnu/ff7VMsrtq17/kDOPPr/93VXLGa1NfjxL3/3W0v70/y/9Z+k8yRmjlDLq/Rt7l137Xfx4ztr2...
null
1,150
Compare two linked lists
<sub>This challenge is part of a tutorial track by [MyCodeSchool](http://www.youtube.com/mycodeschool)</sub> You’re given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. If all data attributes are equal and the lists are the same length, ...
hackerrank
Easy
{ "class_name": null, "func_sign": [ "static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2)" ], "script_name": "SinglyLinkedList", "solution": "/*\n Insert Node at the end of a linked list \n head pointer input could be NULL as well for empty list\n Node is defined as \n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) \n { List<Integer> l1 = new LinkedList();\n List<Integer> l2 = new LinkedList();\n List<Integer> al = new ArrayList();\n \n\n Scanner sc = new Scanner(System....
{ "solution": " // Complete the compareLists function below.\n\n /*\n * For your reference:\n *\n * SinglyLinkedListNode {\n * int data;\n * SinglyLinkedListNode next;\n * }\n *\n */\n static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) ...
{ "class_name": null, "func_sign": [ "compare_lists(llist1, llist2)" ], "solution": "import math\nimport os\nimport random\nimport re\nimport sys\n\nclass SinglyLinkedListNode:\n def __init__(self, node_data):\n self.data = node_data\n self.next = None\n\nclass SinglyLinkedList:\n def __...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
15,592
Down to Zero II
You are given $Q$ queries. Each query consists of a single number $N$. You can perform any of the $2$ operations on $N$ in each move: 1: If we take 2 integers $a$ and $b$ where $N = a\times b$$(a \ne 1$, $b \ne 1)$, then we can change $N=max(a,b)$ 2: Decrease the value of $N$ by $1$. Determine the minimum number of...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int downToZero(int n)" ], "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 private static int MAXSZ = (int)(1E6+1);\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n static int[] moves = new int[1000001];\n\n public static void main(String[] args) {\n for (int i = 1; i <= 1000000; ++i) {\n int least = moves[i - 1];\n for (int j = 2; j * j <= i; ++j) {\n if (i % j == 0) {\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 solve(1000000);\n int t = sc.nextInt();\n for(int i=0; i<t; i++)\n System.out.println(table[sc.nextInt()]);\n...
{ "class_name": null, "func_sign": [ "downToZero(n)" ], "solution": "import math\n\nimport time\nstart = time.time()\n\ndef Sol( N ):\n if N == 0: return 0\n Q = [ (N,0) ]\n setQ = [ 0 ] * N\n while Q:\n N, steps = Q.pop(0)\n if N == 1: return steps+1\n div = int(math.sqrt( ...
eJyNvU2OLT8S3eeBFyL0WDCS36RXYsDP8MDWwJO2BhIgwBDgRdgL8Mzr8koc53eYeZm36rXUaNz/q6rLTH4EgxEnTgT/z//2//5//7//hv/9D/9P/ON//D/+8b/989//x//wj//+3/yj5vHnn6tfV+p//llTSTV+Lle5+vrzzzbSnH/+meI3o4xR/vwz59lz/Ge1OSsN9b1omtOsla+2+PlKLf7V+2rXn3/OGV8a+m/8KY80uv47R+vxwNla1XdWyU3Pay0e1mcv8dgav4u/lVraiq+qoytd8Z9cS4//tD5b/D6Nq6hr8a9c1PtoWad+...
null
8,763
Poisonous Plants
There are a number of plants in a garden. Each of the plants has been treated with some amount of pesticide. After each day, if any plant has more pesticide than the plant on its left, being weaker than the left one, it dies. You are given the initial values of the pesticide in each of the plants. Determine the nu...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int poisonousPlants(List<Integer> p)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.TreeMap;\nimport jav...
{ "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 D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "poisonousPlants(p)" ], "solution": "class plant:\n def __init__(self, pest):\n self.pest = pest\n self.prevkiller = self.nextkiller = None\n __slots__ = 'pest,next,prevkiller,nextkiller'.split(',')\n \nnplants = int(input())\nplants = [int(pest) f...
eJzsvcuu7EqSYCdA0n8E7kCjGtAe7iT7SwQogR5056Ant2uQBTTQaECfLl/LI2LHObdqoFkCexfqWO7LIBlBGh/2WGb2//4f//f/9X/+7//b//M///hvf/7rv/3jj//0+KPm/bc/53k95nmvf2P9q8ecvf6tv8daNtZnYy0bx2N2Pc471r/jcV69/q2/17bn2u4813+fsf/N83Gubc+5/l7bn2N9trY/137OXss717/1WV3Pf/W4qk/EfIsL0Qg/PZYoVqlE1Evk/RZslmOJYL0Yvwo+DbY4rrfgg4MPjrVF3hdiIgZifWVeLFvHeuU6...
null
15,812
Lazy White Falcon
White Falcon just solved the data structure problem below using heavy-light decomposition. Can you help her find a new solution that doesn't require implementing any fancy techniques? There are $2$ types of query operations that can be performed on a tree: 1. `1 u x`: Assign $x$ as the value of node $u$. 2. `2 u v`:...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<List<Integer>> tree, 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\nclass TreeNode imple...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport java.util.stream.Collectors;\n\n class Node {\n int id;\n Node parent;\n List<Node> children;\n List<Node> connections;\n int value;\n\n publi...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass TreeNode implements Comparable<TreeNode> {\n\tint index;\n\tint value;\n\tint level = -1;\t//0 is root.\n\tSet<TreeNode> linkedNodes, children;\n\tTreeNode parent;\n\tBranchContainer bra...
{ "class_name": null, "func_sign": [ "solve(tree, queries)" ], "solution": "class heavy_light_node:\n def __init__(self, size):\n self.parent = None\n self.pos = -1\n self.weight = [0] * size\n self.fenwick = [0] * size\n def set_weight(self, i, x):\n d = x - self.weight[i]\n ...
eJyUncEOLU2OlFnwBIgHKP1rFpWVlZWVPAkSLbGAWbBpZjEjIY2QeHQyvgjX+RsaIST4T8zte+2sc8pppx12/s9//R/+Tfu3/+o//ssf//Wv//jP//THvz/+aNdox9Xv8y9/PY+m/1x/+Ws7uv5z/+Wv1zH0n+cvf+3H1H/ev/z1Ppb+0/Y/GUdr/Hf/o+donf/ufzaPNvjv/ofv0Sb/3f90HW3pv9f+t22rav6QSq3CH/vft+u4hj+2hNaPa/pjy2j3cS0+uqSMozd/SMpz9O4PSZlHH/6QlPfo0x+Sso6++NCjX+dxN39sKdd+9O4P...
null
21,400
Compare the Triplets
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from <em>1</em> to <em>100</em> for three categories: <em>problem clarity</em>, <em>originality</em>, and <em>difficulty</em>. The rating for Alice's challenge is the triplet <em>a = (a[0], a[1], a...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> compareTriplets(List<Integer> a, List<Integer> 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 ...
{ "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": [ "compareTriplets(a, b)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\na0,a1,a2 = input().strip().split(' ')\na0,a1,a2 = [int(a0),int(a1),int(a2)]\nb0,b1,b2 = input().strip().split(' ')\nb0,b1,b2 = [int(b0),int(b1),int(b2)]\n\nA = (a0>b0) + (a1>b1) + (a2>b2)\nB = (a0<...
eJydk01OwzAQhVn0IE9ZV8hje/zDSZAIYgFZsDFdtFIlhMQh4B7suB4vaUBVgiNClB/H8Zd582b8unn/3FwMx/UHBzfPzWPZHfbNFRr1yB62LS7DJ1htS7NF0x133f2+e7h7OuzHlRbSvGxxxjpFdNDQFis9LKEKO5gJrAHOIzJyEliHmKswv0/gyCkPz3hZe/1iV8AhgZS6tkRFUNg6PM9ZMmxEJiyGbsH7FTl7Cw9lop7iEep2mZnolJEDlNEEgrSmTCxOzohEaLOLELcCThRMfxk3JUR2Sj1fAzc1i1LlpFgWsKlNYgzGq7f57OWf...
null
8,636
Staircase
Staircase detail This is a staircase of size $n = 4$: # ## ### #### Its base and height are both equal to $n$. It is drawn using `#` symbols and spaces. *The last line is not preceded by any spaces.* Write a program that prints a staircase of size $n$. **Function Description** Complete the *staircas...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static void staircase(int n)" ], "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) {\n...
{ "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 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 in = new Scanner(System.in);\n int n,i,j,k;\...
{ "class_name": null, "func_sign": [ "staircase(n)" ], "solution": "n=int(input())\nm=\" \"\nt=1\nwhile n>n-n:\n print((n-1)*m+t*(\"#\"))\n n=n-1\n t=t+1", "template": "#\n# Complete the 'staircase' function below.\n#\n# The function accepts INTEGER n as parameter.\n#\n\ndef staircase(n):\n # ...
eJzFnU2OHEUQhVlwkFHH1kI2Nthmx44jIGHEAmbBZvBiLCEhSxwC7sdRQHjc052VWRXx8uXnWpXSwXs1PaX8efFN8+fnf3/3z2f/X99/+9/ND3+cfr17++7+9M3N6fWbu9OTm9Pt729vf76//eWn397dP/xLvLm7+XDF+TbOt3G+jfNtnG/jfBvn2493cXr/5ObiCb7ce4JN9avj5718xsdHfHzCxwd8fL7Hx2ufbvfxbjpX9MejPx798eiPR388+uPRH4/+ePTHoz8e/fHoj0d/PPrj0R9vhy/fv+34dvjyzWzHe8OX7+zV1bwiL15U...
null
26,276
Mini-Max Sum
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. **Example** $arr = [1, 3, 5, 7, 9]$ The minimum sum is $1 + 3 + 5 + 7 ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static void miniMaxSum(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \nclass Main {\n\tstatic int ans[]=new int[1000001];\n\t\tpublic 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\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 a[] = in.nextIntArray(5);\n Arrays.sort(a);\n ...
{ "class_name": null, "func_sign": [ "miniMaxSum(arr)" ], "solution": "a = input().strip().split(' ')\nfor i in range(0, len(a)):\n a[i] = int(a[i])\n \ns = sum(a)\nprint(str(s - max(a)) + \" \" + str(s - min(a)))", "template": "#\n# Complete the 'miniMaxSum' function below.\n#\n# The function accep...
eJylVc1qFGEQ9CD4Gs2eg/T/j08iqHjQHLxEDwkIIvgQevfma1oTM7s6cZaI37JLs/TX1VVdPfPl8bcfTx7dnuffEbz4dHh39eHm+vCMDtkZNcZOIhPObUqaHcFjVJNqViOkEybsnS+vDhd0uPz44fLN9eXb1+9vru8KiWhrR0mQ9FSmu9jh8wX9BqaJOowfUpssLlESn9ZCDDSumvFCK8xhFr6LVqnB6rzcd1PtmdiAlWaijDMKBzobMxpwLQ4pClBEv6mE/9FC1C6WKnPLyCgZZ7ghWzdgac6WARYexhYiQuaiaVNkAlahkJg52YNt...
null
35,155
Subarray Division
Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it. Lily decides to share a contiguous segment of the bar selected such that: - The length of the segment matches Ron's birth month, and, - The sum of the integers on the squares is equal to his birth day. Determine ho...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int birthday(List<Integer> s, int d, int m)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\npublic final class womens_a\n{\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstat...
{ "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": " \t\n \t\t\n \t\t /*\n \t\t * Author- Priyam Vora\n \t\t * BTech 2nd Year DAIICT\n \t\t */\n \t\t \n \t\t \n \t\t import java.io.*;\n \t\t import java.math.*;\n \t\t import java.util.*;\n \t\t import javax.print.attribute.Set...
{ "class_name": null, "func_sign": [ "birthday(s, d, m)" ], "solution": "n = int(input())\ns = list(map(int, input().split()))\nd, m = map(int, input().split())\n\nans = 0\nfor i in range(n-m+1):\n if (sum(s[i:i+m]) == d):\n ans += 1\n \nprint(ans)", "template": "#\n# Complete the 'birthd...
eJy1VcFO5DAM3QOH/YyoZ7SqHXto+QVunJAo4rA7h710OQwSEkLiI+B/ceKXtGyns/SwE00n4ybPz/aL83r2fv39W/7cXNnk9rn5PT48HprL0NBuGClo4CA2OEQb/pSQ7DYbRg40jM15aPZPD/ufh/2v+z+PBwDY6+blPMwgWROk7QkEWM1gbEPhigy4rMkObUsXiFfdtAs31A1jAne+hKfCDZc4DNjctRuAe3L+DM6eDmcreeaJ0vwrsygjLDHPFVZCtBF2xpsIvJJqBUIEevHtGeKMxdilCJYykgev23OoXSqug6EQKJKAsICAZmdO...
null
21,634
Divisible Sum Pairs
Given an array of integers and a positive integer $k$, determine the number of $(i, j)$ pairs where $i \lt j$ and $ar[i]$ + $ar[j]$ is divisible by $k$. **Example** $ar = [1, 2, 3, 4, 5, 6]$ $k = 5$ Three pairs meet the criteria: $[1, 4], [2, 3],$ and $[4, 6]$. **Function Description** Complete the *d...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int divisibleSumPairs(int n, int k, List<Integer> ar)" ], "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 sta...
{ "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": "\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 A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "divisibleSumPairs(n, k, ar)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn,k = input().strip().split(' ')\nn,k = [int(n),int(k)]\na = [int(a_temp) for a_temp in input().strip().split(' ')]\n\nresult = 0\nfor i in range(n-1):\n for j in range(i+1, n):\n i...
eJztl72OHUUUhAmIeYajG1to+r+bJ0HyRQSwAcnFwVpCQkhEZM7M+/qrmouxZpkLhEh4vN5RT/+cU6eqTvvXz39/98Vn/vP1b7y8/vnyw+3N2+fLV3FpLVa93nKUFXVGblFajBKtR04aSV3vpcbIMVPkEmPF4KVG7bG0PFKOPvXe+Nqit8g50oo8YpVIm7atzM9Roy2/Ru8xVyx2Zz3PbDpwLW3AIWVEKjGrPxPg5VVcnn568/Td89P33/749vkefhqXX17FJ/mw51A+VeHUFWVTaINAyKZE1wAp9RrZEa/hxLryKUTvbDuHD+Zmw5Ij...
null
22,936
Counting Valleys
An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly $steps$ steps, for every step it was noted if it was an *uphill*, $U$, or a *downhill*, $D$ step. Hikes always start and end at sea level, and each step up or down represents a $1$ unit change in altitude. We define the follow...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int countingValleys(int steps, String path)" ], "script_name": "Solution", "solution": "/*\n * PDPM IIITDM Jabalpur\n * Asutosh Rana\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main\n{\n static long MOD = 10...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'countingValleys' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts following parameters:\n * 1. INTEGER steps\n * 2. STRING path\n */\n\n public static int coun...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n in.nextInt();\n String s = in.next();\n \n int level = 0;\n int valleys = 0;\n for(int i = 0; i < s...
{ "class_name": null, "func_sign": [ "countingValleys(steps, path)" ], "solution": "N=int(input())\nS=input()\nL=0\nV=0\nfor s in S:\n if s == 'U':\n L += 1\n if L == 0:\n V += 1\n else:\n L -= 1\n \nprint(V)", "template": "#\n# Complete the 'countingValleys' f...
eJzsmLGutclxXQ3DD0JMrECkSIpS3I/gBgxYgAKJgRJaAQkIEAT4GfzEJsVba63qc4dm4kj6h3PvOd/XXV2199r9D/i//9v/+O//57/+l//5rz/802/++Xe//eFvf/LDz/7y735z+XP488Nf/OSHX//LP//6H37763/8+//1u99+Lf/96h/+7S9+kgI//cs/VDj////58zv6+e+fnfOHcX7/z8x0+XW/3nx94Pf946J5+8e11vn3b/ePNf79sS+P5c4I+VXuT3T+q8/Of/qrf+/8TD9fPf+xzfZ+Z6A58czzS3s299UhA35VrQA/0uNP...
null
29,054
Cats and a Mouse
Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse does not move and the cats travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will ...
hackerrank
Easy
{ "class_name": null, "func_sign": [ "static String catAndMouse(int x, int y, int z)" ], "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.*;\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 q = in.nextInt();\n for(int a0 = 0; a0 < q; a0++){\n ...
{ "class_name": null, "func_sign": [ "catAndMouse(x, y, z)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nq = int(input().strip())\nfor a0 in range(q):\n x,y,z = input().strip().split(' ')\n x,y,z = [int(x),int(y),int(z)]\n \n if abs(x - z) < abs(y - z):\n print('Cat A')\n elif abs...
eJy9mUtvJEkVhVuCHxIy2xHKiMh4sZueNXskjBCCXrDxjES3hIRG4kfAv2XB+c6t8tDGLmeVDSNrKjszMh73cc65N//+83/+7Bcf/N9v/nX34cNv/3b354cfvny++1W6m+X+Ibe0p9XuH2pPtaSydGvqRsr7/cMcXI1N90oaPTWNY3zWi2WmuqWuO2Pq1uBWT6ukqRfXprdS01VZqU296wVyWlO39LN5rn1Puls2z7Y0jV7ITJ929lHT3tMeK9Q9aY61p7ZS56GerJSzHuZUZ5q6mlvaRxqs2tLSKvcPPc2mferNxSjGa9fMvLwjzYYV...
null
1,884
Circular Array Rotation
John Watson knows of an operation called a _right circular rotation_ on an array of integers. One rotation operation moves the last array element to the first position and shifts all remaining elements right one. To test Sherlock's abilities, Watson provides Sherlock with an array of integers. Sherlock is to perform...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> circularArrayRotation(List<Integer> a, int k, List<Integer> queries)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class...
{ "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": "\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class 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 q = in.nextInt();\n\t\tLinkedList<Integer> list = new LinkedList<...
{ "class_name": null, "func_sign": [ "circularArrayRotation(a, k, queries)" ], "solution": "#!/usr/bin/env python\n\nimport sys\n\n\nif __name__ == '__main__':\n N, K, Q = list(map(int, sys.stdin.readline().split()))\n A = list(map(int, sys.stdin.readline().split()))\n \n for _ in range(Q):\n ...
eJzUvcuupVuSZgUSj0FjK9rVmPdLPUlJuEQDskEnqEaWVBJC4tGxMWyu5XFO5ElRtCCV4cd977X+f17sbp+Z/V//w3/6+//43/93/9P/8bf/7e//+b/869/+48/f6v6Z56eWX3+vP+2n/4yf+bN+9s/5ufHTn1p/avup/aeOnzp/6vqp+9ff4//r+vX3+evvI/9R83/Lf/Vff//bf/j527/81//8L//Lv/7L//o//+//5V8/L4uPlfxujS9XH8Fftv+o8bS//Z//4ecflrfKz43/qz8jvjfaz//f/j+2d/N/xf//h3/18v3rH//zftd/...
null
15,335
Minimum Distances
The distance between two array values is the number of indices between them. Given $a$, find the minimum distance between any pair of equal elements in the array. If no such value exists, return $-1$. **Example** $a = [3, 2, 1, 2, 3]$ There are two matching pairs of values: $3$ and $2$. The indices of the $3$'s a...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int minimumDistances(List<Integer> a)" ], "script_name": "Solution", "solution": "/*\n * Code Author: Akshay Miterani\n * DA-IICT\n */\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\n...
{ "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": [ "minimumDistances(a)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn = int(input().strip())\nA = [int(A_temp) for A_temp in input().strip().split(' ')]\n\nm = 10**6\n\nfor i in range(n):\n for j in range(i+1, n):\n if A[i] == A[j]:\n m = min(m, ...
eJztnc2uJElSRlnwIKlmhwYUbv7PkyBRiAWMBJuaWcxISAiJh4D35RzziNstegpNwabnKruUUbfyWkZ42Gdu9tlPZP/Hn//XX/7zn+V/f/sX/PB3//bDv3z97e9/98PfvH5o88vX3vfar1l61Neqq6/Xarvu115XuV5lrB2v3qKu1xyt9desnfdnbdd8ldqD30bf/bV6L/GK0WO+YvXSXrOXOZAsyHNizjOuuSpnK7O8RhtjvfpVo7/6mqVw7Nf1apOLvWqZr136XK/aWyuct83+antenHH3a7+ie969ur+NGNdr9Mo7Edf2eqXzfm37...
null
15,233
Flatland Space Stations
Flatland is a country with a number of cities, some of which have space stations. Cities are numbered consecutively and each has a road of $1 km$ length connecting it to the next city. It is not a circular route, so the first city doesn't connect with the last city. Determine the maximum distance from any city to it...
hackerrank
Easy
{ "class_name": null, "func_sign": [ "static int flatlandSpaceStations(int n, int[] c)" ], "script_name": "Solution", "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\n pub...
null
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchExceptio...
{ "class_name": null, "func_sign": [ "flatlandSpaceStations(n, c)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\nn,m = input().strip().split(' ')\nn,m = [int(n),int(m)]\nc = [int(c_temp) for c_temp in input().strip().split(' ')]\nc = sorted(c)\nif (m == 1):\n print(max(c[0]-0, n-1-c[0]))\nelse:\n ...
eJyMvc3KNV2yXeeG8HVsqq1Gzsh/XYnBBW5Ip6HOZzWOwGAMum91tMaY+R4LigIZKnX85ZtP5t47cq5YETEi/tu/+z/O//6//2//5//7t//813/5r//6t//w+1s2/r8f/8/f//L//c36377+d6z/net/1/rfvf73rP+937/9hX8Z/mn4t+Efh38d/nn49+GCvP2L6+Df5orhiuGK4YrhiuGK4Yp5e/914Irdx+GKnSt2rti5YueKnSv2t0+7DlxxcMXhJ+CKgysOrji44uCK4+1nWweuOLni5IrTD80VJ1ecXHFyxfn2m1gHrri44uKK...
null
21,763
Happy Ladybugs
Happy Ladybugs is a board game having the following properties: * The board is represented by a string, $b$, of length $n$. The $i^{th}$ character of the string, $b[i]$, denotes the $i^{th}$ cell of the board. * If $b[i]$ is an underscore (i.e., `_`), it means the $i^{th}$ cell of the board is empty. * If $b[i...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String happyLadybugs(String 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 main(String[] ...
{ "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 Q = in.nextInt();\n for(int a0 = 0; a0 < Q; a0++){\n ...
{ "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 boolean solve(String s) {\n boolean hasUnderscore = false;\n boolean allAreHappy = true;\n int cntChar[] = new int[26];\n\...
{ "class_name": null, "func_sign": [ "happyLadybugs(b)" ], "solution": "#!/bin/python3\n\nimport sys\nimport collections\n\n\ndef all_happy(ladybugs):\n \"\"\"Assumes no empty cells.\"\"\"\n for i, bug in enumerate(ladybugs):\n try:\n left = ladybugs[i - 1]\n except IndexError...
eJy1WEuPHbeVzmJ+RJaG1kEwkmW5lR3fLJLFYvFVZEXBWUy8yKYnCwcYYDBAfkSyzi6/c77qVgxb3Wp120jdvn1fVSQPz/kep/76H3//569/dXeMf+DN7//31Z9u//yX71/97qtXrz/cfv3hlnP+4fbVb7569d3//Pm7//r+uz/Sf//l+49nTFXw2//95qufXvXuwy3jQir92Qvj9uA6TPUtriO6/u7f341h7t8zzoWQT6/kGvWRkbGit28+3NJTx/njDy9ZNgZ+h3jTabig3KVYo5P+2A5NLsuke90r7+FkedfEBTtGyX43kx2CDkvd...
null
343
Insertion Sort - Part 2
In _Insertion Sort Part 1_, you inserted one element into an array at its correct sorted position. Using the same approach repeatedly, can you sort an entire array? _Guideline:_ You already can place an element into a sorted array. How can you use that code to build up a sorted array, one element at a time? Note that ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static void insertionSort2(int n, List<Integer> arr)" ], "script_name": "Solution", "solution": "\n\n/* Head ends here */\nimport java.util.*;\npublic class Solution {\n \n public static void insertIntoSortedArray(int[] ar, int i)\n\t{\n\t\t\n\t\ti...
{ "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.*;\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 PrintStr...
{ "class_name": null, "func_sign": [ "insertionSort2(n, arr)" ], "solution": "size = int(input())\narray = input().split(\" \")\narr = ['None'] * size\nfor i in range(size):\n arr[i] = int(array[i])\ni = 1 \nwhile i < size:\n tmp = arr[i]\n j = i - 1\n while arr[j] > tmp and j > -1:\n a...
eJzs3cuOHPd26Gk00C/RswLHm0BGRMbNT9LA2YAPYGvgHsh7oA0YMAycR++1VlAiRdUlqyovcfkm27JEVmVm/Nf6RXwiqf/zf/+//8//97//r//131/+49d//PO3L//y9GX8+69f52EYn762Tf/Unsb26Ws39P3T16Y5909Tfx6ezu18/vuvX/729OWX//rHL//22y///q//+c/fvn2Bi37204Xf5fuPW/7p9x/9+o+rf/r9R1/7x9UPyR/85X/+9vTDh9f9/de2bc9PX/u5nZ/OzTS8/DHVD6kfnT8uv+Gf/85PX7r/+69T/O2nr+d2...
null
444
The Full Counting Sort
Use the counting sort to order a list of strings associated with integers. If two strings are associated with the same integer, they must be printed in their original order, i.e. your sorting algorithm should be _stable_. There is one other twist: strings in the first half of the array are to be replaced with the char...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static void countSort(List<List<String>> 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 public static void main(Str...
{ "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.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author akshay\n */\npublic class Solution{\n public static void main(String[] args){\n Scanner sco=new Scanner(System.in);\n int siz=sco.nextInt();\n String[] mak=new String[siz];\n int[] mak1=new int[siz...
{ "class_name": null, "func_sign": [ "countSort(arr)" ], "solution": "n = int(input())\nar = []\nfor i in range(0,n) :\n data = input().strip().split(' ')\n ar.append((int(data[0]), data[1]))\n\nc = [0]*100\nfor a in ar :\n c[a[0]] += 1\n \nc1 = [0]*100\nfor x in range(1,100) :\n c1[x] = c1[x...
eJx8vdnO5DiyBuYL3/gthHNtA117le/8FgY8gEGKu0RRFBeRMgz4Nfy2jiX/pWf6GA3MVFVmaiFj+SLii+D/8z/+7//b//s//Q//x//1X/44W/2v/3X5ry/ffv7+1/Hl6yJKu551Xe9/HX++Ltv81/Hj1yL+dXz9vtzKHlpY/6/j95cl2CuZIsa/jl9flyv2fsAPvi+nnyWfm4J//raYsK56jXCpL9+W4G7R2ynTv47vPxa4yJffS207fPH7sorsy/SKLtZu+PDnj8WOw8Tz/Nfx7cvSzLravXUJD7L4krziC+T7Ma1Eb056whngcb8u...
null
457
Find the Median
The median of a list of numbers is essentially its middle element after sorting. The same number of elements occur after it as before. Given a list of numbers with an odd number of elements, find the [median](https://en.wikipedia.org/wiki/Median)? **Example** $arr = [5, 3, 1, 2, 4]$ The sorted array $arr' = [...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int findMedian(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\t\n\tprivate static int[] input;\n\t\n\tprivate static void compute(int[] input){\n\t\t\n\t\tArrays.sort...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.Arrays;\n\npublic class Solution {\n\n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n try {\n br.readLine();\n String[] strAr...
{ "solution": "import java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class Solution {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int inputSize = Integer.parseInt(sc.nextLine());\n ArrayList<Integer> arr = ...
{ "class_name": null, "func_sign": [ "findMedian(arr)" ], "solution": "import math\ndef main():\n testcase = int(input())\n med = [int(i) for i in input().split()]\n print(findmed(med))\n \ndef findmed(med):\n med.sort()\n if(len(med)%2 == 1):\n return med[int(len(med)/2)]\n else...
eJy8vc2utkuTnMWACWex1GMv6a7/Ko4EiZYYgAdMGg9syRJC4jQ4UqbUdUWtD6yWJU9wt3r33u+71vPcP1VZmZERkf/nf/s//N//13/33/yP//s//a//8u/+w7//p//+559q+ed/+S3f/Z+f33P/x39u/7n85/z5T/76+0/+N3/jX/hr/pa/dP8x+Ef/p3/z80//9j/+u3/7P//7f/u//E//23/49+97v3/+l3/6P/7Nz//nSkZbXEpZ9xv3HuenntJ/di3rp1e+f5zefmr/7ud+5ee3jtp+2pjrp+0+f/au97LX/c/f1sv9+7FG/elf...
null
1,364
Making Anagrams
We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, `bacdc` and `dcbac` are anagrams, but `bacdc` and `dcbad` are not. Alice is taking a...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int makingAnagrams(String s1, String s2)" ], "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...
{ "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.Scanner;\npublic class Solution{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n String str1 = in.next();\n String str2 = in.next();\n int[] arr = new int[26];\n for(int i = 0; i < 26; i++)\n arr[i] = 0...
{ "class_name": null, "func_sign": [ "makingAnagrams(s1, s2)" ], "solution": "import sys\nlines = [sys.stdin.readline(), sys.stdin.readline()]\n\nlines = [line.strip() for line in lines]\n\nlines = [ sorted(line) for line in lines ]\n\ncounts = [\n\t[\n\t\tsum( [1 for c in line if c == test] )\n\t\tfor test...
eJzsvdvOJbuaJQQSD1Kq677ooqFF8SRIbAn5fD6fjUA8OsMbLoDdW6oWpT8rs8PyyrVWes6YDvv7xiHsiPg//pv/qf/v//V/9T//r/9oYh79H//Hf/hHQhkXUmljnQ8x5VJbH3Ptc/8S/19t5P/Z9o//7h/+UewsWBf8f0mj/98H+2//Ev/xf/t3//AvOvzX8rV8LV/L1/K1fC1fy9fytXwtX8vX8rV8LV/L1/K1fC1fy9fytXwtX8vX8rV8LV/L1/K1fC1fy9fytXwtX8vX8rX8Ni3/nz11/xa69LV8LV/L1/K1fC1fy9fytXwtX8vX...
null
20,589
Super Functional Strings
We define a function, $F$, on a string, $P$, as follows: $$F(P) = \bigg(length(P)^{distinct(P)} \bigg)\ \% \ (10^9 + 7)$$ where: * $length(P)$ denotes the number of characters in string $P$. * $distinct(P)$ denotes the number of distinct characters in string $P$. Consuela loves creating string challenges and she ne...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int superFunctionalStrings(String s)" ], "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.I...
{ "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 D {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solve(...
{ "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 D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t...
{ "class_name": null, "func_sign": [ "superFunctionalStrings(s)" ], "solution": "from string import ascii_lowercase\nfrom bisect import bisect_left, bisect_right\nfrom itertools import zip_longest, islice\n\nMOD = 7 + 10 ** 9\n\nN = 10 ** 5\n\nsum_pow = [[0] * (N + 1) for k in range(27)]\nfor k in range(1, ...
eJzsvNmqBUm2JCaQPuRSz/ehcs7sDxECFTQ+z/PsTYN+S38ni7z90nRl0yAE0pVnVGVZHTtn7wj35bbMInzv/+N/+d/+1//zf/6f/vf/9DcT8+h/+w//8rcf/hGN5JvtxWilSrSzAotjKLGGUJP7uaf1qoSVA2nyNiJzdo7aqtW8gdzLa9DGuZ542YveyScLR5ExjGokt1GKbWGXwxMjJupcbS02VeN6rMMSXpqhm163uM1O3F5cz5Vu0gavpcbbrUnHNL9tDUNcY6VQI0o+pbmRExH1iIvx68Th03EeSnCJpGZrlHY1y0SqIm7DphTD...
null
6,774
Connected Cells in a Grid
Consider a matrix where each cell contains either a $0$ or a $1$. Any cell containing a $1$ is called a *filled* cell. Two cells are said to be *connected* if they are adjacent to each other horizontally, vertically, or diagonally. In the following grid, all cells marked `X` are connected to the cell marked `Y`. ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int connectedCell(List<List<Integer>> matrix)" ], "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 public static int se...
{ "solution": "import java.util.*;\n\npublic class Solution {\n static void regionX(int[][] matrix, int n, int m, int i, int j){\n if(matrix[i][j] == 1){\n matrix[i][j] = 2;\n if(i < 0 || j < 0){}\n else if( i == 0 && j == 0){\n regionX(matrix, n, m, i + 1, j)...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static int N,M;\n public static int[][] grid;\n public static boolean[][] vis;\n\n public static void main(String[] args) throws IOException {\n in = ne...
{ "class_name": null, "func_sign": [ "connectedCell(matrix)" ], "solution": "rows = int(input())\ncols = int(input())\n\nmat = []\nfor _ in range(rows):\n mat.append([int(x=='1') for x in input().strip().split(' ')])\n\n \nones = set()\n\nfor row in range(rows):\n for col in range(cols):\n i...
eJzNVc1OwzAM5sCFt6hynpBd1nWduPESSBRxgB64lB06CQlN4iHgfeman9qOLcqJbeuUOo79+cvn5PPy++7qYvrc346Dhw/32u8Pg9sVrm57jD/gA7cqXPe+756H7uXp7TCEFaU7rgoSoWz7U5ACxi/6Z4xQQDBMr0aotQi1bfvNaS2G1eDjhth0Bn0K9AYxg/kMztHSiwEKdVQzEBAvDG9CG/EyN8YPRnZYAAtVJVCNkCpCQqwN5rzouSBDyDLa+WqRbwxQTgvtJTlvNx4ABBwBWcgfVBKAhQKS0UiyzWmoSe0xoLpBKU+cRUoWzIQR...
null
47
Task Scheduling
You have a long list of tasks that you need to do today. To accomplish task $i$ you need $M$<sub>$i$</sub> minutes, and the deadline for this task is $D$<sub>$i$</sub>. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then switch back. You've realized that it might ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int taskScheduling(int d, int m)" ], "script_name": "Solution", "solution": "import java.util.*;\nimport java.io.*;\n\nclass Solution\n{\n\tBufferedReader input;\n\tBufferedWriter out;\n\tStringTokenizer token;\n\n\tint[] ST;\n\tint[] add;\n\n\tvoid ...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\nclass Task implements Comparable<Task> {\n\n public long D;\n public long M;\n\n public Task(long D, long M) {\n this.D = D;\n this.M = M;\n }\n\n public int compare...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\tprivate static StringTokenizer tokens = new StringTokenizer(\"\");\n\tprivate static BufferedReader in;\n\tprivate static BufferedWriter out;\n\t\n static class Tree {\n privat...
{ "class_name": null, "func_sign": [ "taskScheduling(d, m)" ], "solution": "def returnIndex(array,number):\n if not array:\n return None\n if len(array) == 1:\n if number > array[0]:\n return 0\n else:\n return None\n\n si = 0\n ei = len(array)-1\n r...
eJzsvcGuLb2unZeGkedYOO3bKLIkleQnCeADuJHchjsnblwDAQwDeag8j58l5CDHqP/Whm/DjTSCdfCfLa05a6qqVCJFkZ9Y//e/+9/+n//+v/4v/+G//u0//eM//5d/+du///mb2d//YT/xj//43/9x/9x//8f4GX//x/yZf//Hyi+e/GLnFye/sCu/Mfzmb//087d//r/+8z//7//yz//Hf/w//8u/dJtXfB9txe/z8P5/nic+svjMr/r/3/7bP/385VKeaNfvM5+ffZ88+o5zHY8frnU/8+esHRe31lg/z8oDzjjxYdTG42v83CMu...
null
19,174
King Richard's Knights
King Richard is leading a troop of $N^2$ knights into battle! Being very organized, he labels his knights $K_0, K_1, \ldots, K_{N^2-1}$ and arranges them in an $N\times N$ square formation, demonstrated below: ![knight1](https://s3.amazonaws.com/hr-challenge-images/19174/1467511713-dd93440d86-3.png) <!-- https://s3....
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<List<Integer>> kingRichardKnights(int n, int s, List<Integer> knights)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Soluti...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution2 {\n\n static class Drill {\n int x1;\n int y1;\n int z;\n\n int num = 1;\n long sumX;\n long sumY;\n\n int invX1;\n int invY1;\n long invSumX;\n long invSumY;\n int inNum = 0;\n\n Drill(int x1, int y1,...
{ "solution": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class App {\n\tpublic static void main(String[] args) throws Exce...
{ "class_name": null, "func_sign": [ "kingRichardKnights(n, s, knights)" ], "solution": "from __future__ import print_function\ntry: input = raw_input\nexcept: pass\n\n# i is rows/down, j is cols/across\n\n# Carry out order for a given position\ndef rotate_clockwise(pos, i, j, width):\n (offi,offj) = (pos[...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
21,484
Tripartite Matching
You are given $3$ unweighted, undirected graphs, $G_1$, $G_2$, and $G_3$, with $n$ vertices each, where the $k^{th}$ graph has $m_k$ edges and the vertices in each graph are numbered from $1$ through $n$. Find the number of ordered triples $(a, b, c)$, where $1 \le a, b, c \le n$, $a \ne b, b \ne c, c \ne a$, such that...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int tripartiteMatching(int n, List<List<Integer>> g1, List<List<Integer>> g2, List<List<Integer>> g3)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport j...
{ "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 D {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n int[][] rea...
{ "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 D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint[][] read(int n)\n...
{ "class_name": null, "func_sign": [ "tripartiteMatching(n, g1, g2, g3)" ], "solution": "vertices = int(input())\ngraph = [[], [], [], []]\ncount = 0\nG1 = 1\nG2 = 2\nG3 = 3\n\nfor i in range(1, 4):\n for j in range(0, vertices + 1):\n graph[i].append(None)\n\nfor i in range(1, 4):\n edges = in...
eJy1vU+uNEvT5MWAhRx94xbKjP/BiBlbQKIQA+gBkw8G3RISaolFwA5ZCGk/s6iqc597W43UvNJ7Tz1VWVmZkeER7m5m7v/nf/l//7f/z3/B//67/+Z58d//H//yv/zr//bv/92//Nc//zJrf/1rGc//f+7Xv1b9p+k//ae9/nX81Ne/Tv1z6T9b/7wvvbzvn+c7d/l5vn3Xn/L8l6/dnf8Offt+vnk9fxb/2D/3en6Fb5dbb5XyU57PS9VJyvP1+fzp+o0yfm79mT+6snuW9+UVXV7R5VVdXtflDV1e1+UNLq9xeZvLu7m8+XV5g8ub...
null
32,212
Weighted Uniform Strings
A weighted string is a string of lowercase English letters where each letter has a *weight*. Character weights are $1$ to $26$ from $a$ to $z$ as shown below: ![image](https://s3.amazonaws.com/hr-challenge-images/0/1484319110-9529e3b407-uniform.png) - The _weight of a string_ is the sum of the weights of its charact...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<String> weightedUniformStrings(String s, List<Integer> queries)" ], "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\...
{ "solution": "import java.util.*;\npublic class WeightedUniformString {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n int n = in.nextInt();\n char [] charArray = s.toCharArray();\n int contigentString = 1;\n ...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWr...
{ "class_name": null, "func_sign": [ "weightedUniformStrings(s, queries)" ], "solution": "s = input().strip()\ncost = set()\nprev = ''\ncount = 0\nfor i in s:\n if i != prev:\n prev = i\n count = 0\n count += 1\n cost.add(count * (ord(i) - ord('a') + 1))\nfor _ in range(int(input())):...
eJzt2t1u49p5gOEe9KCXMfDxRsHFxd9cRI560KBTBP6RLf9JHlu2ZQUBehG9ul5Nv295pwgmSLLTBm128RjvPJl4JIqiyEVyaf/b3//zf/zTP/zdv/zm7Hb39Ho4+8WXs7fD29X1zcfm6v1wt7u7er642F28n97eLjdPH6eX4+7x+uLrbh6+7vp1ndd+ir+MpdR5/bqb+n6Z1/Hrbuy7fp67+MvU1bmr8ZeldnVc85lz6fPBdSlDyX9a+qWrdYnfzMPaL/FPS7esUzfHkoeydlO81rLEq63xm6mUsV9L/maY1j7+aRy6cRljOfGUeHp7...
null
1,847
Two Two
Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2. One day he played a game in his class. He brought some number plates on each of which a digit from 0 to 9 is written. He made students stand in a ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int twoTwo(String a)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\n\npublic class Solution {\n\n static class Node {\n Node[] edges = new Node[10];\n Node sl...
{ "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.math.BigInteger;\nimport java.util.*;\n\n\npublic class Solution {\n BufferedReader reader;\n\n int nextInt() throws IOException {\n tokenizer.nextToken();\n return (int) tokenizer.nval;\n }\n\n String next() throws IOException {\n tokenizer.nextToken();\n ...
{ "class_name": null, "func_sign": [ "twoTwo(a)" ], "solution": " \ntree = [False, {}]\n\ndef add(word) :\n current = tree\n for c in word :\n try :\n current = current[1][c]\n except KeyError :\n current[1][c] = [False, {}]\n current = current[1][...
eJx03UuuddvSnWUSLoj1p52Y4z4GJUHiSCTACTIHJ4yEhJCoDeWgZsTz9nUQwrJ9tP+9v2+tOcel9+gRLVpr8X/+u//u//q//91/89//7//2P//zP/2v//nf/tt//2/bP/75bte3v7/t+N3nfuzn8zuO47yf/fj9vvPc7m/brv099++6f899Hr/rOeePfr/z++3vt53XflzH9Vz3/OvvOo75xG3fz/ve9t9+Pfvz3tt3buf5+13fsz37fNN9bfOf8xfXfr3Pbz7oPY75o/e7zud6nvP89uO9fue+HfNTx88/5wfPc67yO865qHs+bv8d...
null
2,490
Sherlock and Array
Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all elements to the left is equal to the sum of all elements to the right. **Example** $arr = [5, 6, 8, 11]$ $8$ is between two subarrays that sum to $11$. $arr = [1]$ The answer is $[1]$ si...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String balancedSums(List<Integer> arr)" ], "script_name": "Solution", "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\tvoid solve() ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\npublic class Solution {\npublic static void main(String[] args) {\n/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\nScanner in = n...
{ "solution": "import java.util.Scanner;\n\n/**\n *\n * @author akshay\n */\npublic class Solution {\n public static void main(String[] args){\n Scanner sco=new Scanner(System.in);\n int cases=sco.nextInt();\n int[] ar,pr,po;\n for(int i=0;i<cases;i++){\n ar=new int[sco.nextI...
{ "class_name": null, "func_sign": [ "balancedSums(arr)" ], "solution": "for t in range(int(input())):\n n = int(input())\n a = [int(b) for b in input().split()]\n s = sum(a)\n count = 0\n for i in range(n):\n if 2*count == s-a[i]:\n print(\"YES\")\n break\n ...
eJykncuuN8ty1BnAe7TO2IOuexVzT2HgCRafxAA8YPLhgS0hISRegSfi1ej4RWb32sfYyKBz2Wuv9b9UV2VlRkZGVf6Pf/nv/uf/+lf/4t//tz/9599/+/d/96d/ff1p//rd66/fe9RrrX6Nsa+1n/+terVdrtX2VZ5/1jOu1fvzt/s6rV1tzmu0de3nbbNds6/r1HmV2a9en7eXee25r/N8YjnPS55PW8/Lnp/rXa6yytWen8/zbWWNa9/zqs8/R7v59qHX1vv5iOd/ZV39Htec/dfv8vxvPN/Tn+/Zz1A05F36Vce4zppXe/62ar32...
null
2,619
Maximum Subarray Sum
We define the following: - A *subarray* of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0 \le i \le j \lt n$. - The *sum* of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static long maximumSum(List<Long> a, long m)" ], "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 java.ut...
{ "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.math.BigInteger;\nimport java.util.Map.Entry;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n\tlong check(long[] a, long m) {\n\t\tlong ans = 0;\n\t\tint n = a.length;\n\n\t\tfor (int l = 0; l < n; l++) {\n\t\t\tfor (int r = l; r < n; ...
{ "class_name": null, "func_sign": [ "maximumSum(a, m)" ], "solution": "import bisect\n\nt = int(input())\nfor _ in range(t):\n n, m = map(int, input().split())\n a = list(map(int, input().split()))\n\n csum = [a[0] % m]\n for x in a[1:]:\n csum.append((csum[-1] + ...
eJzs3cuuJtmyJWQaNHgM12lXw3369BtPgkRKNOA06CTVOCUhISReiHdkfMOj4OxM7chYa0VWCSlOqfbeEbHW/7vPaddhw8z+r//2f/i//+2/+2/+x//jX/7X3//jf/q3f/nvl3/Zfvt9O8dyH/s8n+3ctmM++2+//8Of5/L9P27Xej77vY+xr899/OHDvvvH8d2PHh/54/d/9yuf/KHv/f4X/en1v3t2H3ql7/9x/9uO44M3+hfC8t1//v43f+yr/kJsv3K4f/7mj2jIlw7wKyryE/Xpr/71S+/wocP9mIb96V4/cnEf++W/uov/Uobh...
null
5,670
Prim's (MST) : Special Subtree
Given a graph which consists of several edges connecting its nodes, find a subgraph of the given graph with the following properties: * The subgraph contains all the nodes present in the original graph. * The subgraph is of minimum overall weight (sum of all edges) among all such subgraphs. * It is also required...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int prims(int n, List<List<Integer>> edges, int start)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nclass Edge implements Comparable<Edge>{\...
{ "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 StreamTokenizer in;\n private PrintWriter out;\n\n private int[] parent;\n private int[] rank;\n\n class Edge {\n public int v;\n public int u;\n public int cost;\n\n public Edge(int...
{ "class_name": null, "func_sign": [ "prims(n, edges, start)" ], "solution": "\nfrom collections import defaultdict\n\nimport heapq\n\n\ndef prim(S, N, G):\n E = defaultdict(int)\n D = {}\n T = [0 for _ in range(N + 1)]\n H = [(0, S)]\n\n for n in range(1, N + 1):\n D[n] = ...
eJx8vcuuLcuSbYUQHzJ1yrcQHhH+4ksQLIkCZIHK4RbySkgIid/gb7HWusfcO/OSHGXuZWOOl48Id3t26/Z//3f/w//zP/63/83/9H/+43/753/+L//6j//+5x/9p11//tl+7p9nv/P5888Sfnobc/755/Pz/qzV1/3nn+9P/3nee6w//+z12r1G5/lez7er8wH10rs/L+LzM+vPvOn+GaOthze1n9Hvi4/6x3/6+ce//B//+V/+l3/9l//1f/7f/8u/npXs9q760n/8X//p52/ra9fPzvrWfJ+W9c09x5P19b6fnvW9r2L/GT/9XqO+...
null
17,276
Minimum Penalty Path
Consider an undirected graph containing $N$ nodes and $M$ edges. Each edge $M_i$ has an integer *cost*, $C_i$, associated with it. The *penalty* of a path is the *[bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR)* of every edge cost in the path between a pair of nodes, $A$ and $B$. In other words, if a ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int beautifulPath(List<List<Integer>> edges, int A, int B)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.Input...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static class Node {\n public boolean visited = false;\n public int penalty;\n ArrayList<Edge> edges = new ArrayList<>();\n }\n\n public static class Edge {\n public Node source, target;\n public int weight;\n\n...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n \n public static ArrayList<Edge>[] graph;\n \n static class Edge {\n public int to,weight;\n public Edge(int to, int weight) {\n this.to = to;\n t...
{ "class_name": null, "func_sign": [ "beautifulPath(edges, A, B)" ], "solution": "def main():\n nvert, nedge = readints()\n edge = [[] for _ in range(nvert)]\n for _ in range(nedge):\n v1, v2, cost = readints()\n edge[v1-1].append((v2-1, cost))\n edge[v2-1].append((v1-1, cost))...
eJyEvUuuNb2yLUQB+rF0yhcp/bZpCRJbogCnQGVzC+dKV0JI9JACHSIdjzHGXGtu0P9JfyxPO54jws5Mp/P/+m//x//n//7v/pv/6f/4t//tn//5v/zHv/0PP/9W6k/Z6x//LM/P/Dm9/OOf5+dtG6NYW/sZT32p8vP+scvzj3+2n/6zz/zHP+dLjD3+8c/+8/663/71dppPf/vX21bfH9fPO7btadzGz67npS7bVS6vt+N81hVaf9rlemX/zH2Zvfos+8m4vuOG8WrRfdRlHN4fb//9Shz3t357lWuJKb1Os5Gv9Fau1u9/rV/F1ksM...
null
71
Crab Graphs
A crab is an undirected graph which has two kinds of vertices: 1 head, and K feet , and exactly K edges which join the head to each of the feet.( 1 <= K <= T, where T is given) Given an undirected graph, you have to find in it some vertex-disjoint subgraphs where each one is a crab . The goal is to select those crabs ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int crabGraphs(int n, int t, List<List<Integer>> graph)" ], "script_name": "Solution", "solution": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class Solution {\n\n\tpublic static void main(String[...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n /*\n * Complete the crabGraphs function below.\n */\n static int crabGraphs(int n, int t, int[][] graph) {\n List<Set<Integer>> adjacency = new...
{ "solution": "import java.util.*;\n\npublic class Solution {\n static class Edge {\n int to;\n int capacity;\n Edge reverse;\n }\n static void addEdge(List<List<Edge>> graph, int from, int to, int cap, int revCap) {\n Edge direct = new Edge();\n Edge reverse = new Edge();\...
{ "class_name": null, "func_sign": [ "crabGraphs(n, t, graph)" ], "solution": "import sys\n\n'''\nhttps://www.hackerrank.com/challenges/crab-graphs\n\nIdea: If flow is sent through the head of a crab the flow will be max. Let's transform the problem to a maximum flow problem.\n'''\n\n__author__ = 'bbyk'\n\n...
eJxrYJnKxgABPUzRsVP0ABkLAyg=
null
57
Repair Roads
The country of Byteland contains $N$ cities and $N - 1$ bidirectional roads. There is a path between any two cities. The roads in Byteland were built long ago, and now they are in need of repair. You have been hired to fix all the roads. You intend to do this by dispatching robots on some of the roads. Each robot will ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int repairRoads(int n, List<List<Integer>> roads)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\nprivate Map<Integer, List<Integer>> roads = new HashMap<>();\n /*\n * Complete the repairRoads function below.\n */\n static int repairRoads(int n, int...
{ "solution": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.*;\n\n/**\n * Created by piotr\n * On 09.11.15\n */\npublic class Solution {\n\n private final Edge[] edges;\n\n public Solution(Edge[] edges) {\n this.edges = edges;\n }\n\n\n public static void main(Strin...
{ "class_name": null, "func_sign": [ "repairRoads(n, roads)" ], "solution": "import collections\nimport queue\n\n\ndef solve():\n n = int(input().strip())\n\n # read graph\n graph = dict((i, []) for i in range(0, n))\n\n for j in range(n - 1):\n x, y = [int(p) for p in input().strip().spl...
eJztnd2qZsd1RUPIg5T7Wphv/9aqPInBx+Qi0UVuOrqQIRAMfog8Wh4oYyyMLVpp0ceR1OdngpjMC50pdZ899q5as779/fmffveb//nHf/j9f33494/f/fH7D/88PmxPH++nj4+xKbtyKKdyPX388M348O1/fvftv37/7b/9y3/88fu//dSHP30zfpDDj97n9pekzaTdpMOk06Rr8N+5x3z6OEc9fayxnj6usT34t/kZf2gbGz+27WPjB7djbPzodo6NH96usfHj2z02ArY5NiK2Ghsh2xo7KTv/+6Ts/Lf9j+9jJ2U/xk7Kfo6dlP0a...
null
2,150
A Chocolate Fiesta
Welcome to the exciting class of Professor Manasa. In each lecture she used to play some game while teaching a new concept. Today's topic is Set Theory. For today's game, she had given a set _A = {a<sub>1</sub>, a<sub>2</sub>, ...a<sub>N</sub>}_ of _N_ integers to her students and asked them to play the game as follows...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> a)" ], "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.InputMismat...
{ "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.*;\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 in = new Scanner(System.in);\n int N = in.ne...
{ "class_name": null, "func_sign": [ "solve(a)" ], "solution": "mod = 1000000007\n\nn = int(input())\nA = list(map(int, input().split(\" \")))\n\nodd = len([x for x in A if x%2==1])\neven = n - odd\n\nif odd == 0:\n odd =1\n\nprint((((2**(odd - 1)) % mod) * ((2**even) % mod) - 1) % mod)", "template": "#\...
eJzs/TuudU+yHHiW0ErNYiPlK6xHrBdH0kAlQIFMgUryCnkBAgSBGljPoifU9rP4CBSQSKH1SC8W//zOOXuvR4SHu7m5+f/9//p//3/+v//n//F//c+//Le///t//OMv/+n3l/evf7/P8d33c5+/87j34z6O7Xe/+3Zf2/78vuu7t+fafud2bc95v/mv83qP4zqv39jO/XrG/f6e/T2fsV/XX/7t95e//Y9//9t/+cff/ut//u//8Y8/37Mfz1///pf/9W+//8d373/9+/4vfn3751/e/O+vf99+y5YtW7Zs2bJly5YtW7Zs2bJly5Yt...
null
4,732
Pairwise Sum and Divide
You are given an array of numbers. Let us denote the array with $A[]$. Your task is very simple. You need to find the value returned by the function $\text{fun}(A)$. fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(List<Integer> a)" ], "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.InputMismat...
{ "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 PSAD {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\"...
{ "solution": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Solution {\n\n void solve() throws IOException {\n int t=nextInt();\n while(t-->0){\n int n=nextInt();\n long one=0;\n long two=0;\n for(int i=0;i<n;i++){\...
{ "class_name": null, "func_sign": [ "solve(a)" ], "solution": "def f(a):\n n = len(a)\n ones = a.count(1)\n twos = a.count(2)\n s = sum(a) - ones\n return ones * (ones - 1) // 2 * 2 + ones * (n - ones) + twos * (twos - 1) // 2\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n ...
eJw83UuubU2SFGAaDGRTXYS0Yr1iBSNBoiZAJ0UDWnQYOvZZnB9VqvLmPffsvR4RHu7mZub/9z/+t//0n//Lf/jv/+ff/se//uf//l//9l9//3b/+7/GO//9X993vM+zjuP3fe/xfPPOn97zeMa3vt91Hm/+x5q/Nb6x5nfM37WeZ67jun/nMdd9nit/WseY1/jm7z3mvN/3Pn/3+13rfdf1y4/ekQ9Zv/s4nnmfz/Mb13Vfx/Mcv3V97zWfOz997+8dM//u/PL51/m8+bzrOeeY3++dVz74Xecv3zPWWnP83uf9vvM6vt+z7mPkWq9c...
null
13,579
Arrays - DS
An *array* is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, $A$, of size $N$, each memory location has some unique index, $i$ (where $0 \le i \lt N$), that can be referenced as $A[i]$ or $A_i$. Reverse an array of integers. **Note:** If you've alrea...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> reverseArray(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 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.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int length = sc.nextInt();\n int[] array = new int[length];\n for (int i = 0; i < length ; i++) {\n array[i] ...
{ "class_name": null, "func_sign": [ "reverseArray(a)" ], "solution": "n = int(input())\nm = input().strip().split(' ')\nres = m[::-1]\nr=\"\"\n\nfor i in range(n):\n r = r + str(res[i]) + \" \"\n \nprint(r)\n", "template": "#\n# Complete the 'reverseArray' function below.\n#\n# The function is expe...
eJztvU2uNcuSpgUSAwnddgmFe/ifMQGmgMRFNCAbdC7VyJJKQiUxCGbFpPDnMV8BeVQnq1Gisioz7tZd+zt771grwt1+XnvN3Oz//G/+h//7v/+v/6v/8f/4y//2t3/9b/7+L//d9Zf517+VMa+24rnG/czrKfO5WqvrijrbNUtbf/3bX/7V9Ze/+7f/+u/+l7//u//1f/7f/83f/y7ev8w/8wIv9U18u/2+f/l3/+r6/3zY89e/jVKeq97PuOYd7c/fef8y/4wL/vA2/a9/i1ruq64+r7hHu557lKuv0v/0Dfll/pkX5KX7Tf7w1iX2...
null
22,538
Left Rotation
A *left rotation* operation on an array of size $n$ shifts each of the array's elements $1$ unit to the left. Given an integer, $d$, rotate the array that many steps left and return the result. **Example** $d=2$ $arr = [1, 2, 3, 4, 5]$ After $2$ rotations, $arr' = [3, 4, 5, 1, 2]$. **Function Description** ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> rotateLeft(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...
{ "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 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 Scanner scanner = new Scanner(System.in);\n ...
{ "class_name": null, "func_sign": [ "rotateLeft(d, arr)" ], "solution": "n, d = map(int, input().split())\narr = [int(x) for x in input().split()]\n\nfor i in range(d):\n arr.append(arr[i])\n \nfor x in arr[d:]:\n print(x, end=' ')", "template": "#\n# Complete the 'rotateLeft' function below.\n#...
eJztncsOJVt2VUGiyz+Eqo3Qfj/4EiQuogFu0Lm4YUtIyBIfwSfyIYwxIxvWLSdG2AXlqrDkyLqZJ86J2Hvtteaa6/Xf/8W//Z//8p//s3/33373n3/9y7/+q9/9m+d3daz7cFm//LpGP308567ey7PnOvPp54zCB0rtsz6j9XHrU9sq6zxz7drKc87dvT+71Fnbc0dpc/NvfZT9rLtqf2YbY8xnlNpme9qYY7fn7DX5jjJL5eO1l7WeNbZfwffzhXPzc+u5a/PLfnjxNPzZn1t4Hh9j7HufOepe5emrl7GezT+29qx+y97PqWvN8lSe...
null
33,183
Game of Two Stacks
Alexa has two stacks of non-negative integers, stack $a[n]$ and stack $b[m]$ where index $0$ denotes the top of the stack. Alexa challenges Nick to play the following game: * In each move, Nick can remove one integer from the top of either stack $a$ or stack $b$. * Nick keeps a running sum of the integers he removes f...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int twoStacks(int maxSum, List<Integer> a, List<Integer> b)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * @author Aydar Gizatullin a.k.a. lightning95, aydar.gizatullin@gmail.com\n * ...
{ "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.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\ni...
{ "class_name": null, "func_sign": [ "twoStacks(maxSum, a, b)" ], "solution": "#!/bin/python3\n\nimport sys\n\n\ng = int(input().strip())\nfor a0 in range(g):\n n,m,x = input().strip().split(' ')\n n,m,x = [int(n),int(m),int(x)]\n a = list(map(int, input().strip().split(' ')))\n b = list(map(int...
eJzsvcuqbUuXnWewwa8x+csqxP2iJzH4gApSFlQ5ViEFAiHwo/v7WuwfG4T8AhqZUp4x9l5rzjEi+qX11luP/X//b//H/97/1//l//yv//iPf/+n//yv//i3v3+sv/6uv/Hro57W7p1//T1Oq7389fcq44z1G7vfUX5rlzXXb5825vnr7z1//L+7d6239/3X3/e2Xn6j3XMqP7UXv9p33ff+epmt3t/ofF77nbprn7+2Tr/9d/ucZf7OXbXUX+/3lv7rq8x9+ck2W/utNfi83663lfGbre9yfv0cfnCPsv3W0ndvv3nP4EkHj7CXzzZ4...
null
15,512
Waiter
You are a waiter at a party. There is a pile of numbered plates. Create an empty $answers$ array. At each iteration, $i$, remove each plate from the top of the stack in order. Determine if the number on the plate is evenly divisible by the $i^th$ prime number. If it is, stack it in pile $B_i$. Otherwise, stack it...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> waiter(List<Integer> number, int q)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Wai...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static Stack<Integer> data;\n private static Stack<Integer> div_stack;\n private static Stack<Integer> non_div_stack;\n \n public Solution(int[] raw_data){\n data = new Stack<Integer>();\n div_stack...
{ "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 q = sc.nextInt();\n ArrayDeque<Integer> nums = new ArrayDeque<Integer>();\n boolean[]...
{ "class_name": null, "func_sign": [ "waiter(number, q)" ], "solution": "def Primes(q):\n i = 2\n result = []\n n = 1\n while len(result) < q:\n n += 1\n while i < n:\n flag = True\n for item in range(2, int(i**0.5)+1):\n if i % item == 0 and i ...
eJzsvbvOLcuSXidDjt5i4tg0Km510ZMI0AZokG3IOaTRBAgIAmTrqZVjZM291jnsFgmQTcr4gT1r/2vWLTMjMytqzIwv/u//+X/7f/7t//I//e//51/+j7/++//wj3/5Xz9/Oev5XH3/8dfz6Pnc93xijvMTx31/np7nc/axjqjrc8Wz9t/x6TzPz33m/TnjXJvnOj/XHednuo7PHOv4PJ/j88SVn+fp65PXuvacx7rIPOvgp+Iz1eu6x7lueq5Drq751H3Xul6e69YPO9ZFu6/rc84Vn7tyFWcoyqxb1jn9uefmtvnJiHWLZ6514ahP...
null
1,058
Cube Summation
[Chinese Version](https://hr-testcases.s3.amazonaws.com/1058/1058-chinese.md)<br/> [Russian Version](https://hr-testcases.s3.amazonaws.com/1058/1058_rus.md)<br/> Define a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinates (1,1,1) and the last block is defined by the coor...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> cubeSum(int n, List<String> operations)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.i...
{ "solution": "import java.util.Scanner;\n\npublic class CubeSummation {\n public static void main(String[] args) \n {\n Scanner s = new Scanner(System.in);\n int g = s.nextInt();\n for (int e = 0; e<g; e++)\n {\n long Sum = 0;\n int c = s.nextInt();\n ...
{ "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport ja...
{ "class_name": null, "func_sign": [ "cubeSum(n, operations)" ], "solution": "import sys\n\nfor t in range(int(sys.stdin.readline().strip())):\n n,m = [int(x) for x in sys.stdin.readline().strip().split(\" \")]\n nonzero = {}\n for i in range(m):\n parts = sys.stdin.readline().strip().split(...
eJzsvdvKNV2TJSTihSzquBfM/cYzwT5XsUGxwAPtA0/KPqgGQQSvznvwbowxYmbmiHye/+tqkd7gW99T/8p3bTLnJmbsY8T/+Z/9d//3//Wf/if/w//+d//LP/yrf/2Pf/eff/6u/v0/5P7p6+//4b/+F//8v/nvP+VTP/2zPjl/xvUe/l0+2f7aZ//9P/yL/+q//C/+23/+yfWzP+NTVkt59Tavb9vt8NXEi2Y3uj+wW0+7Vf/M+yZ4x770nWXVVPqo9yf4XrcPxrb/G/P5YODe5fPNqZa267yHvu0/H6ZN4f56wxM+377SqqtnHb6P...
null
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
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
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
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
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
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
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
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