question_id
int64
39
56.8k
question_title
stringlengths
3
54
question_content
stringlengths
88
4.02k
dataset
stringclasses
1 value
difficulty
stringclasses
3 values
java
dict
java15
dict
java8
dict
python
dict
test_cases
stringlengths
28
4.02M
max_retries
float64
1
3
⌀
3,434
Find the Seed
A company needs random numbers for its operation. $N$ random numbers have been generated using $N$ numbers as seeds and the following recurrence formula: $$F(K) = ( C(1) \times F(K-1) + C(2) \times F(K-2) + \cdots + \\C(N-1) \times F(K-N+1) + C(N) \times F(K-N) )\ \% \ (10^9 + 7)$$ The numbers used as seeds are $F(...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> findSeed(int k, List<Integer> f, List<Integer> c)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class Solution {\n\n public static final int MOD = 100000000...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\nprivate static InputReader in;\nprivate static PrintWriter out;\npublic static long mod = 1000000007;\n\npublic static long inv(long N, long M) {\nlong x = 0, lastx = 1, y = 1, lasty = 0, q, t, a = N, b = M;\nwhile (b != 0) {\nq = a / b...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static long mod = 1000000007;\n \n public static long inv(long N, long M) {\n long x = 0, lastx = 1, y = 1, lasty = 0, q, t, a = N, b = M;\n while (b ...
{ "class_name": null, "func_sign": [ "findSeed(k, f, c)" ], "solution": "#http://stackoverflow.com/questions/24701490/modular-matrix-inversion-with-large-number?lq=1\nMOD = 1000000007\n\ndef generalizedEuclidianAlgorithm(a, b):\n if b > a:\n return generalizedEuclidianAlgorithm(b,a);\n elif b =...
eJzVmsuuZEcRRRnwIak7YmChfEU++BIkGjEAD5hcGNgSErLEiBkz+F/WirJp29XFQ+IhuiV3+d4652RG7Nh7R+T5ww//8qcf/SD//PSPfPjZ799+/f7bL794+0l5a7ucNSJOOx/e49axzoxZ5h191Thlr83/n8mnOqLdvqP45TnuGWWuutuptdxYc3H5Kf2MWG3GLffWxRf7LG3HOXXUXkbfffYerWzu12pELbHnXjPW5saDp40a5bIkrh+79Bn1tFinxGjR56ntw/uad98b3OaePu/cPG3tO/tavfDdPVur7CLqZF2s74x2bp+NbbAv...
null
2,562
Best spot
In Chile, land are partitioned into a one large grid, where each element represents a land of size _1x1_. <br> Shaka is a newcomer in Chile and is trying to start his own business. He is planning to build a store. He has his own ideas for the "perfect store" which can be represented by a _HxW_ grid. Element at positi...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static void bestSpot(List<List<Integer>> heights, List<List<Integer>> store)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.Big...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static void bestSpot(int[][] land, int[][] store, int r, int c, int h, int w) {\n long sumDiff = 0;\n int m = r - h;\n int n = c - w;\n long minSum = Integer.MAX_VALUE;\n int minCol = n;\n int minRow = m;\n for ...
{ "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\tstatic InputStream is;\n\tstatic PrintWriter out;\n\tstatic String INPUT = \"\";\...
{ "class_name": null, "func_sign": [ "bestSpot(heights, store)" ], "solution": "import itertools\n\ndef initSquareCache():\n return list(i ** 2 for i in range(41))\n# heightSub = R - H + 1\n# widthSub = C - W + 1\ndef enhancedDiff(purchasedLand, H, W, perfectStore, heightSub, widthSub):\n squareCache ...
eJy8vcuuLsuSrAUSDxKqNr+UcY/gSZAoiQacBp0CoYOEhJB4SB6ImWGfeeTc1D7SaYBqrVV7jPFfMuPibm5mHvl//Vf/7f/9v/6X/8V/93/8y//0b//L//Yf/+W/Sf/S0vjXf6vpt9KvpjzSTL/8nN/k+v7QUu6p/PnNb6e83x/+/I/y56/9X//tzytGyjPl9+fnz7/5z+9S/fPa91PGnw/913/7l/86/ct/+N//l//wP/zH//A//vf/8//2H/navPb72vwv/+d/nT5XU9935z9v/vNN5V//7c9HlOf9989H/vmCP1/1O2/786ff+53t...
null
19,130
Super Kth LIS
Given an array of $N$ integers ($a_0, a_1, \ldots, a_{N-1}$), find all possible increasing subsequences of maximum length, $L$. Then print the lexicographically $K^{th}$ longest increasing subsequence as a single line of space-separated integers; if there are less than $K$ subsequences of length $L$, print $\texttt{-1}...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> superKth(long k, 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 ...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\n\npublic class E {\n InputStream is;\n PrintWriter out;\n String INPUT ...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\"...
{ "class_name": null, "func_sign": [ "superKth(k, a)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\nfrom collections import defaultdict\n\n#\n# Complete the 'superKth' function below.\n#\n# The function is expected to return an INTEGER_ARRAY.\n# The functi...
eJztnc2uLUdynQ3YD7LBccuo/KvM1JMYMA0NpB54QvWADQgwBPgd7Hf11Pl9kftKMKFGE57YQFhcbfLec/auysqMnxUrov77f/hP/+t//Pt/95//20//9Zc//fnXn/7289P+9LeW2dfesz77rf3pP/9SP+vTPvtTPu9nfvqn/vzLT3/4/PTHf/rTH//+1z/+w9/9459/vb//N+Wnf/7D5199YP3U3vbTS597n39p/Tm/XT7lr/+I+Vl77jVaq/tdb6ttLD6in+sZYvz1H/aeu3jWbuXd9dxgre+o+9zhOB/Xns84H8cafF7us4xPfT91...
null
20,981
Counting the Ways
Little Walter likes playing with his toy scales. He has $N$ types of weights. The $i^{th}$ weight type has weight $a_i$. There are infinitely many weights of each type. Recently, Walter defined a function, $F(X)$, denoting the number of different ways to combine several weights so their total weight is equal to $X$. W...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int countWays(List<Integer> arr, long l, long r)" ], "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 v...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int MOD = 1000000007;\n \n static int N;\n static int[] arr;\n static List<Integer> listS;\n static int[] pSum;\n static int[] frec;\n ...
{ "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 F {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tint mod = 1000000007;\n\t...
{ "class_name": null, "func_sign": [ "countWays(arr, l, r)" ], "solution": "MOD = 10**9 + 7\n\ndef lcm(lst):\n ans = 1\n for x in lst:\n ans = ans*x//gcd(ans, x)\n return ans\n\ndef gcd(a,b):\n if a<b:\n a, b = b, a\n while b > 0:\n a, b = b, a%b\n return a\n\ndef gets...
eJyVlM1KHUEQhbOQPEcxu4BI13+1TyI44iK5i2wmLq4giOBD6Pta9+bHG3tqSHpgGJrpj1NV5/Tz2Wv7/Om4rr7kx/Xj9H25u99PlzDFvGA7LMDTZ14s9xwhzBr26Rym3cPd7ut+9+32x/3+12EkVxUym5fp6RxOsLmj8OeZl85BooCOzhIFjrora+M24LCty/wp1aOLESB2ROECzozITUgHuPzNTrEEZFiJjO5Bo8ReKcx9cuAaqElUERyQfIrMb1XI3wpMaCCvN26tZ/lqH1c1ZZcW3Hmc8vZYsLmHQldisYItzi2HxzSw6R19mDAQ...
null
22,736
Hard Disk Drives
There are $n$ *pairs* of hard disk drives (HDDs) in a cluster. Each HDD is located at an integer coordinate on an infinite straight line, and each pair consists of one *primary* HDD and one *backup* HDD. Next, you want to place $k$ computers at integer coordinates on the same infinite straight line. Each *pair* of HDD...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int hardDrive(int k, List<List<Integer>> hdds)" ], "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 HD[] hdds;...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static class Pll {\n long fi;\n long se;\n\n Pll(long fi, long se) {\n this.fi = fi;\n this.se = se;\n }\n \n Pll() {}\n }\n \n static long[] xs;\n \n static int lowerBound(long[] arr, long key) {\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static class Pll {\n long fi;\n long se;\n\n Pll(long fi, long se) {\n this.fi = fi;\n this.se = se;\n }\n \n Pll() {}\n }\n \n static long[] xs;\n \n static int lowerBound(long[] arr, long key) {\n ...
{ "class_name": null, "func_sign": [ "hardDrive(k, hdds)" ], "solution": "from copy import copy\nfrom operator import itemgetter\n\nap = [] # all points, sorted, no duplicates\nroots = []\nsaved_cost = dict()\n\n\nclass CostTree:\n def __init__(self, lower, upper):\n self.lower, self.upper = lowe...
eJw0vUmOBVmyZEeAXEAtwfDnDlyz29dKCmBsgJMEB+SoJrUB7plyjr7AbzLSw/09s9toIyoq+r/+j//xv/9//+1/+z//53/9X//5v//f/+e//vvzX3f3/cx//jPube379nz+xjpr9rH/+c+dvZ/vnc/t6+t3jH/+8/fOdb6z53jy/7/Z37v++c9cvY/z3u/566d9fb/75Xf3yQ/zX56/94zW35UP/cunf986ez1/s39ttzUWDzD3/HY7z7ptfvN+J7+7v/fb62vt2We99+7x8Qk9H9bmmM84+133fjxZ/nz197v72WPdPvLQ/u6678gH...
null
915
Lonely Integer
Given an array of integers, where all elements but one occur twice, find the unique element. **Example** $a = [1, 2, 3, 4, 3, 2, 1]$ The unique element is $4$. **Function Description** Complete the *lonelyinteger* function in the editor below. lonelyinteger has the following parameter(s): - *int a[...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int lonelyinteger(List<Integer> a)" ], "script_name": "Solution", "solution": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\n\npublic class Solution{\n public s...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) \n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt(),result=0;\n for(int i=0;i<n;i++)\n {\n result^=s.nextInt();\n }\n System.ou...
{ "class_name": null, "func_sign": [ "lonelyinteger(a)" ], "solution": "n=int(input())\na=list(map(int,input().split()))\nr=a[0]\nfor i in range(1,n):\n r=r^a[i]\nprint(r)", "template": "#\n# Complete the 'lonelyinteger' function below.\n#\n# The function is expected to return an INTEGER.\n# The functi...
eJyVVjuOHTcQVOBMl2i8WBDY7OZPF1Cm2ICf4cDewMmTghVgwBDgQ1j3VVVxAmGkCXZBzPKR7F9Vd5P//fL1w+tX+vv1PSa//Xv7+/Hp8/Ptnd1m3B9eLIa1Zn1YLdabpduytJXWsOQWrg18BxdHteE2G3c5WRbVVqUK6JphRWtBtSO42dLqsjYplMsGdEgfbEEZTi4an9V658CeVdifFIc+msVe2uymD3a2SiibzoHN7PS1B3VDGkEMLTpEqRtRwIOOiG9v7Pb0z6enP5+f/vrj4+fnAwyvty9v7Dt0wu+PPhlGQrBYC8NPmMJgeIte...
null
16,469
Xor-sequence
An array, $A$, is defined as follows: * $A_0=0$ * $A_x=A_{x-1} ⊕ x$ for $x>0$, where $⊕$ is the symbol for [XOR](https://en.wikipedia.org/wiki/Exclusive_or) You will be given a left and right index $l \ r$. You must determine the XOR sum of the segment of $A$ as $A[l]⊕A[l+1]⊕...⊕A[r-1]⊕A[r]$. For example, $A=[0,1...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static long xorSequence(long l, long r)" ], "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.InputMismatchExc...
null
{ "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.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOExcep...
{ "class_name": null, "func_sign": [ "xorSequence(l, r)" ], "solution": "#!/bin/python3\n\nimport sys\n\ndef x(a):\n res = [a,1,a+1,0]\n return res[a%4]\n\ndef y(a):\n if a%2==0:\n return x(a//2)<<1\n else:\n r = 0\n if (a+1)%4==2:\n r =1\n return((x(a//2)<...
eJytnU+uNUGO1RmwkFSNWyjjfyQrQaIQA+gBk6YH3RISaolFwA5ZAzMkfM5xOnzfu18LJIpq6vp++fJGRoQdP9uRjv/2L//H//6f/4L/+Tf/yz782//6l//0d3//j//wl399/aX0v/7dmq3OvWbdtfZxveJ+yrPsn+sYdfYy1hz308oV8qp97vHXv5v9Ga3eY8xR7nterzzrU2u9//p3u/XW6z3Hvntb1yvOds817e/ruOsznn7P1vclcd7Vvhv2+0+zvxrjmW3Np4wr5Nn25gVrdrv3tObaD9sFLldr/lzWwP3s+qA9d7H29CvkPutC...
null
1,148
Xoring Ninja
An [XOR](https://en.wikipedia.org/wiki/Exclusive_or) operation on a list is defined here as the *xor* ($\oplus$) of all its elements (e.g.: $XOR(\{A, B, C\}) = A \oplus B \oplus C$). The $XorSum$ of set $arr$ is defined here as the sum of the $XOR$s of all non-empty subsets of $arr$ known as $arr'$. The set $arr'$ ca...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int xoringNinja(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic ...
{ "solution": "import java.math.BigInteger;\nimport java.util.*;\npublic class Solution {\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int t=in.nextInt();\n for(int j=0;j<t;j++){\n BigInteger res=new BigInteger(\"0\");\n int n=in.nextInt();\n ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class Solution {\n static final int mod = 1000000007;\n \n public static void main(String[] args) {\n InputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in ...
{ "class_name": null, "func_sign": [ "xoringNinja(arr)" ], "solution": "import sys\n\ndef poweroftwo(n):\n\tval = 1\n\tyield val\n\tfor i in range(n):\n\t\tval *= 2\n\t\tyield val\n \n\nr = sys.stdin.readline\n#table = list(poweroftwo(100000))\ntext = r()\nt = int(text)\nfor i in range(t):\n\ttext = r()\...
eJzs/cvKZM26LGYKoQsJVlsFPg4+hg9dSUFNqIa0G+r8pcYWCIoC3bW6ssc8VyHQXhcgkXMdMmbm90WM8MN7NLP3f/1v/p//j//tv/6v/l//33/7H//5n/7n//xv/93v3+a//jnuf/0zx3l+1zqO3/vM7zvec/zeY3zfdd7377rPe77j+j1jXO+8vuv3rfe973Gs33Wc17rf9cs7vOObfv5Z68ybPL+Vv3nHkR+b8z3v78h7vOvJRz33773m9d7fdf/Wc53Xkdd5Go9zP/mUdzzjt+aR93jW+1v38Y51jvn73rz1cTznb43nucd9z9/x...
null
2,326
Cipher
Jack and Daniel are friends. They want to encrypt their conversations so that they can save themselves from interception by a detective agency so they invent a new cipher. Every message is encoded to its binary representation. Then it is written down $k$ times, shifted by $0, 1, \cdots, k-1$ bits. Each of the colum...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String cipher(int k, String s)" ], "script_name": "Solution", "solution": "import java.io.*;\n\npublic class Solution {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int k = in...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String[] line = scanner.nextLine().split(\" \");\n int n = Integer.valueOf(line[0]);\n int k = Integer.valueOf(line...
{ "solution": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.*;\n\n// https://www.hackerrank.com/contests/w10/challenges/alternating-characters\npublic class Solution {\n\tprivate static final int mod = (int)1e9+7;\n\n\tfinal Random random = new Random(0);\n\tfinal IO...
{ "class_name": null, "func_sign": [ "cipher(k, s)" ], "solution": "n, k = map(int, input().split())\ns = input()\nans = []\npref = 0\nfor i in range(n):\n val = pref ^ (ord(s[i]) - ord('0'))\n ans.append(val)\n pref ^= val\n if i >= k - 1:\n pref ^= ans[i - k + 1]\nprint(''.join(map(str,...
eJzsvcHObct1XpdGOunlES7UdqOKFiUxTxIgBNJI1EiHcUMGDAQB8oR5pojkmWOMWftQSiI5Cs297jn/v/datWbN+X3jK16bsPl//Nf//f/53/43/9X/8L/91f/yu//wH//hr/67X/7qb3/5m/vb3517/qXXb3/3V//ul7/6+//0H/7+f/qHv/+f/8f/9T/+w48dzr0/nv/v/+6X7Pzrc3751a9/9dvf3e/1F3f9i3H7873+ZFD+kkX5S53941T8RyF++fXv79/zn/+f7/UXd/3p0+f/g+uT9r/9u/vLb/76/gH375/vn++f75/vn++f...
null
13,530
What's Next?
Johnny is playing with a large binary number, $B$. The number is so large that it needs to be compressed into an array of integers, $A$, where the values in *even indices* ($0, 2, 4, \ldots$) represent some number of consecutive $1$ bits and the values in *odd indices* ($1, 3, 5, \ldots$) represent some number of conse...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static void whatsNext(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String...
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimp...
{ "class_name": null, "func_sign": [ "whatsNext(arr)" ], "solution": "T = int(input())\nfor t in range(T):\n N = int(input())\n A = [int(x) for x in input().split()]\n if N == 1:\n A = [1, 1, A[0] - 1]\n elif N == 2:\n A = [1, A[1] + 1, A[0] - 1]\n elif N & 1:\n A.append(1)\n A...
eJytmE1uJEUQhVlwBtYpr0coMyP/gpMgYcQCZsHGsJiRkBASV0ACiePyRURVd7vpatsDZc/Y7q7MjHjx4sWr/v3zv/7+4jO/vv6DX7759eHHp58/fnj4Kj3Mx6fy+LR0jLken8bjUx+p8vsoWVdaJZWyNIvU1lLpvDyKlpm0Pz6xtM7E63WVOdJceehMq6eyZh/CypLF9s8ckIeU0uy2JquN1GrNM9U6ltY0c62tplJHz3WKnSqjzJWkS1utsqeuUlNTyWVInx6prRBO5iViliSrs4hdZssWOqdyU+PvwntFl6S+pKumQjRztllrIopV...
null
16,865
A or B
Consider four numbers: $A$, $B$, $C$, and $K$. You must change *at most* $K$ bits in $A$ and $B$ to form the numbers $A'$ and $B'$ satisfying the equation $A'\ |\ B' = C$. Here, the | symbol denotes the *bitwise OR* operation. Given $Q$ sets of the numbers defined above, find and print the respective values of $A'$ a...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static void aOrB(int k, String a, String b, String c)" ], "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.Decimal...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n static byte[] hexStringToByteArray(String s) {\n int len = s.length();\n int bl = len/2;\n if(s.length()%2==1) bl++;\n byte[] data = new byte[bl];\n for (int i = 0; i < len/2; i += 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.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimp...
{ "class_name": null, "func_sign": [ "aOrB(k, a, b, c)" ], "solution": "Q = int(input())\nfor _ in range(Q):\n k = int(input())\n A = bin(int(input(), 16))[2:]\n B = bin(int(input(), 16))[2:]\n C = bin(int(input(), 16))[2:]\n \n l = max(len(A), len(B), len(C))\n A = list('0' * (l - len(...
eJztvUvObkuSpkWDgaSinYX8fqHnl7XGgMRGNCAb1dlUI0tCKpXEIGAOjIMes+J51qlClYo4QUVmZEol9onLidjn/79vLXez197X3Mz8f/uv/4//+//8r76//rv/i//x3/+7P/zrn//m3/79H/7bv/lD+vGz9JJj/vFzjxBaGT2Fwh/y1/PsEUOYe9x9d30Sf753iKWW294WYnhbeWaZfca31xZzeJ8fP3PI/NaPnzXH9tz67rF6nanUft52nne2MVJaOc1aAv+73TVKWaW9Nz53v3XEp54Qn6fnO/Z8z4+f52mz3tYi/yDVskLlmeOJ...
null
77
Changing Bits
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: - `set_a idx x`: Set $a[idx]$ to $x$, where $0 \leq idx \lt n$ and $a[idx]$ is $idx^{th}$ least significant bit of $a$. - `set_b idx x`: Set $b[idx]$ to $x$, where $0 \leq idx \lt n$ and $b[idx]$ is $idx^{th}$ lea...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static void changeBits(String a, String b, List<String> queries)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\n // leave empty to read from stdin/s...
{ "solution": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class ChangingBits {\n \n public static void main(String[] args) throws IOException {\n final int N = IOFast.nex...
{ "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 int n = in.nextInt();\n int q = in.nextInt();\n char[] a = new StringBuffer(in.next()).reverse().toString().toCharArray(...
{ "class_name": null, "func_sign": [ "changeBits(a, b, queries)" ], "solution": "n_bit, line_count = [int(i) for i in input().split()]\na = int(input(), 2)\nb = int(input(), 2)\n\nfor i in range(line_count):\n inp = input().split()\n x = int(inp[1])\n \n if inp[0] == \"get_c\":\n print(( ...
eJzsvduOJUu2XCdA+pBCP/PBL3HVlwhQA0Rt6kDQS4sADwEBggB9lD5QlVlrmg2LiKzdddjUIalVtXfWylgR7vNiNn36Jdz/7//hf/p//um//+/+5//zL//b3/79f/znv/yP3/6yrt/G2P/6t/Yv+/Of8OD/+k///G//3bd1++vf/sOPT3982751f2y/d/Ve1m8WgKtvud5yveV6y/WW6y3XW663XP9/lesv/+bbX/7p//j3//Tv/vmf/pd/+7//x39+JYx/mtn95f/6N9+QYJ7bdnwbP8rrvbUf/33+//rnx6X6+/PK69Pnx7r/877u...
null
2,056
Mixing proteins
Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called $A, B, C, D$ (you know, protein names can be very complicated). A ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String pmix(String s, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\n\npublic class Solution {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt(), k = in.nextInt();\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.*;\n\npublic class Solution {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt(), k = in.nextInt();\n int[] a = new int[n];\n char[] c = in.next().toCharArray();\n for (int i = 0; i < n; ++i) {\n a...
{ "class_name": null, "func_sign": [ "pmix(s, k)" ], "solution": "# A = 0 (0b00)\n# B = 1 (0b01)\n# C = 2 (0b10)\n# D = 3 (0b11)\n# a[x + 2^m, i] = a[x, i] ^ a[x, i + 2^m]\n\nimport sys\n\nc2i = {'A': 0, 'B': 1, 'C': 2, 'D': 3}\ni2c = ['A', 'B', 'C', 'D']\n\nn, k = [int(x) for x in input().strip().split()]\...
eJzsvcuuLUlypqeBXkHzRE5Vg7zUlTM3s4cQoAIIiKwBJ8kaVAEECAJ6dO3w77NYpwsqNbon6iZ+s1yZ5+zLWhHu5mb/Jcj6v//X/+P/+t//t//l//z37//llz//9S/f/8N33//408+//s13999//OVUMplMJpPJZDKZTCaTyWQymUwmk8lkMplMJpPJZDKZTCaTyWQymUwmk8n/tPnHX77/1Xff/+nf/vynf/rLn/75H//1r3/x/7ygDvHf+99EIpFIJBKJRCKRSCQS/+NH+H8ikUgkEolEIpFIJBL/+SP8P5FIJBKJRCKRSCQSif/8...
null
16,694
Simplified Chess Engine
Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as [Stockfish](https://stockfishchess.org/) and [Komodo](https://komodochess.com/) to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ideas and algori...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static String simplifiedChessEngine(char[][] whites, char[][] blacks, int moves)" ], "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 p...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static class Feature {\n public int Qi;\n public int Qj;\n public int qi;\n public int qj;\n public List<int[]> wpieces = new Ar...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n static class Piece {\n char type;\n boolean isWhite;\n \n Piece(char type, boolean isWhite) {\n this.type = type;\n this.isWhite = isWhite;\n }\n }\n \n static ...
{ "class_name": null, "func_sign": [ "simplifiedChessEngine(whites, blacks, moves)" ], "solution": "N = 4\nD = ((1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, 1), (-1, -1), (1, -1), (2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1))\nFIGURES = \"QNBR\"\nRANGE = ((0, 8), (8, 16), (4, 8),...
eJylVT1PwzAQZUD8DstzheSPdGCLHVajlAVEEQNkYAkdUgkJIfEj4L+ywdl3dhzaghyyOHaV997de+e+HX98nRyF5+oTXm5e+GO/2Q78jHGx7jWTDJYVa5ha9waWsKuZXPctLMIfWqZxBwtfMN49b7r7oXu4e9oOBHV9fslfF2wKXgF4hV8qxFEe3ERUiTs4dMg/g0MxwZYJwCAV4bRwWAgnWIUAoWY39iMoD5IdSA7gQXmZVo19bWLPZUL1jZDYFoHgAn87zOEudik06BcoXKcyyM+MkFoVSrSoyWY5KCAEOu9xikyDdhpUYTNeikGZ...
null
21,906
Nimble Game
Two people are playing Nimble! The rules of the game are: - The game is played on a line of $n$ squares, indexed from $0$ to $n-1$. Each square $i$ (where $0 \le i \lt n$) contains $c_{i}$ coins. For example: ![nimble.png](https://s3.amazonaws.com/hr-challenge-images/18624/1457422376-06a45e063f-nimple.png) - The pla...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String nimbleGame(List<Integer> 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//Day 2: Nimble Game\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 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 s=new Scanner(System.in);\n int t=s.nextInt(...
{ "class_name": null, "func_sign": [ "nimbleGame(s)" ], "solution": "test = int(input())\nfor _ in range(test):\n n = int(input())\n ar = list(map(int,input().strip().split()))\n #print(n,ar)\n result = []\n for i in range(len(ar)):\n result.append(ar[i]%2)\n #print(result)\n xor...
eJztmE9uJscNxbPIEXKAgtZGUGSxSJYPkAt4EyAKsrBn4c1nIxkDBgwDOYRzluxytvxef8ofWCNL4/VoMepRd1cVycfH9/rvv/3Hv373m+vnj//k4k8/PHx9+/a79w+fjwd/vNl8vNWs1T5njvQ6Oz1qdM5dNruGu/maZ+9xfKbNFXN0R8c+Z4+eYba3m65Odfke2b3SdvXovdxjrXi8tfbJdXqtOcJ5qfaJsbJZJytHWSzzyBrL7Fjt4q4vq5URrO61LHJYc3PWZsmHz8bDu++/fffl+3df/eWb794/RfWHr//6t/ePt6dfDz9+Nv4v...
null
22,357
Zero-Move Nim
> [Nim](https://en.wikipedia.org/wiki/Nim) is a famous game in which two players take turns removing items from $n$ distinct piles. During each turn, a player must remove one or more items from a single, non-empty pile. The winner of the game is whichever player *removes the last item from the last non-empty pile*. Jo...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static char zeroMoveNim(List<Integer> p)" ], "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.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//...
{ "class_name": null, "func_sign": [ "zeroMoveNim(p)" ], "solution": "from itertools import *\nfrom operator import *\nfrom functools import *\nfor _ in range(int(input())):\n input()\n print(\"W\" if reduce(xor, [x + 1 if x & 1 else x - 1 for x in map(int, input().split())], 0) else \"L\")", "templ...
eJy1mM9uH8cRhHPIM+Q84FkI5k/3dLefwfcECIMcbB1yYXyQAAOGAT+Effctr5mvZilRokSBhBWJkH5c7u5MV1dX1fCXP//237/86fz5++98+MdPN/++++Htm5tv2k3c3tntXcyobj7anrb2DJ9t2fDcZaNxyVZ6+u3dvL0bfQXX55ptj+IHYaGrvGdWzJ67RXkM37P5MF66RvNYe63c0Spszsqx27bMmbGqee3ua1tLXsF9ndty+/K9oiW3rN73OBsdmX3zp7dagz3EmG30UX0uy2JHI9zZPyXxxYNU0ymLjU5f3RtlLEqrbDHnsDK2...
null
21,913
Powers Game
After their success in coming up with *Fun Game*, Kyle and Mike invented another game having the following rules: * The game starts with an $n$-element sequence, $*2^1 * 2^2 * 2^3 * \ldots *2^n$, and is played by two players, $P_1$ and $P_2$. * The players move in alternating turns, with $P_1$ always moving first. Du...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String powersGame(int n)" ], "script_name": "Solution", "solution": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Scanner;\n\n\npublic class Solution {\n public static void main(...
{ "solution": "import java.io.*;\nimport java.util.*;\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 StringBuilder answer = new StringBuilder();\n for(int t=0; t<T; t++){\n int n =...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.lang.*;\n\n\npublic class TowerBreakersRevisted{\n\tstatic long mod=1000000007;\n\t\n public static void main(String[] args) throws Exception{ \t\n \t InputReader in ...
{ "class_name": null, "func_sign": [ "powersGame(n)" ], "solution": "r = ['First', 'Second']\nfor i in range(int(input())):\n print(r[not(int(input()) % 8)])", "template": "#\n# Complete the 'powersGame' function below.\n#\n# The function is expected to return a STRING.\n# The function accepts INTEGER ...
eJzs/U2uNMm2JuYJoAZycdrVCLP158EBcALqEOAB2CCrUZ1kQboFCCAIcAAah8apsMc+kFSp6vIekU1POGIhM90yv71f37EjnjBf63/+v/7X/+//13/xf/lv/se//bu//v1/+Oe//Zf/9LeVf/9r+tkzf/9rfbp/f/v057P61Nrf/au5nnz+/lesWPk77fl2z/n7p+Pzq9+Zz/n3+xOf/v7qEzHx97/qG/X51azJ9fvnq7+Vv//e3/7NP/3t3/4///2//e/++d/+9//t//Af/vnPn+S/+nf/9//HP//9r//bv/3v/oe//vv/tf5H//jP...
null
6,570
Strange Grid Again
A strange grid has been recovered from an old book. It has $5$ columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this: .............. .............. 20 22 24 26 28 11 13 15 17 19 10 12 14 16 18 1 3 5 7 9 0 2 ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int strangeGrid(int r, int c)" ], "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.InputMis...
{ "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 SG {\n static InputStream is;\n static PrintWriter out;\n static String INPUT = \"\";\...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static long get(long r, long c) {\n return (r-1)/2*10 + (r-1)%2 + (c-1)*2; \n }\n \n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n System.out.println(get(s.n...
{ "class_name": null, "func_sign": [ "strangeGrid(r, c)" ], "solution": "nums = input()\nnums = nums.split()\nrow = int(nums[0]) - 1\ncol = int(nums[1]) - 1\n\ntens = int(row / 2) * 10\nones = row % 2 + col * 2\n\ntotal = tens + ones\nprint(total)", "template": "#\n# Complete the 'strangeGrid' function be...
eJyNkk1KA0EQRl3kIE2vg9R/dXkSQcWFZuEmBkwgKAEPofe1ESeRHlKkVg1Tb+r1V/25+H5fXP3W7Vs/3H3Ul/Vmt603pSI7ozYDL3i/rstSV/vN6mm7en583W3/mqyZejAw1MOy/KOVHQGbFj7LkjVVCJIRJQ1AUi+UsBQKRo0GmCJMVZATaZRo5A42SqMoEyB4FD1LO5kBKEcb6WYW4SgJHMx9uFoMbHQZByJMtLscsCLCqG3dJUBawjJGiBLjgIqFEoq3LGsW73bceLwwNCXp0p7cWKXvqku3WVyJ7mwxyYDxv5RtftabrGro5eQp...
null
1,667
Matrix Tracing
A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS" MATHE ATHEM THEMA HEMAT EMATI MATIC ATICS There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the matrix from the top-left position and...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(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.InputMismatchE...
{ "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.BigInteger;\n/*\n1 1 1 1 1\n1 2 3 4 5\n1 3 6 10 15\n1 4 10 20 35\n*/\npublic class Solution {\n\n public static boolean overflow(long a, long b){\n int r = 0;\n for(; a > 0; ++r)\n a >>= 1;\n for(; b ...
{ "class_name": null, "func_sign": [ "solve(n, m)" ], "solution": "#!/usr/env/bin python\n\nimport sys\n\n\ndef modinv(n, p):\n return pow(n, p - 2, p)\n\ndef mod_choose(n, k, m):\n if k < 0 or k > n:\n return 0\n \n else:\n p, q = 1, 1\n \n for i in range(1, min(k...
eJylnEuONUlShRmwkKsat5A/zd3ZAhtAohED6AETYNAtIaGWWAQskxkL4DvHPPJm/o9ulaguVecjboS7udmxc8ws8j//8r//92/+wv/87f/wxd/9xy///C//9off//LXr1/qb/9lvvjPL795/fK7f/+33/3j73/3T//wr3/4/fPrX/74m9fXy/uvu7z9usvHGOc16/zpZ9oZUWKO9v1n65nr1XdpP/3wjHrGifH9Z3fp89XLOT9/cC1tR8wfLnq99mrlp59dfZ25W50/sE+frdXXODPW/rmlSm21l1q+v8Fau671Oq2X2X9+gx4xYvYf...
null
1,318
Sumar and the Floating Rocks
Famous wizard Sumar moonji kumaru is stuck in a huge room and has to save Hermione Granger from a monster. Kumaru is at location P1 given by integral coordinates (x<sub>1</sub>,y<sub>1</sub>) and Hermione is at location P2 given by integral coordinates (x<sub>2</sub>,y<sub>2</sub>). Sadly P1 and P2 are the only points...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int x1, int y1, int x2, int y2)" ], "script_name": "Solution", "solution": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.u...
{ "solution": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nim...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n private static Scanner in;\n\n public static long readLong() {\n if (in == null) {\n in = new Scanner(System.in);\n }\n return in.nextLong();\n }\n \n public static long gcd(long x, ...
{ "class_name": null, "func_sign": [ "solve(x1, y1, x2, y2)" ], "solution": "#!/usr/bin/env python\n\nimport math, sys\n\n\nif __name__ == '__main__':\n T = int(sys.stdin.readline())\n \n for _ in range(T):\n x1, y1, x2, y2 = list(map(int, sys.stdin.readline().split()))\n\n dx = abs(x...
eJyVmkuOZEkRRRmwEFeNCeT/DytBohAD6AGTgkG3hISQWATskhkb4Bx7kZVRmRkFdKeyIiNevOdudu3aNTP/+8//+e/8s/jv1//ixW/++umPX/7804+ffpU+lfP5y+20ufOeq6ZVNj+953SbtZ+66xrpds6opbTFtWfsVs7qJfU65tq5nLRXPnvVVtJttz7a2qtz131yH3W2lm69tjZy24d78fu0NbjtGjn3VptLGHmXVUtfqfHPzDwtdVZU6unptMHduS8Xzpxbr4tlnbW5/7XAzjPnYi2lzc5yY6mz7N3bYVksLs9ZZ0+3ss/kYWen...
null
15,898
Mutual Recurrences
Since you know [how to compute large Fibonacci numbers quickly](https://www.hackerrank.com/contests/infinitum10/challenges/fibonacci-finding-easy) using *matrix exponentiation*, let's take things to the next level. Let $a$, $b$, $c$, $d$, $e$, $f$, $g$ and $h$ be positive integers. We define two bi-infinite sequence...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(int a, int b, int c, int d, int e, int f, int g, int h, long n)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.io.InputStream;\n\nimport static java.lang.Math.max;\n\npublic class Solution {\n...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static long mod = 1000000000;\n private static long[][] mat_exp(long[][] A, long e) {\n if (e == 1)\n return A;\n else if (e % 2 == 0) {\n lo...
{ "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 C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n...
{ "class_name": null, "func_sign": [ "solve(a, b, c, d, e, f, g, h, n)" ], "solution": "from operator import mul\n\ndef matrixMult(m1, m2, d):\n m2tr = list(zip(*m2))\n return [[sum(map(mul, m1row, m2col)) % d for m2col in m2tr] for m1row in m1]\n \ndef matrixVectorMult(m, v):\n return [sum(map(...
eJyVVbtuHEcQVKBAnzG4mDD6/fCXGDANBzYDJ7QCEhBgEHDoTIn8v66ZJSnwbpcmd7i7A95MTXdVde/fH//9+unDun76B5Of/zr9cfv5/u704zjx9W0OGzJiPRl3Xt+ersbp5svnm9/ubn7/9c/7u6fFHR7dQ4Uy/PRwNV4iNfbb0JGjhwOx6hAqo1IlNEY7sUnUDl6NGhNz4jWQX8HjJNMSw+JoMcrsvfhsITnePJ9h2BZ+DFshwcUWwyWpkkL3w7R1K+ir4aFcFSHH0c6DPRFBZ7c17aDyJPAx/UUpBzlSs0PUtmgjlSHi5Mx1CSqL...
null
5,353
Euler's Criterion
Your friend gives you an equation $A \equiv X^2 \pmod{M}$ and asks you to find an integer solution for $X$. However, you know your friend's mischievous nature and suspect that there is no solution to such an equation. Thus, you first want to find out whether there is a solution to it. You may find this link helpf...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String solve(int a, 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.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 EC {\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 long modPow(int a,int p,int m){\n if(p==0)return 1;\n long x=modPow(a,p/2,m);\n x*=x;\n x%=m;\n if(p%2==1){\n x*=a;\n x%=m;\n }\n ...
{ "class_name": null, "func_sign": [ "solve(a, m)" ], "solution": "t = int(input())\nfor _ in range(t):\n a, p = map(int, input().split())\n print(\"YES\" if a == 0 or pow(a, (p - 1) // 2, p) == 1 else \"NO\")", "template": "#\n# Complete the 'solve' function below.\n#\n# The function is expected to...
eJylmsuOnUkRhFnwIKUWywFVVdaVPVtYsAHRiAXMgk0zC4+EhJB4CHhfvog6hrHd5+aZke3Tx/9flZWXiMgs/+un/2k/+4n/+93P+fCHf7z89e277z+8/DK9zNe3OmKlXisfe8t7pd3aite3PXIqefCJn3eskkZbZa79+lZyXS1FHZu/rbmWVNcor2+zzj77TnPXxp+vby/fpJdv//7dt3/+8O1f/vS37z9cdv31b17ffv+r315++99P+qBfL//8Jv3Axs6GK1fs2jJ3llSisht7RFpVFtYVu0zMnW3q57miXZ6/YcIPf9mAzzfWyqVw...
null
3,547
Mehta and his Laziness
Mehta is a very lazy boy. He always sleeps in Maths class. One day his teacher catches him sleeping and tells him that she would mark him absent for the whole semester. While she pretends to be strict, she is actually very kind-hearted. So she wants to give Mehta a chance to prove himself. She gives him a problem. If M...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String solve(int 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 public static int gcd(int a, int b) {\n return b == ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static Reader in;\n public static PrintWriter out;\n public static int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n public static void main(String[] args) throws IOException {\n in = new Reader();\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(n)" ], "solution": "import math\ndef primes(n):\n primfac = {}\n d = 2\n while d*d <= n:\n while (n % d) == 0:\n if d in primfac:\n primfac[d]+=1\n else:\n primfac[d] = 1 # supposing you want mul...
eJztnEuOJMl6nQVQC2nU+ELp9nJz40oEqAkOyB5wwOId9AUIEAS0CO1Sm9A5xyKzIisiM4safxcfOioiPdzt8b9/i/u///v//Nf/+3f/7X/9x7d/+f7Xv/357e9/+zZ//z7Pq87r9+/lOM/x+/frPI4y/Trqanrt5err9++ttNJ12bXOc+r9t7/89u2Pf//rH//05x///I//9rc/bzc8fv9+T33xvY5v//mX3+6eev7+fc15+Lb1aMf0hVdrs//+faw2Dr32MXvV5+Vco7evH1dfqq4qL6U8fVxpeo5mt8p59sO3b+vUbOpsM4+9Vrv0...
null
1,892
Manasa loves Maths
You are given an integer N. Is there a permutation of digits of integer that's divisible by 8? A permutation of digits of integer N is defined as an integer formed by rearranging the digits of N. For example, if the number N = 123, then {123, 132, 213, 231, 312, 321} are the possible permutations. **Input Format** ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String solve(String n)" ], "script_name": "Solution", "solution": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic class Soluti...
{ "solution": "import java.io.*;\npublic class Solution \n{\n public static void main(String[] args) throws Exception\n {\n BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));\n int cases = Integer.parseInt(buf.readLine());\n for(int i=0;i<cases;i++)\n {\n ...
{ "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\tstatic InputStream is;\n\tstatic PrintWriter out;\n\tstatic String INPUT = \"\";\...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "#!/usr/bin/env python\n\nimport itertools, sys\n\n\nif __name__ == '__main__':\n T = int(sys.stdin.readline())\n\n for _ in range(T):\n N = sys.stdin.readline().strip()\n \n if len(N) == 1:\n print('YES' if...
eJy9mbuOZUkRRTH4CqxW2SOUGfkMhIdwZwwcEIUwoA2cYoweCQmNxEfA/7JWntKopy/1uGNQKlXfxzmZGRE79t5x+l8//89vfvGz8/P7X/Pij/98+NvTt999evjVh4dYj0+z9Zwx6uw78vEp9swd0Wobo6zx+LRKeXxqvc6aMdvOUVpdbQd37SjRS7SxR8xRSln18Ymr+64reTe4pA0+2zFaC/59fKrBBdH3rGtG4/3g3ojcbe45KktntuC27LF36bOMvbPWGKVzmL6y97VKX6UNVoxSs80VfbQ+OGIfZbao0duYrUTdZcxz4kji5Jy9...
null
3,082
Strange numbers
Let $length(A)$ denote the count of digits of a number $A$ in its decimal representation. John is looking for new methods of determining which numbers are strange all day long. All non-negative numbers of length 1 are strange. Further, a number $X$ with $length(X) \ge1$ can also be considered strange if and only if...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long l, long r)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.ArrayList;\n\npublic class HR_strange_numbers {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n ArrayLi...
{ "solution": "import java.io.*;\nimport java.util.ArrayList;\n\npublic class HR_strange_numbers {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n ArrayList<Long> list = new ArrayList<Long>();\n list.add(0L);\n for (int i = 1; i <= 9; ++i) {\n rec(i, l...
{ "solution": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.*;\n\npublic class Main {\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 IOException...
{ "class_name": null, "func_sign": [ "solve(l, r)" ], "solution": "import math\nimport bisect\n\n_l = [n for n in range(10)]\nfor i in range(2, 19):\n j = 1\n while j < len(_l):\n if i == int(math.log10(_l[j] * i)) + 1:\n _l.append(_l[j] * i)\n j += 1\n\ndef s(n):\n return ...
eJztnMuOZNlVhi3Eg2z12EL7fuEV4AGQKMQAPGDSeGBLSMgSDwFPy4TvWyciMjIys7rbGMkDytXOyIgT5+y9Lv/612XXf/zlf/3F3/4q/vzdf//Nr3719//+w7/8+Nvf/+6Hv04/9PLtx7p3G72N08dppbSRWll5r1rzqaWXddbhqrFa7332Wk4+7eSedvfVyDmP2veem5uVnGtrs8/jNXvtndbOZZe2R929tpK9W+N5vNMbl/GVuVLfs/e6Oo+ZJbdcls+seVWeWBef5r56GrvO1llR7T2fcurmZpmFb9Y6Gmvoa6Za/bycM2ctmVX2...
null
2,414
Lucy and Flowers
Little Lucy loves to arrange her flowers in patterns similar to those of a binary search tree. Her father, a computer scientist himself, takes note of this and finds out that she has *N* flowers. Every day she takes some of these *N* flowers and arranges them into all possible different patterns. The more the number of...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int n)" ], "script_name": "Solution", "solution": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputS...
{ "solution": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class LucyFlowers {\n static long[][] loadNCRTable(int n, long m) {\n long ncr[][] = new long[n + 1][n + 1];\n // pre-populate table \n for(int i=0; i<=n; i++) {\n for(int j=0; j<=i; j++) {\n ...
{ "class_name": null, "func_sign": [ "solve(n)" ], "solution": "import functools\n\nN = 10001\nP = 10**9 + 9\n\nfact = [1]\nfor i in range(1, N):\n\tfact.append(fact[-1] * i % P)\n\ninv = [0, 1]\nfor i in range(2, N):\n\tinv.append(P - P // i * inv[P % i] % P)\ninv_fact = [1]\nfor i in range(1, N):\n\tinv_f...
eJyUvcmObruSHuaBB/ZbFO5Yg8We1JMYcAIaSDXQ5LoGJUCAIMBP6edxNGwiGIzcW4Vb5+TJ/P+1yGA0X7T8f//3/+v/+z/+z//t//4f//iv//y3//bv//iP//KPWn/+mccI9M8I//z5Z/pi+fkn/Cb1tH+fSu3wc/rgA7Fk+H0cX6G/FvxN++jn9vNPfiD8M/Q46Dnwn+nnn/CnlFum/9wfjt+H7+mZPhhGgW+MiO/oH7wP/gdPTyPyz7imUOFZ+L9Uy1p6KCGt554VjwQvyBm/C29Yq8oN35Fjwo80+l5I8JtYI24Klw3//3V4VG/8...
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
2,452
Sherlock and Queries
Watson gives Sherlock an array $A$ of $N$ elements and two arrays $B$ and $C$, of $M$ elements each. Then he asks Sherlock to perform the following program: for i = 1 to M do for j = 1 to N do if j % B[i] == 0 then A[j] = A[j] * C[i] endif end do end do ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<Integer> A, List<Integer> B, List<Integer> C)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport jav...
{ "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.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 int MOD = (int) (1e9 + 7);\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m...
{ "class_name": null, "func_sign": [ "solve(A, B, C)" ], "solution": "from collections import Counter\n\nmod = 10**9 + 7\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\ntmp = [-1] * (n + 1)\nfor i in range(...
eJx0vcmubVmSXacGP2Qj2mysutCXEKADbIjZyI4zCSQBAYQA6c85x1jHlckAgqI8Ht+795y9V2HFtGnT/t//8J/+v3/+7//Hf/6ff/vnP//lf/zr3/7P72/7q3/82W8d4xunnfu12c/4+hytfXvUc7656z5fq/X2/Ogff9bVzvnjz7/9x+9v//R//8s//V//+k//9b/8t//xr78P/PefNWofc8zb/rfPu732Otsa7zP/9v/8x+9/e6D5x5+7r92/0/IDX2tntu+Ueta326zta2Pkz2PNmsdY3/rqN7/1x59z5Ie+vVZeYK2S32r19PHV...
null
2,143
Summing the K-N series
You are given a sequence whose $n^{\text{th}}$ term is $$T_n = n^K$$ You have to evaluate the series $$S_n = T_1 + T_2 + T_3 + \cdots + T_n$$ Find $S_n \bmod (10^9+7)$. **Input Format** The first line of input contains $T$, the number of test cases. Each test case consists of one line containing two space-sepa...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int solve(long n, 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.InputMismatch...
{ "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.math.BigInteger;\nimport java.util.Scanner;\n\n/**\n * @author tainic, 6/8/15\n */\npublic class SummingTheKNSeries {\n public static final long MOD = 1000000007;\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int t = in.nextInt();\n ...
{ "class_name": null, "func_sign": [ "solve(n, k)" ], "solution": "from fractions import Fraction \nimport math\n\nf = [1,1]\ninf = [1,1]\n\nfor i in range(5000):\n\tf.append(((i+2)*f[i+1])%1000000007)\n\tinf.append((pow(i+2,1000000005,1000000007)*inf[i+1])%1000000007)\n\ndef nCr(n,r):\n return (f[n] * i...
eJy9lk2OXEUQhFmw4RalWVuo8r+SkyAxiAV4wabxwpaQEBKHgEuw44Z8+YxHtsftJU/jdnVVvarMyIjI/uPLv/756ovr+fZvBt/99vDz7dWb1w/frIfzeOvq0jqyQyorasU2cymLx5t3nazax7W7tVaLtIdpPd4sIk4e37x1Qvcy7Yw+rY+3U63HhO97e0qtktPh6dxXcSwkqk7l3mmLmzVD5fEWqpZni14vnlgRYpH7GGuc7brZuXmlVFoI7vGW6s2uYllXpnFQCPMPL9bDy19fvfzx9cuffvjlzev/EpZ5rLMJRN3kZD7ehPDFdhF5...
null
2,609
Emma and sum of products
Emma is really fond of integers and loves playing with them. Her friends were jealous, and to test her, one of them gave her a problem. Emma is given a list $A$ of $N$ integers and is asked a set of $Q$ queries. Each query is denoted by an integer $K$, for which you have to return the sum of product of all possible s...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<Integer> A, List<Integer> queries)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arra...
{ "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.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static long sum = 0;\n\n public static void main(String[] args) {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class sh...
{ "class_name": null, "func_sign": [ "solve(A, queries)" ], "solution": "#!/bin/python3\nimport os, sys, math\n\ndef amax(a):\n return max(map(abs, a))\n\ndef multiply_polynomials_kronecker_2(p1, p2, modulus):\n c1max,c2max = amax(p1),amax(p2)\n cbound = c1max*c2max*len(p1)*len(p2)\n xlen = int....
eJx0/TuubcuyZYlRyBKwBAtPTmH4350lIcALUGCGkMplCpEAgQQBilRZY/bWbJ4gEYkHvNhx7t5rzTmGf+zTrVu3/9f/8H/+//y//4//h//L//Yf//O//5f/9b/+x//p7z/av/695v7uv/7d/L//+B///uO//D/+l//yf/uv/+V/+r/+3//X//r7MX/mP/6f/+Pf/9+vrn/9++1vrL82xvgbr835N2+/76+vcee//j38v/zY/E8/d/Z+8jNznPn96999397+u2/p/H1rb+Sz73t/bfd7/9Y+c/+N/Hr/O2Of8Xd7fuqv97v63/3a3X+n...
null
2,333
Sherlock and Counting
Watson gives Sherlock two integers, $n$ and $k$, and asks him to count the number of positive integer $i$'s such that: $$i \cdot (n-i) \le n \cdot k, \text{ and } i < n$$ Given $q$ queries where each query consists of some $n$ and $k$, print the number of possible $i$'s for each query on a new line.
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int solve(int n, int k)" ], "script_name": "Solution", "solution": "import static java.lang.Math.*;\n\nimport java.io.*;\n\npublic class Solution {\n\n\tpublic Solution () {\n\t\tlong N = sc.nextLong();\n\t\tlong K = sc.nextLong();\n\n\t\tdouble D = ...
{ "solution": "import static java.lang.Math.*;\n\nimport java.io.*;\n\npublic class Solution {\n\n public Solution () {\n long N = sc.nextLong();\n long K = sc.nextLong();\n\n double D = N*N - 4*N*K;\n if (leq(D, 0)) print(N-1);\n else {\n long A = floor((N-sqrt(D))/2)...
{ "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\tstatic InputStream is;\n\tstatic PrintWriter out;\n\tstatic String INPUT = \"\";\...
{ "class_name": null, "func_sign": [ "solve(n, k)" ], "solution": "import sys\nfrom math import ceil\nT = int(sys.stdin.readline())\nfor _ in range(T):\n N, K = [int(c) for c in sys.stdin.readline().split()]\n if (N*N-4*N*K) < 0:\n print(N-1)\n else:\n z1 = (N+(N*N-4*N*K)**.5)/2\n ...
eJyMvU2uNMmyXacGB5K4bUKI8H/nSAToA9QQX4OdKzYeAQGCAE6K86Pttc3OTxUf8HBvVeU5J9MzwsPN3dxs+bb//h/+j//9f/yH/+3//P/+8V/++V//27/+4z99/tHeP/9sY89x7xmfffYz7rN3/DJ+jH/+/HO9933eOZ/Pec87Zrz8889930/88+eft6++2x39c+JFf/fVZ8c779tWtLBWfPrqI6e3vs+zn89cz33PM+Lj716f+Ce+5RNvGR/9avXWZr/P5+65+3xa/GGPcWZ/481PvLfd5+64zs/c0dJtj66o7c9ucb36une/fXzu...
null
3,926
Circle City
Roy lives in a city that is circular in shape on a $2D$ plane that has radius $r$. The city center is located at origin $(0,0)$ and it has suburbs lying on the lattice points (points with integer coordinates). The city Police Department Headquarters can only protect those suburbs which are located strictly inside the c...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String solve(int d, 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.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.*;\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\tint r = ...
{ "class_name": null, "func_sign": [ "solve(d, k)" ], "solution": "import math\n\ndef need(r):\n ret = 0\n if r % 2 == 0 and int(math.sqrt(r // 2))**2 == r // 2:\n ret += 4\n y = int(math.sqrt(r))\n if y * y == r:\n ret += 4\n x = 1\n while True:\n while x < y and x * ...
eJztvd3Kdd12puWGBzJYW24U2v9/PBLBiKBmI6CpQKVAkAIPQo/Gk/O67v6mzPslBSlNYkGetVa+zG8+c84xRu+tt9+73e1//8//z//q//rP8p//5r/gxX/7v/3pL/7yr/7tX//pv/7+VNuf/WX9yp/9ZfMf3X8M/zH9Ry35S17PvF7v/fdWb78+VfK3P/2r709//r/+1Z//j3/95//Tf/+v/+1f/7rCX/wvf/Wv/82/+Yv/4X/+8z/7y7/9+u9/95/69Z/+3b/6/tbjtz18qHbHrd88e955qmtw6r3ntvudttpYpbMCd5fT+vla7Xuu...
null
12,799
Xrange's Pancakes
Xrange makes the best *polygonal pancakes* in PancakeLand. To grow the business, they hired $m$ line cooks to be pancake *rotators* and *flippers*. A regular [n-gon](https://en.wikipedia.org/wiki/Polygon) has $n$ vertices, $n$ flipping axes, and $n$ rotation points. We define the following: - Flipping Axes - If $n...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static List<Integer> solve(List<List<Integer>> operations)" ], "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": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\nstatic class Reader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n \n public Re...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\nstatic class Reader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n \n public Re...
{ "class_name": null, "func_sign": [ "solve(operations)" ], "solution": "n, count = map(int, input().split())\nsgn = 1\nrot = 0\nfor i in range(count):\n t, k = map(int, input().split())\n t = 3 - 2 * t\n sgn *= t\n rot = k + t * rot\nprint((3 - sgn) // 2, (-sgn * rot) % n)\n", "template": "#\...
eJzk3cuuPEuTJXSQeJCjGvcg/O7OkyDREgOoAZOiB9USUgvEo/Io5E77WUTs853zqeZM/pd9yYyMcDe3tcxsrf/nf/if/t//+7//7/7n//Yv//u//Zf/+u//8j/+8S/zj/6f/638/FH/KP5V/rj+87/9y3/641/+9f/8L//6v/77v/5v/8v/8V//3c9/fupf/q//9MfrFfofbfz8zve328/r1J8/mv9+v+G18xv19bXr51/X7994fq3eP1Lu9yh+4/3D1/2N9vuN2n1V7f618refrvzDpyt1/FHX/v7auO9PO99LKt9XX/PnP/v7njtu...
null
26,065
Baby Step, Giant Step
You are standing at point $(0, 0)$ on an infinite plane. In one step, you can move from some point $(x_{f}, y_{f})$ to any point $(x_{t}, y_{t})$ *as long as* the [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance), $\sqrt{(x_{f}-x_{t})^2+(y_{f}-y_{t})^2}$, between the two points is either $a$ or $b$...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, int b, 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(String[] ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static int steps(int a, int b, int d) {\n int minSteps = d/b;\n if (d % b == 0) {\n return d / b;\n }\n \n if (d % a == 0 && d / a <= minSteps + 1) {\n return d /...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static int steps(int a, int b, int d) {\n int minSteps = d/b;\n if (d % b == 0) {\n return d / b;\n }\n \n if (d % a == 0 && d / a <= minSteps + 1) {\n return d /...
{ "class_name": null, "func_sign": [ "solve(a, b, d)" ], "solution": "from math import ceil\n\ndef steps(a, b, d):\n mmin = min(a, b)\n mmax = max(a, b)\n if d is 0:\n return 0\n if d in {mmin, mmax}:\n return 1\n if d < mmax:\n return 2\n return ceil(d / mmax)\n\nt = ...
eJytncuObMmSlhnwIEtn3EJ+v/AkSBRiAD1gUvSgkZAQEjNGzOB9+T6Lql0Z4em7qxpO5+kTOyNjhS93u/xm9put//Ev/8///p//Iv7zb/4XL/7tf/vbf/r1H/7LP/7tXz9/m7/8OteYua2aH1+V3nZ/1kqj97X3L7+uNVJfsyV+OXbi9XpqSWOUtMcvv+688p4rzYdXfbWc+1PS3K2UXX/5teyUZ81rPryaY3CFp41VN6/KL7/y3shpz/1kviGVPPqTa201sQwuXteok5fPrjvt3PN4ykq8X3r/5deRai8zz/WM1PJqa+SHr8p775l+...
null
118
Random number generator
**Random number generator** There is an ideal random number generator, which given a positive integer M can generate any **real number** between 0 to M, and [probability density function](http://en.wikipedia.org/wiki/Probability_density_function) is uniform in [0, M]. Given two numbers A and B and we generate _x_ and...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String solve(int a, int b, int c)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int gcd(int a, int b) {...
{ "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.*;\nimport java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n Scanner s = new Scanner(System.in);\n int T = s.nextInt();\n\n for (int t = 0; t < T; t++) {\n int A = s.nextInt(), B = s.nextIn...
{ "class_name": null, "func_sign": [ "solve(a, b, c)" ], "solution": "from itertools import product\nfrom fractions import Fraction\n\nfor t in range(int(input())):\n tmp = input().split();A,B,C = [int(i) for i in tmp]\n if A+B <= C: fr = Fraction(1,1)\n elif C <= A and C <= B: fr = Fraction(C**2,(...
eJxsvU2uLMuSnacGoXFsvDaBDP9350gE6AFqkNVgp1iNKoAAIUCj1Dg0BK1vmUe673Pva7zMu09mZIS7uf0sW2b2//yn/+P/+3//9//t//xf//jv//pv//Hv//gvP//IufV//usoqf7kMcZPevS/f/5rW6P91D7X+4daavtpueefpI/XWn7mWP3915nTT1t5/fTR9O9tjudntvPt0cvzU2p+vtdvufykkfP3+qlkfWXV9w/ledJP7m3xg+Xp6WfW8v3+KqX/tP58b7iM+ZN9e/HfaSa9zbrD/Ez93jP17ykNrparPrxm8qX1z+2nrPm9...
null
22,940
Extremely Dangerous Virus
A recent lab accident resulted in the creation of an extremely dangerous virus that replicates so rapidly it's hard to predict exactly how many cells it will contain after a given period of time. However, a lab technician made the following observations about its growth per millisecond: - The probability of the number...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(int a, int b, long t)" ], "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 = 1000000007;\n ...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'solve' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts following parameters:\n * 1. INTEGER a\n * 2. INTEGER b\n * 3. LONG_INTEGER t\n */\n\n public stat...
{ "solution": "import java.util.Scanner;\n\npublic class Solution {\n private static final int M = 1000000000 + 7;\n \n public static void main(String[] args) {\n try (Scanner scanner = new Scanner(System.in)) {\n byte a = scanner.nextByte();\n byte b = scanner.nextByte();\n ...
{ "class_name": null, "func_sign": [ "solve(a, b, t)" ], "solution": "MOD=10**9+7\n\nA,B,T=map(int,input().split())\nD=(A+B)//2\nR=1\nwhile T > 0:\n if T % 2:\n R = (R*D) % MOD\n D = (D*D) % MOD\n T //= 2\n \nprint(R)", "template": "#\n# Complete the 'solve' function below.\n#\n# The fu...
eJyVU0tKBEEMdeFBQq9F8qn8PImg4kJn4UZnMQOCCB5Cj+jOQ5gZXAjVESxoaKh6nyQvb6cfX6cnx3P5WT9XL8vD43a/Wy5gEQZGsAwPIw5RVkaM68flDJbN83Zzt9vc3z7tdz/vNdMiObFevJ7BLyZXCAcaYmItXKRkJMQnuBgYgozMwBaexEoyYoYTENhogTQBMoAMnNEye7vVF3amuVqBkRDs4uSE2SsrB6kG5kQRBhHgWffiMao1vY/Bg4tlLkPAHYa5urToQCfx1ZkFKENOp6UySUuvmiYqRQgEJeTeR7WT0XWuQmt8CkxU6aoP...
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
1,168
Inserting a Node Into a Sorted Doubly Linked List
Given a reference to the head of a doubly-linked list and an integer, $data$, create a new *DoublyLinkedListNode* object having data value $data$ and insert it at the proper location to maintain the sort. **Example** $head$ refers to the list $1 \leftrightarrow 2 \leftrightarrow 4 \rightarrow NULL$ $data = 3$ ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static DoublyLinkedListNode sortedInsert(DoublyLinkedListNode llist, int data)" ], "script_name": "DoublyLinkedListPrintHelper", "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 i...
{ "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": " // Complete the sortedInsert function below.\n\n /*\n * For your reference:\n *\n * DoublyLinkedListNode {\n * int data;\n * DoublyLinkedListNode next;\n * DoublyLinkedListNode prev;\n * }\n *\n */\n static DoublyLinkedListNode sortedInsert(Doub...
{ "class_name": null, "func_sign": [ "sortedInsert(llist, data)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\nclass DoublyLinkedListNode:\n def __init__(self, node_data):\n self.data = node_data\n self.next = None\n self.prev = Non...
eJztfcvKLL1ypQ0e9zN8/GPTVOqufhKD03hgn4En2x4cg6Ex+CH6gTtWZEoKhUJZtQ0NbVOUVnAumVXfzqWU4q7/+Ku/+dv/8Zd/8bf/+49/+vUv//rnP/7Xzx/H+Su+zl8HD8fD8wg8Io/EI/MoPCqP43XjuOFu+BvhRryRbuQb5Ua94F43jhvuhr8RbsQL+O0//vrnjz/927/86R/+/Kd//Pt//tc/t3/Xz/Hj6OPpE+gT6ZPok+lT6FPpc7zaOHg4Hp5H4BF5JB6ZR+FRMdyLx8HD8fA8Ao/4gz/xj3//6x/5uPmJvcQzrOIROgWv...
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
33,294
Migratory Birds
Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids. **Example** $arr = [1,1,2,2,3]$ There are two each of types $1$ and $2$, and one sig...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static int migratoryBirds(List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(St...
{ "solution": "DNE", "template": "class Result {\n\n /*\n * Complete the 'migratoryBirds' function below.\n *\n * The function is expected to return an INTEGER.\n * The function accepts INTEGER_ARRAY arr as parameter.\n */\n\n public static int migratoryBirds(List<Integer> arr) {\n // W...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] typeCounts = new int[5];\n ...
{ "class_name": null, "func_sign": [ "migratoryBirds(arr)" ], "solution": "#!/bin/python3\n\nimport sys\nfrom collections import Counter\n\nn = int(input().strip())\ntypes = list(map(int, input().strip().split(' ')))\nfreq = Counter(types)\nprint(max(freq, key=freq.get))\n# your code goes here\n", "templa...
eJzsnc2uJMlxpWcxq3mKQK+5oP8Nh3qSAaYBLSQutGlxQQICBAHzvvMS0103PvuOZzUXhBaEJJOhqvLezIxwNzc7ds4JqPl///v//n+/+R//7f/86w//9NMf//ynH/7u+eH3v//9jz+NZzzrmd9iPOfbn/2Mb/HL7877u/nt9/PnP+fnz49vr9b7zfXt0/vbldb7/v72vf3tu+v9M9+rfn1/fLvC/naN9f7Nnea36+/3W3z+69Pj2yfW+4n97X1Wur6t8rxXnR97YU37/dT69vPXCtd7/fnu42sdX6/Ou0uzsd7rfq17vJ9lv9xrvt/e...
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,359
Gridland Provinces
The Kingdom of Gridland contains $P$ provinces. Each province is defined as a $2 \times N$ grid where each cell in the grid represents a city. Every cell in the grid contains a single lowercase character denoting the first character of the city name corresponding to that cell. From a city with the coordinates $(i, j)$...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int gridlandProvinces(String s1, String s2)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport ...
{ "solution": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class Solution2 {\nprivate final static Scanner scanner = \nnew Scanner(System.in);\nprivate final static long mod1 = 2147483607,\n f1 = 107, f2 = 101;\nprivate final static long[] arr1 = new long[10000], \narr2 = new...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport jav...
{ "class_name": null, "func_sign": [ "gridlandProvinces(s1, s2)" ], "solution": "\n\n\nclass Solution:\n def __init__(self):\n self.size = int(input())\n self.array = []\n self.array.append(input().strip())\n self.array.append(input().strip())\n self.hash = set()\n\n ...
eJztvVmOJcm1LaYPDeSC3w9C9pmlkQh4KQjW931vggANQpqG/jQJjUrLo6r4SBazLi9fFeuyGO7nnIwMP+Fubrb32mtZs/3//B//7//3//sfXrb/5f/BD//1f/+DiXn0P/zP//aHtx+/xk9v3nyN5HV73X6F7Wu8r9vr9itsPwIXfd1f919+/xp/8yK87r/L/Y/AxbiQShvrfIgpl9r6mGuf+3rk9cjff+RrxD+vr9fXL/76U+B6/fibPgRnlLx+/E0fr5b1alm/lmW9AFdgJFi+CCvq7K25KpHwLgeLrLF+hb3NlCQI5560ToQqTjhz...
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
2,491
Sherlock and MiniMax
Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1 \le i \le |arr|$) ). Once that has been determined for all integers in the range, return the $M$ which generated the maximum of those values. If th...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int sherlockAndMinimax(List<Integer> arr, int p, int q)" ], "script_name": "Solution", "solution": "import java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.NoSu...
{ "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 static int miniMax = 0;\n static int miniMax_index = 0;\n\tprivate static int mini_first_last(int[] a,int first_last){\n\t\t//check for p\n\t\tint mini = Integer.MAX_VALUE;\n\t\t\n\t\tfor(int i = 0;i < a.le...
{ "class_name": null, "func_sign": [ "sherlockAndMinimax(arr, p, q)" ], "solution": "N = int(input())\nA = [int(c) for c in input().split()[:N]]\nP, Q = [int(c) for c in input().split()[:2]]\n\na = sorted(A)\nmax_point = P\nmax_distance = min(abs(i - P) for i in a)\nfor i in range(len(a) - 1):\n if a[i] ...
eJztmM2OHUkRhVnwDKxT3rAZjTIiIzMjeBIkjFiAF2zMLDzSSAiJh4D35TvZ7vat7i6Y2XPtGdetm5UZPydOnKh//vrf3//mV+fz+99y8Ye/f/jr5x9+/PLhd+3DiI+fa1tb07r58GzWnz9t8rV6X2P5nm1sZ9my3fnaVnrYrh6Nf41vtpq1MWebOZvtSO++dvOVlWWss2YZXjqmrT36rs3vGTknX7PNkZ1bsdjRH83QLWu7swRL7WJh1h6VLGfVbjbH3usYEm3O/fHzxNTp9fHzh+/ah08//fDpz18+/eVPf/vxy1f/+Z3f/vFde4iJ...
null
676
Equal
Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure everyone gets the same number. To make things difficult, she must equa...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int equal(List<Integer> arr)" ], "script_name": "Solution", "solution": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\...
{ "solution": "/*\n JAI MATA DI\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.sql.Array;\npublic class CP {\n static class FR{\n BufferedReader br;\n StringTokenizer st;\n public FR() {\n br = new BufferedReader(new In...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private int count;\n private int []C;\n private static final int [] opts = {1, 2, 5};\n\n public Solution(int []chocolates) {\n this.C = chocolates;\n Arrays.sort(this.C);\n\n final int offset =...
{ "class_name": null, "func_sign": [ "equal(arr)" ], "solution": "from sys import stdin\n\n\ndef count_ops(N):\n c = N//5\n N %= 5\n c += N // 2\n N %= 2\n c += N\n return c\n\nassert count_ops(10) == 2\nassert count_ops(11) == 3\n\ndef solve(N, xs):\n if N == 0:\n return 0\n ...
eJztvcuuLFmyXScC+pCNahOC+3o7AUK/IUBJqCHdhjopNi4BAoIAfgQ/WGuMuTwr6lRmRxBbDFR5nr1jR4T7etlj2jSz//I//i///n/+N//D//p//+3//P0//qd//du/+/nb/dvvdez/PM/18zxlX/UnP/d93efnef72nJ95zzg/t/P6Ov++39HP35/z8zjX+/3X+f7y8fnPz1zntet85r3XOP+uj+/8vPf9y3O9z/Leo573fd73/cx1Pvc55nVeKz9/n6P18Z7xyzx9Pus89+4fz77O9X728/X39+eX933O0/vsn2twf7w+Pj7fPp7n...
2
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
68
Count Strings
A regular expression is used to describe a set of strings. For this problem the alphabet is limited to 'a' and 'b'. We define $R$ to be a valid regular expression if: 1) $R$ is "$a$" or "$b$". 2) $R$ is of the form "$(R_1R_2)$", where $R_1$ and $R_2$ are regular expressions. 3) $R$ is of the form "$(R_1|R_2)$" w...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int countStrings(String r, int l)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util....
{ "solution": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\nclass Regex {\n static char e = '\\0';\n\n final Node root;\n final Node[] nodes;\n\n Regex(String regex) {\n Parser parser = new Parser(regex);\n ...
{ "solution": "\nimport java.util.*;\n\nimport static java.util.Arrays.asList;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numTestCases = Integer.parseInt(sc.nextLine());\n\n String[] testStrings = new String[numTestCases...
{ "class_name": null, "func_sign": [ "countStrings(r, l)" ], "solution": "from enum import Enum\nfrom collections import namedtuple\n\nEdge = namedtuple('Edge', 'dest char')\n\n\nclass Alphabet(Enum):\n a = 'a'\n b = 'b'\n e = None\n\n\ndef empty_edge(dest):\n return Edge(dest, Alphabet.e)\n\n\n...
eJydVs2O4zYM7qG3voSRUzxYFPyRKKpPskCnKOx2DntJ9zALFKgX6EN0L3vbNy1J2bEzcSad2oEjWRL5kfz0yX9//+XbD9/F9f6rNX7+6/Dh9PHT8+Gn7iCPp+PxOE5Db4/jMPZ9Px3Hh77vRBEkA6rNGAbrV0k5F0iPp7FLRYuyCNngOI19R8IkUBR89kPfcUHJVYm9fxxHN5gRlFTt1eFdd3j68+PTb89Pv//6x6fnGQw+nmD5efvw+V23wZodq5ky8ykl0VQoXnkAg731ERurKoKFUn08DZ3WXLMa8sDhkU0ejcEhm1cMpXo8Ficy...
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
1,545
Drive
HackerRank is starting a bus service in [MountainView, California](https://maps.google.com/maps?q=152+E+Dana+St,+Mountain+View,+CA&hl=en&ll=37.386646,-122.06583&spn=0.005336,0.009645&sll=37.387156,-122.066474&layer=c&cbp=13,353.31,,0,12.73&cbll=37.387138,-122.066472&hnear=152+E+Dana+St,+Mountain+View,+California+94041&...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int drive(int n, int k, List<Integer> d, List<List<Integer>> commuters)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Drive {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n \n step[] steps = new step[scan.nextInt()];\n passe...
{ "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 scan = new Scanner(System.in);\n //try{scan = new Scanner(new File(\"input00.txt\"));}catch(Exc...
{ "class_name": null, "func_sign": [ "drive(n, k, d, commuters)" ], "solution": "import heapq\n\ndef main():\n import sys\n input = sys.stdin.read\n data = input().splitlines()\n\n # Read n, m, k\n n, m, k = map(int, data[0].split())\n n -= 1 # Adjust for 0-based indexing\n\n # Read di...
eJzcvcuudE2WJIQED3KUYwZ+v/STIJESA+hBT5IeVEuIFhJPwDOzzGyZR5zM/2taTJCorKyK78SOvX27+7rbMv8//7v/4f/63//b/+Z//M9/+w//+I//6d/+9u9+/rbmT+uz/PS+yy7n7/+oP/+f/ufv/1jzzjJ+5vlZ/e//uKOfOefPmD8rvmz99jH6z4oBx1h3G22tn1l/1vz7P3Zfu9720y7/Ofs9pf+MET/++z96XLzii/jtiPvMPs++P73+9Hjpu2vdNy6scXlcW9qK59f4csdT7hlxMZ4y40ZjzRhT/LTw2rn3qS1GVzjAFePD...
null
1,319
Cutting Boards
Alice gives Bob a board composed of $1 \times 1$ wooden squares and asks him to find the minimum cost of breaking the board back down into its individual squares. To break the board down, Bob must make cuts along its horizontal and vertical lines. To reduce the board to squares, Bob makes horizontal and vertical cuts...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int boardCutting(List<Integer> cost_y, List<Integer> cost_x)" ], "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.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.str...
{ "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class Solution {\n public static long MODULO = 1000000007;\n \n private static BufferedReader getStdinReader() {\n return new BufferedReader(new InputStreamReader(System.in));\n }\n \n ...
{ "class_name": null, "func_sign": [ "boardCutting(cost_y, cost_x)" ], "solution": "for t in range(int(input())):\n m,n = map(int,input().split())\n hor = sorted(map(int,input().split()),reverse=True)\n ver = sorted(map(int,input().split()),reverse=True)\n h = v = 0\n ret = 0\n modulo = 10...
eJyMvcuubUuWZQUSH7IU5SzY+8GXIHCJAmSBipOFTAkJIeWn01uzeTw8MtwFcW/4PWfv9ZjTptl49NFHH//1f/if/uf/+t//d//L//0v/8df/9N/+c//8j/+/qX+5a/1zPGrpfa//HXVX/2t8pv3N/Jv+53+y8/679Tfnb+2f2fz+/zvLb97f+3w55lXrV/t+ZRfW7xy3d9cv53XH357yq+3X6/8eU7e2/I947fLb83f3HzP2HzVzeds3r5+Y/K323/3/PIdg0ua5bcbb7uDd+YLdq5z/U7e9pvnV/OzvPD87q/e3178b9628rW/fn89...
null
19,310
Accessory Collection
[Victoria](http://dontnodentertainment.wikia.com/wiki/Victoria_Chase) is splurging on expensive accessories at her favorite stores. Each store stocks $A$ types of accessories, where the $i^{th}$ accessory costs $i$ dollars ($1 \le i \le A$). Assume that an item's type identifier is the same as its cost, and the store h...
hackerrank
Hard
{ "class_name": null, "func_sign": [ "static String acessoryCollection(int L, int A, int N, int D)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Vic {\n\n static long Solve(int L, int A, int N, int D) { \n\n ...
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 T = in.nextInt();\n for(int a0 = 0; a0 < T; a0++)...
{ "class_name": null, "func_sign": [ "acessoryCollection(L, A, N, D)" ], "solution": "import math\n\ndef total(g):\n # g = size of consecutive groups after the first one\n if g <= 0:\n return 0\n first = N - g * (D - 2) - 1\n f = (L - first) // g\n if first < g or A - f <= 0 or first +...
eJyVmMuOJTkRhlnwDKytXqIRsiMc4Qh2SLwBGyQKsYBZsClm0SMhISQeAt6X73fRl+nqOi1qZs6cqsy0HZf/Evmvn/9n/eJn9+f3v+TLH/7x7q/PP/z4/t2vx7s1n56X59mjbK4cyyNy9Mrz9Bxre/GXEbN6jrXa9tNzn9o+1tgnw4blXP30XHYWv4w4O2OsXGc9PZu35ahhsVmmOlnyrD32WLN7HLen57271vCxd6YPW1lskT3dhh8vG+lhfN/Ngfjce+Rw0xVz7cza67D6YCF2s0kUT8/vvhvvvv/7D9//+f33f/nT3358/zHaU15R...
null
9,000
Yet Another KMP Problem
This challenge uses the famous [KMP algorithm](https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm). It isn't really important to understand how KMP works, but you should understand what it calculates. A KMP algorithm takes a string, $S$, of length $N$ as input. Let's assume that the characters ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String kmp(List<Integer> x)" ], "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[] 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.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{\...
{ "class_name": null, "func_sign": [ "kmp(x)" ], "solution": "from string import ascii_lowercase as A\nimport sys\nx = list(map(int, input().split()))\nused = [i for i in range(26) if x[i]]\nif len(used) == 0:\n sys.exit()\nif len(used) == 1:\n print(A[used[0]] * x[used[0]])\nelse:\n f = min(used, ...
eJzs3d1SE92ewOE5mAv5Vx9z0Gv1t1eyq8YqCyFKUELUBBHLqn2+D+dC5xZm4cs741ZUUISEPM+vyEd/rG46xTqgIPnnf/7jX//z3//xXx+r+WK5XlVPomqijr581ZE+fzWRr56lz0v+fnx52/51/3RR7UU1O1/ODlazw2en69XVWC/29/cPPjuaz+fHxyeL03ers/fF+UX1aS++OOz018Bl5DG6csjURCrPc+S6HOZy3eWJtFelcoo5pshdNN89+nr/b4f/b/aNF5devjz60vz/HH/h1TVeF6enp8vlm+Jt8a5YFWefle/0bx++5+Li...
null
1,975
The Maximum Subarray
We define *subsequence* as any subset of an array. We define a *subarray* as a *contiguous subsequence* in an array. Given an array, find the maximum possible sum among: 1. all nonempty subarrays. 2. all nonempty subsequences. Print the two values as space-separated integers on one line. **Note** that empty s...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Integer> maxSubarray(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 Solution {\n\n public static void main(String[] args) throws IOException {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n BufferedReader in = new BufferedReader(n...
{ "class_name": null, "func_sign": [ "maxSubarray(arr)" ], "solution": "# your code goes here\ntest = int(input())\nwhile test:\n\ttest -= 1\n\tinput()\n\tnum_list = [int(x) for x in input().split()]\n\tmax_sum = 0\n\ttmp_sum = 0\n\tmax_non_contg = 0\n\tflg = False\n\tmx = max(num_list)\n\tif mx < 0:\n\t\tp...
eJztms2OX0kNxVnwIKWW2M0fVbnscpnXYIOgEQvIgk3PLDISEkLiIeB9+Z266U5G6QZGk6BEdJR0Kvejrn38dezK33/+z9/+4mfn129+zeJ3f73788N337+9+1W7G/cPse4fbqM//mqv68+3/gJE+ArXd9+0uzd/+e7NH9+++dMfvv3+7aPvvn/4/fL+4e5v37Qfevjmj8/Yo0Ib79xm21ZvlqtHz25tZHjkZHVbFj7m9mo2Zq3pfbew2H3N4e1WY+215hztFhkV0YurO2plVXhzPpIjM9p0H2y5Z9vc0DrZvffR+U61mw8fq2yudptI...
3
19,358
Mandragora Forest
The evil forest is guarded by vicious mandragoras. Garnet and her [pet](http://finalfantasy.wikia.com/wiki/Quina) must make a journey through. She starts with $1$ health point ($s$) and $0$ experience points. As she encouters each mandragora, her choices are: 1. Garnet's pet *eats* mandragora $i$. This increment...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static long mandragora(List<Integer> H)" ], "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.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 private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n\n int t = in.n...
{ "class_name": null, "func_sign": [ "mandragora(H)" ], "solution": "def main():\n t = int(input())\n while t > 0:\n n = int(input())\n a = list(map(int, input().split()))\n a.sort()\n b = a[:]\n for i in range(n - 2, -1, -1):\n b[i] = a[i] + b[i + 1]\n ...
eJzs3bvOJU2XHGYZvJCN36ZRlVmHLN6EXAEaQIZEQ86IxhASQAjQpSueyJcQIECeAMn4Z5rT/Lrf3rsqD+sQK1as/+Pf/Xf/7f/67/6b//6//ON//tf/9J//7R//4feP81/+9XrH/Jd//e7zm9/zG8818v9+z/s9zzh/83znN+bvPa7xvL/x5u/v+Xu+ed7H/M37fI95/+a8r/Xkn6/ruPL7PI/jGeN3Xvfz5vcx17jf77fyNSM//x3XN9+Vv1/nkd/XOu73un7zuK985O8bx/Pez+9Z35EH+Z3ncb35fV3fWEd+v8c581jj+MZ5fR7z...
null
43
Grid Walking
You are situated in an $n$ dimensional grid at position $(x[1],x[2],...,x[n])$. The dimensions of the grid are $(D[1],D[2],...D[n])$. In one step, you can walk one step ahead or behind in any one of the $n$ dimensions. This implies that there are always $2\times n$ possible moves if movements are unconstrained by grid ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int gridWalking(int m, List<Integer> x, List<Integer> D)" ], "script_name": "Solution", "solution": "/* Enter your code here. Read input from STDIN. Print output to STDOUT */\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport ...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n public static final int MOD = 1000000007;\n public static final int MAXSTEPS = 310;\n \n public static void main(String[] args) throws IOException{\n long[][] pascals = new long[MAXSTEPS][];\n for (int i...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n private static final int MOD = 1000000007;\n private static int[][] combCache = new int[301][301];\n private static int[][][] singleCache;\n private static int[][] ways;\n private static int[] initPos = new int[11...
{ "class_name": null, "func_sign": [ "gridWalking(m, x, D)" ], "solution": "#!/usr/bin/env python\n\nimport sys\n\n\nMOD = 1000000007\n\n\ndef choose(n, k):\n if k < 0 or k > n:\n return 0\n \n else:\n p, q = 1, 1\n \n for i in range(1, min(k, n - k) + 1):\n ...
eJyFV0tuJUUQZMGWO5S8HqHKrKrMSk6ChBELmAUbw2JGQkJIHAKOw46DERHVM2PN8zP2e+3u6vrkJyIy/eeXf//71Rf6+fYf3Hz3+8PPT7++f/fwTXvIx6fdzOfj09yt2hzNeMFYs8en1Zv1hqvjb9d3tMElYz0+OYdbcIphHPMH710DWqbB1WxjzdCebRQ+Z2fMXJz2+FTN3R+fzNuONhIv9ji2bDzgxXX4Z5boCsubVec53kID9uyl6zjT/dI1MZ2TMAfnyocyTjxmD41g9ePTw5v28Pa3X9/++O7tTz/88v7dFTPrVRZrbizKnb7c...
null
5,680
Knapsack
Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create the sum, use any element of your array zero or more times. For example, if $arr=[2,3,4]$ and your target sum is $10$, you might select $[2,2,2,2,2], [2,2,3,3]$ or $[3,3,3,1]$. In this...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int unboundedKnapsack(int k, List<Integer> arr)" ], "script_name": "Solution", "solution": "import java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.Scanner;\n\npublic class Solution {\n\n\tprivate static Scan...
{ "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.*;\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\tpublic static void main(String[] args...
{ "class_name": null, "func_sign": [ "unboundedKnapsack(k, arr)" ], "solution": "t=int(input())\nfor _ in range(t):\n lst=[int(i) for i in input().split()]\n goal=lst[1]\n nums=[int(i) for i in input().split()]\n dyno=[0]\n dyno += [-1]*goal\n for i in range(len(dyno)):\n tmp=-1\n ...
eJx0/c2qNUmzrIsJpCvQFQxW+zQyfjNDVyLQB2pIu6FO6TT2AYEQqHdu+6Q9j+esjUCwvlpV7zvnGPkT4eFuZm7+//0//J//j//r//5/93/5f//X/+Of//l/+e//9X/6/df9n3/aM9ev7bn+889u/dfu1X/3ev/oXOc3zv1ba/5a29fvOfM3xvu3e/16fuI+7fc870+M9z/a+3utP+s31vP+yxrvH43xG8/43f3+tZUPP/v943W1X3t/rV3Pk/+6f1xCO+f9o/zK7L9xzd/s72/M+/2N98vHud4vbOt3X9dvv38wz+/M91/P/q39fvLz...
null
100
Coin on the Table
You have a rectangular board consisting of $n$ rows, numbered from $1$ to $n$, and $m$ columns, numbered from $1$ to $m$. The top left is $(1,1)$ and the bottom right is $(n,m)$. Initially - at time $0$ - there is a coin on the top-left cell of your board. Each cell of your board contains one of these letters: - **\...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int coinOnTheTable(int m, int k, List<String> board)" ], "script_name": "Solution", "solution": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution im...
{ "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.*;\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\tpublic static void main(String[] args...
{ "class_name": null, "func_sign": [ "coinOnTheTable(m, k, board)" ], "solution": "def main():\n height,width,k = [int(i) for i in input().split(\" \")]\n k += 1\n board = [[\"\" for j in range(width)] for i in range(height)]\n for i in range(height):\n row = input()\n for j in ran...
eJztms2KXMkRhb3wg1x6WYyHqv6Z7p51LGMVEGCwjBe2Ft60Z6EBwzDgh7Df0Tu/gvN8J25LlCihBg+YoTRSa7ruzcz4OXHiRLb+8dt//efb3/Dr9/9e//OHn27++vLDjx9uvt9ubh+3+8ftdHz3kpEV2ZWhrxHRkfq2q5uPOvQ89Gy9+e6l9d16J9Y7vR5XdIbertxfXHutN6L1zbuX9Xy9xdZatf4uLS1eSp6ub9fSLP23TMoqfcoW68lau95LvYeJerDOWrtrSeuEYqvkbT0u7SAv2Gq9FTKwWSIf9FxrljnYUc1RyUdrjV7XLq3l...
null
2,176
Hexagonal Grid
You are given a hexagonal grid consisting of two rows, each row consisting of $n$ cells. The cells of the first row are labelled $a_1, a_2, \ldots a_n$ and the cells of the second row are labelled $b_1, b_2, \ldots, b_n$. For example, for $n = 6$: ![Grid Shape](https://s3.amazonaws.com/hr-assets/0/1495564532-9e16e2...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static String hexagonalGrid(String a, String b)" ], "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.ut...
{ "solution": "import java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int tc=sc.nextInt();\n for(int t=0;t<tc;t++)\n {\n int n=sc.nextInt();\n int[] a=new int[n];\n int[] b=new in...
{ "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 HexagonalGrid {\n\tstatic InputStream is;\n\tstatic PrintWriter out;\n\tstatic String INPUT = \...
{ "class_name": null, "func_sign": [ "hexagonalGrid(a, b)" ], "solution": "def nextIndex(index):\n return [index[0]+index[1], (index[1]+1)%2]\ndef onBoard(index, board):\n return index[0] < len(board[0])\nfor t in range(int(input())):\n n = int(input())\n line1 = input()\n line2 = input()\n board = [l...
eJydVbFOw0AMZUDiN6LMFbIT0gI7KwwsIA4xQIYuR4dUQkJIfAOCgb/lzvZd3F5ySUkTxbkmz/Z7tu/z+Of35IiOuy9nPLyXa7vZduVlUZ4Zi8YCnc4GBP/obsZW3nB/I5n+5lfLRVG2b5v2uWtfnl63neDcX90ae31jrBjlx6JQbpbGrjwcIHpM7wBAXJLhnp2DmiLwzjDEpVbBr54zDND7LlrkL0fCUhHpay86BYsRFjPZJggV5YeUFTCNnFbIIRNfAtYYe0HZehCM8RCgFwX5WgaH9C5RVlMWwlQtPEI2EcXPsHTI0RDnIh6rN56V...
null
1,317
The Indian Job
It is the Indian version of the famous heist “The Italian Job”. _N_ robbers have already broken into the National Museum and are just about to get inside the main vault which is full of jewels. They were lucky that just as they broke into the museum, the guard was leaving the museum for exactly _G_ minutes. But there...
hackerrank
Medium
{ "class_name": null, "func_sign": [ "static String indianJob(int g, int[] arr)" ], "script_name": "Solution", "solution": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class Solutio...
null
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n final int T = scanner.nextInt();\n for (int t = 0; t < T; t++) {\n final int N = scanner.nextInt();\n ...
{ "class_name": null, "func_sign": [ "indianJob(g, arr)" ], "solution": "import itertools\n\ndef nzerolast(l):\n for i in range(len(l)-1, -1, -1):\n if l[i] > 0:\n return i\n return 0\n\nT = int(input())\nfor _ in range(T):\n N, G = map(int, input().split())\n L = list(itertools.repeat(0, G + 1)...
eJztlr2OHVUQhAlIeYfWjS10/n+ck9qBEyMWEcAGJNcO1hISQvJDwDM58zP5q5prZMsYMRlC7P3ZO2f6dFdXV/eZ11/+8farL/z3/A0/vvv18vP15auHy+O45LtrH1HazKveXVfMFi1F2bFj1pgrOr9GDO7MmJFTipqjlJgleos1Y5UYO9aIWqJ5pa9YPVaLUWP3mCl2Ym/PMaauMCnTW2uMRnB9T7shIG5KjxaV2D1GkjtMsO3r7np5FJf7X17e//hw/9MPL1493NL49ptnl98exceJkUvJaYx9dy05co4+haAL5nAG4FLowVovkYmY...
null
16,833
King and Four Sons
The King of Byteland wants to grow his territory by conquering $K$ other countries. To prepare his $4$ heirs for the future, he decides they must work together to capture each country. The King has an army, $A$, of $N$ battalions; the $i^{th}$ battalion has $A_i$ soldiers. For each battle, the heirs get a detachment ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int king(List<Integer> army, int k)" ], "script_name": "Solution", "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static long mod = 1000000...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static long mod = 1000000007;\n public static long INV4 = pow(new Complex(4,0), mod-2).a;\n \n static class Complex {\n public long a,b;\n public Com...
{ "solution": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n private static InputReader in;\n private static PrintWriter out;\n public static long mod = 1000000007;\n public static long INV4 = pow(new Complex(4,0), mod-2).a;\n \n static class Complex {\n public long a,b;\n public Com...
{ "class_name": null, "func_sign": [ "king(army, k)" ], "solution": "#!/bin/python3\n\nimport os\nimport sys\nfrom functools import reduce\nfrom itertools import combinations\n#\n# Complete the king function below.\n#\ncc = 10**9 + 7\nd30 = 73741817\nD2 = 976371285\nD3 = 688423210\nD4 = 905611805\nD5 = 6077...
eJx83cvOJUGSHGYtBD3HQa9nkZEZeQmu+RAC1AAXZC+4ac6iByJAENCj0z6LGkAYaMQBu6ur/v+czLj4xdzc/P/53//P//s//h//2//1P/7yX//+z//yj7/8h99f5u/869/f813HvMfvOef1nO99/q457u9Zc/zyV/P67u/+69//8k+/v/ztv//z3/7zP/72X/7Tf/uXf/z5jGs+zzfGu/7yP//p9//67PEb+ex1v+N+zn//t9dz3N9xPv9fv/3Ncz3Xdbz/7q+/9/rWdR7/9tff63def/37usZ5ne84f0+e8L7zcr/vfp73nt/xm8+4...
null
21,907
Poker Nim
Poker Nim is another $2$-player game that's a simple variation on a Nim game. The rules of the games are as follows: - The game starts with $n$ piles of chips indexed from $0$ to $n-1$. Each pile $i$ (where $0 \le i \lt n$) has $c_i$ chips. - The players move in alternating turns. During each move, the current player ...
hackerrank
Easy
{ "class_name": "Result", "func_sign": [ "public static String pokerNim(int k, List<Integer> c)" ], "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//Day 2: Poker Nim\n public...
{ "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 s=new Scanner(System.in);\n int t=s.nextInt(...
{ "class_name": null, "func_sign": [ "pokerNim(k, c)" ], "solution": "\ntest = int(input())\nfor _ in range(test):\n n,pile = map(int,input().strip().split())\n ar = list(map(int,input().strip().split()))\n xor = 0\n for n in ar:\n xor = xor^n\n if xor == 0:\n print('Second')\n ...
eJztnEmuZFl2XdXQQB6iTQi3LjQAToAdAXRCDTIb7DgJKgkIIAhwENIE1eMstNa2+E9ZgGJEQkQKRHgk0s3/N3u3OsU+++xr//Qf/+c//8V/yJ//8r948ef/8MNff//bv//1D//5+aF9+z6eO799b3f2WsZZT1u8Lvzf0/pdu+zanjruaZvX377fyb++fd9trVLmKM++s515e+c5++4y637mmfO0s9rDz/ns3M/qo/Q1y37G7KXPWuvTR22r3/30eu+YbTy1lFXGLJ3Bx15ld6bBA+refT5zMLlay33WWH72lqedcds+9VmFZ7V2z9Nq...
null
823
Vertical Rooks
HackerChess is a variant of chess played at HackerRank. It is a game played between two players who make moves in turns until one of them cannot make any move. The player who cannot make a move loses the game and the other player is declared the winner. The game is played on a board with $n$ rows and $n$ columns. The o...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static String verticalRooks(List<Integer> r1, List<Integer> r2)" ], "script_name": "Solution", "solution": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\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": "\nimport com.sun.org.apache.bcel.internal.generic.RET;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n new S...
{ "class_name": null, "func_sign": [ "verticalRooks(r1, r2)" ], "solution": "from functools import reduce\n\ndef processTestCase():\n n = int(input())\n p1 = [int(input()) for i in range(n)]\n p2 = [int(input()) for i in range(n)]\n p = [ abs(p1[i]-p2[i]) - 1 for i in range(n)]\n nimsum = red...
eJy0vevKLdvSpSXihRTf7xIysx8y0ysRTBDR+iHIspAqUETQa/YGXP15WvQx9ydoHRT2nmvO9x0jsx/i0KL1iOj/+3/2X/4f/+d/+p/8V//rP/33f/3rf/tv/um/+Bf/dH9/zeP5/hrP9f3Vnvb91fv79x/rb+fb1s/m99cz/v7X+f11/f338+p///Tv7/X773+NuX60/nm1vz9w3usr/e9/vn//vB3rx+ujx9/PvNf3xt8f6n+/aqxfjWs98l1f+/vH6y99veGaf39l+Mnp985jPa6tMa5/XutV1xrica73HWucdwbS2rO+Odb7+RmT...
null
107
Binomial Coefficients
In mathematics, **binomial coefficients** are a family of positive integers that occur as coefficients in the binomial theorem.   $$n\choose k$$ denotes the number of ways of choosing k objects from n different objects. However when n and k are too large, we often save them after modulo operation by a prime number P. ...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static int solve(String n, int p)" ], "script_name": "Solution", "solution": "/*\n Enter your code here. Read input from STDIN. Print output to STDOUT\n Your class should be named Solution\n*/\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\n\npu...
{ "solution": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n for (int t = cin.nextInt(); t>0; t--) {\n BigInteger n = cin.nextBigInteger();\n BigInteger ...
{ "solution": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int T = Integer.parseInt(br.readLine());\n for (int ...
{ "class_name": null, "func_sign": [ "solve(n, p)" ], "solution": "def solve(n,p):\n a = []\n nn = n\n while nn>0:\n a.append(nn%p)\n nn //= p\n m = 0\n for i in range(len(a)):\n b = a[-(i+1)]\n m *= (b+1)\n m += b\n print(n-m)\n\nt = int(input())\nfor i ...
eJzt3UmuNdmWFGAaDOTotVNo+/ZqOyNBIhANyAadIBuZEhKkhMQUYBDMEvvMb/xRh8gWKV68hCj+uPcc912swpYtW//9X/6v//G//0X/92/+W/7h3/7Xv/yn7//uH/7+L//685f7u++P7XnGNtYz9vlc6zjve41rrT3/96zn2Mdx3fd+P5+5nfc89/357vv8U/7buOa17es+x7jn2Ld5bs92jWvf9v24x3Nez3Xd4zrv05+sse1jHPd8zuPej8+13/s58s/ffT+vfNh1HHN77ifPseVLj3Pc1zzyQOd155efeZ752u2+L9+49uNa29zy...
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
9,305
Rational Sums
Today Konstantin learned about convergence of series. For instance, series $$ \sum\limits_{n = 1}^{\infty}\frac1{n(n+1)} = \frac12 + \frac16 + \frac1{12} + \dots = 1, $$ $$ \sum\limits_{n = 1}^{\infty}\frac1{n^2} = 1 + \frac14 + \frac19 + \frac1{16} + \dots = \frac{\pi^2}{6}, $$ converge, while $$ \sum\limits_{n = ...
hackerrank
Hard
{ "class_name": "Result", "func_sign": [ "public static int rationalSums(int n, List<Integer> a, List<Integer> b)" ], "script_name": "Solution", "solution": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays...
{ "solution": "import java.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 InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n void solve(...
{ "solution": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashSet;\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...
{ "class_name": null, "func_sign": [ "rationalSums(n, a, b)" ], "solution": "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\n#\n# Complete the 'rationalSums' function below.\n#\n# The function is expected to return an INTEGER.\n# The function accepts following parameters:\n...
eJzsnbuubdt2VRHiQ6Zu7KC/HyT8BhJHIgAHJAcHtmQJIRHw4dRS+lwXpKubEi2Q7XX23mvOMfqjPWut7X/9u//4H/73v/03/+l//OW//flP//LPf/n3n7/U0v/4s93aPr3OT733M3b93Fo/fbXxaaufzx3rU+dpn9FH/ui0k78c8zNqW59RxqfPtT6ttPxR6/vT72qfenr9rNs/bc6dv1z7M+65n15azXeMk9/c+dv8+Km156vz6/XM/uGj987fjzxFW/mOfFs+4h7+s5f8Rcvjnvzt6Pm7mm8cKw8+Zp66nvzmqufT+uRh87e35i95...
null
65
Vertical Sticks
Given an array of integers $Y=[y_1, y_2, \ldots, y_n]$, we have $n$ line segments, such that, the endpoints of $i^{th}$ segment are $(i, 0)$ and $(i, y_i)$. Imagine that from the top of each segment a horizontal ray is shot to the left, and this ray stops when it touches another segment or it hits the y-axis. We const...
hackerrank
Medium
{ "class_name": "Result", "func_sign": [ "public static List<Double> solve(List<Integer> y)" ], "script_name": "Solution", "solution": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\t\n\tstatic pr...
{ "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;\nimport java.io.*;\nimport java.util.Arrays;\npublic class Solution\n{\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int no_cases = scanner.nextInt();\n for (int i = 0; i < no_cases; i++) {\n int n =...
{ "class_name": null, "func_sign": [ "solve(y)" ], "solution": "cs = int(input())\n\nfrom functools import reduce\n\ndef perm(n,r): return(reduce(lambda x,y: x*y,range(n-r+1,n+1),1))\n\ndef fact(n): return(perm(n,n))\nfor c in range(cs):\n n = int(input())\n li = [int(i) for i in input().strip().split...
eJy1msuOJUkRRFnMjp9I9YLV6Co9IjwefAkSjVjALNgUs5iRkBASHwH/ix3z2z09U10lIQHM7fvIzHj4w9zcov75zb9//Ztf+X+/+0Yffv/3D395+f7HHz789vqQH1/6+fiy5r52O1e2dZ1+X232a892nWxXn3H1O68x9FpT1+Jacc2xrjjjGrtd677OfV9rz2vqvW3dee6rR+jzlf1aLa/Z9e0eVx9xZeS1usaOfmlKzdJuzaxxpt410Wzz40veH1/Gva/Red1X8L6vWHl1vZh96fJMLTA0vdamO3asa+e45plXHg2uEdd99Mi1T/rO...
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