question_id
int64
700k
876k
question_title
stringlengths
3
81
question_content
stringlengths
131
2.51k
dataset
stringclasses
1 value
difficulty
stringclasses
3 values
java
dict
python
dict
test_cases
stringlengths
200
208M
704,548
Count of sum of consecutives
Given a number N, the task is find the number of ways to represent this number as a sum of 2 or more consecutive natural numbers. Examples: Input: N = 10 Output: 1 Explanation: 10 can be reprsented as sum of two or more consecutive numbers in only one way. 10 = 1+2+3+4. Input: N = 15 Output: 3 Explanation: 15 can b...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1616498561, "func_sign": [ "static int getCount(int N)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read...
{ "class_name": "Solution", "created_at_timestamp": 1616498561, "func_sign": [ "getCount(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n\n ob = Solution()\n print(ob.getCount...
eJy9lL0KwjAUhR30PUrmIkmTtIlPIlhx0A4u1aEFQRQfQl/JzXcy9Icici7eDmYKNB/ny2lvb9PHazZp1vIZNquz2JfHuhKLSKi89M0KGxFHojgdi21V7DaHuhqOXMPDSxx9c07zMZel1ugEghrnOSklFjUGkEp2C6KOlh1XTvD1bFAl2tg0o0iIQkQCAr8ERHjXBoVifrmlxapDtSM0upYUYfRRJVUndGzwkWHcj3sIK/+axg/LibNskXamPTHUSQbvYPnuIARleEf/qvAQM93aWezbpSaqV13f52+/4sIu
702,849
Print Binary Tree levels in sorted order
Given an array arr[] which contains data of N nodes of Complete Binary tree in level order fashion. The task is to print the level order traversal in sorted order. Examples: Input: N = 7 arr[] = {7 6 5 4 3 2 1} Output: 7 5 6 1 2 3 4 Explanation: The formed Binary Tree is: 7 / \ 6 5 /...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public static ArrayList <ArrayList <Integer>> binTreeSortedLevels(int arr[], int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass GfG\n{\n public static void main (String[...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "binTreeSortedLevels(self,arr, n)" ], "initial_code": "t = int(input())\nfor tc in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n\n ob = Solution()\n res = ob.binTreeSortedLevels(arr, n)\n\n ...
eJyllE1KxEAQhV2I53hkPUh39U8STyIYcaFZuImzyIAgiofQK7jzjlZVjGZgutPDDBUImX5fVb+urvfzz++LM/1df/HLzUv1OGx3Y3WFynaDhOmGaoOqf97292P/cPe0G+cFBt3wxn+/brCvIw6DjJREmtY7DoM8wv0iKEnxHAarIC8A0oW5mgKHQQkwCMPp2pUKI4dBITYKxuvyGeuS5IbDoDYo5zcCiyqa/VhkS+SxQR5YD+tgCdZyCrRoUCMiwMOBv6Z7KAjeCaAbWtEKgeQj6xzrA3Nq5iUK4P0k4Yd7Sx+1owU1oBoUQQHkQVws...
702,681
Subarrays with given sum
Given an unsorted array arr[] of integers and a sum k. The task is to count the number of subarrays that add to a given number k. Examples: Input: arr[] = [10, 2, -2, -20, 10], k = -10 Output: 3 Explanation: Subarrays with sum -10 are: [10, 2, -2, -20], [2, -2, -20, 10] and [-20, 10]. Input: arr[] = [1, 4, 20, 3, 10,...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public static int subArraySum(int[] arr, int k)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "subArraySum(self,arr,k)" ], "initial_code": "# Initial Template for Python 3\n\n\nif __name__ == '__main__':\n tc = int(input())\n\n while tc > 0:\n arr = list(map(int, input().strip().split()))\n k = int(i...
eJztVs1OhDAQ9uDNl5j0vDVMoRR8EhMxHpSDF9wDm5gYjQ+hb+HNF/QbKBtXKT/q6m5iYdKWdqad6ddveDx8fj06aMrpCxpnd+q6Wq5qdUKKi4qjppDuGvM/FFWkFqTK22V5WZdXFzerurOfFtVDUan7BW2uqi0xGdIxOdIpJWjnpDOK5ZM8TDqhiCxpW1TxXPPrHdq2Nr7ra+e78Xt/sKD3xmsHFjWBNSPa+jMQaONsKNQI5c69goCgL0FHPgLxv7FXjebQ2zLz6BvUgC5MSxCJkINQA6XCHqAQR5nQBzgkx3WWFYlFiYmhBmEoQhiq...
702,139
Find All Four Sum Numbers
Given an array arr of integers and another number k. Find all the uniquequadruples from the given array that sum up to k. Examples: Input: arr[] = [0, 0, 2, 1, 1], k = 3 Output: [0, 0, 1, 2] Explanation: Sum of 0, 0, 1, 2 is equal to k. Input: arr[] = [10, 2, 3, 4, 5, 7, 8], k = 23 Output: [[ 2, 3, 8, 10],[2, 4, 7,...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1617213044, "func_sign": [ "public ArrayList<ArrayList<Integer>> fourSum(int[] arr, int k)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String[] args) throws IOExc...
{ "class_name": "Solution", "created_at_timestamp": 1617213044, "func_sign": [ "fourSum(self, arr, k)" ], "initial_code": "# Initial Template for Python 3\n\n# Main\nif __name__ == '__main__':\n t = int(input())\n while t:\n t -= 1\n A = [int(x) for x in input().strip().split()]\n ...
eJzdVjtu3DAQTZEulxioNgP+tJJyEgNW4MLZIo3iYg0YCGzkEMl9PV+BBjxaC94qqw+Gw/fekEMuNX8+/7v98ol/19do3Pzufi73D6fuG3RpXhJECPzKQBfaoc5LnJfuCrrj4/3x7nT8cfvr4aScUBHMSAYnsSI7iZzMIleCeXlGqacreB02FENW6Ocl++EYSDBHqYceCj4Yml8oNfpqgu09sRQpG/zg4COnBa0eBxoxJeT2tXNUIqPB2sC3dgUWxZeXlx7TDzRpzSHNvUiSNkIzC0GUAyQXtWiZzCIRsmjJerWy+CiKGoSTATCzilpl...
703,026
Maximum distinct elements after removing K elements
Given an array containing integers. The task is to find the maximum number of distinct elements after removing K elements from the array. Examples: Input: arr[] = [5, 7, 5, 5, 1, 2, 2], k = 3 Output: 4 Explanation: Remove 2 occurrences of element 5 and 1 occurrence of element 2 . Input: arr[] = [1, 2, 3, 4, 5, 6...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1618076356, "func_sign": [ "public long maxDistinctNum(int[] arr, int k)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\nclass Main {\n public static void main(String args[]) throws IOException {\n BufferedReader read = new Buffe...
{ "class_name": "Solution", "created_at_timestamp": 1618076356, "func_sign": [ "maxDistinctNum(self, arr, k)" ], "initial_code": "if __name__ == '__main__':\n import heapq\n\n tc = int(input().strip())\n while tc > 0:\n arr = list(map(int, input().strip().split()))\n k = int(input()...
eJzNlsFuEzEQhnNASPAUv/ZcIdtje8Y8CRJBHCAHLqGHVKpUIfEQ8Lzwe61NoFlvk6aVunY8h4zHnpnPHv989fv129X4ffjzZrX6eDd8217f7Ib3GPx6651zOGdYb9NwhWFze735stt8/fz9ZnewNvy4wrH9OrWMXxPWhDaRm0hNxCakidAE7Vhn0TC7KALkcY2Te/7J/FLHLezbwXDctzS19Tb0lkrzoURwEIfokByygzoYQzsmBp7/eyp4aniqeOp4Knlqear5Uue7aqeXQHdqBstcPu+LudBc2NZb6W0+dvaOpd/owf/dpq5jJ50k...
714,438
Game Of Subsets
Elena is the topper of the class. Once her teacher asked her a problem. He gave Elena an array of integers of length n. He calls a subset of array arr goodif its product can be represented as a product of one or moredistinct primenumbers. He asked her to find the number of differentgoodsubsets inarrmodulo10**9+ 7. Exam...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1680673077, "func_sign": [ "public int goodSubsets(int[] arr, int n)" ], "initial_code": "// Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n// Position this line where user code will be pasted.\n\nclass GFG {\...
{ "class_name": "Solution", "created_at_timestamp": 1680673077, "func_sign": [ "goodSubsets(self, n : int, arr : List[int]) -> int" ], "initial_code": "class IntArray:\n def __init__(self) -> None:\n pass\n\n def Input(self, n):\n arr = [int(i) for i in input().strip().split()] # arra...
eJydU0EKwjAQ9NCHDDmLZDdtrb5EMOJBe/ASPVQQRPER+jpvvsTEFiroWtOmh4QyszOT6SW5PZLB65nd/WZ+VBu321dqCkXWhVcNocrDrlxV5Xq53VfNV23d2Tp1GuIDYrSAIRmTx0DYz/Ao+GVdah0jRQGSOGqpElPWMNVseTgxDDKMQb/N5yz4CZQMKsAaXCA6jyxY6pBgxDD1m6F2RV6jt8YT8ESASc7D8FY6yID8xhMZmYs0m/+C1PHN8nrS2AaHADuw4ryi+WskodLQ0OIe3nphvtxP3wt6ZdUn38+CdrBlJHWurqoovkEtrqMn...
703,157
Reversing the equation
Given a mathematical equation that contains only numbers and +, -, *, /. Print the equation in reverse, such that the equation is reversed, but the numbers remain the same.It is guaranteed that the given equation is valid, and there are no leading zeros. Examples: Input: S = "20-3+5*2" Output: 2*5+3-20 Explanation: T...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "String reverseEqn(String S)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\n BufferedReade...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "reverseEqn(self, s)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n\n for _ in range(t):\n s = input().strip()\n ob = Solution()\n ans = ob.rev...
eJydlMFOhEAMhj3oexCOMzu202HYHZ/ExDEelIMXdg9sYmI0PoS+kzdfyQIShaUDkbmQtP1p/37D2/nH18VZ91x/8svNc/5YH45NfpXlNtZWU6zzTZZXT4fqvqke7vbH5idMmhNeOfyyySZV5AqxrA/O16Eh1A5VgeBRVPAIBSqHmtBYlLT06MjtTPNm1YL6c0StSdasEoJVZJyWDSq0M6QsSJN5dskrS7oEJ4o4KLUlRd54SSexWcmFYNgi5O8rB4kBwPGInKetCZIPDkh5U+qt2akAVt62RQhqZ7a6NF5RO/L8vgfslg2WlkwD8DFK...
706,045
Smallest Positive Integer that can not be represented as Sum
Given an array of size N, find the smallest positive integer valuethat is either not presented in the array orcannot be represented as a sum(coz sum means you are adding two or more elements) of some elements from the array.Example 1: Examples: Input: N = 6 array[] = {1, 10, 3, 11, 6, 15} Output: 2 Explanation: 2 is...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1618056738, "func_sign": [ "long smallestpositive(long[] array, int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*; \nclass GFG{\n public static void main(String args[]) throws IOException { \n Scan...
{ "class_name": "Solution", "created_at_timestamp": 1618056738, "func_sign": [ "smallestpositive(self, array, n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n array = list(map(int, input()...
eJzFVMtKxEAQ9CB+R5HzIt09j0z8EBHM4kFz8BL3kAVBFD9C/9fuRBAls5uJgjNkZg7poqq6Zl5P37dnJ+O4utTD9VN13+/2Q3WBitueqe0FHgERNRIaMIEZLNUGVfe4626H7u7mYT981by0ffW8wQ+goB8EbhYM7MAeHHKoksMdYT9npjhmSpPJgxAcwRMCIRJqQqJSbWIknKoyPQGiQhNchA8IKlbVpgykZCBFfdfiJbOQbN32Tt0/ZhrnXLNEMJEZR2YdmXlk9pEZSGYhmYm6NLbYz6WOxrGrNA4045i2NG31tMVCV0fusDwncIQT...
703,307
Play With OR
You are given an array arr[] of length n, you have to re-construct the same array arr[] in-place. The arr[i] after reconstruction will become arr[i] OR arr[i+1], where OR is bitwise or. If for some i, i+1 does not exists, then do not change arr[i]. Examples: Input: n = 5 arr[] = {10, 11, 1, 2, 3} Output: 11 11 3 3 3 ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1619081437, "func_sign": [ "public static int[] game_with_number(int arr[], int n)" ], "initial_code": "//Initial Template for Java\n\n//Initial Template for Java\n\n//Initial Template for Java\n\n/*package whatever //do not write package name here */\n\...
{ "class_name": "Solution", "created_at_timestamp": 1619081437, "func_sign": [ "game_with_number(self, arr, n)" ], "initial_code": "# Initial Template for Python 3\n\nfor _ in range(0, int(input())):\n n = int(input())\n arr = list(map(int, input().strip().split()))\n ob = Solution()\n res = ...
eJzVVsuOYzUQZcEH8AmlrEfI9XDZNV+CRCMW0As2YRY9EhICzUeAxI5f5ZTt252MuJlOk5YYS/G5yY2Py/U45Q9f/vn3V1+M8c1fePj218NPx3fvHw5v6cB3Ry75mYNiDupzUJuDfA6qc5DNQToHyRzEcxze0OH+l3f3Pzzc//j9z+8ftt1yD5ZGXMw9TIldVMyYWrdmHNhQpXGl2qpLb9RqqGkjtdJKY8LbGl23je6Ov98dD7+9oX85EwkZdWyBReRGLJ2k4gwsO/YpOf5FYmSdAs8hpN2oec9Ve5tVfESteqMJnSYETSg0gWmC0ASl...
705,079
Tom and Jerry
Tom and Jerry being bored in this pandemic, decides to play a game. Given aninteger N. On each player's turn, that player makes a move bysubtracting a divisor of current N(which is less than N) from current N, thusforming a new N for the next turn.The player who does not have any divisor left to subtract loses the game...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int numsGame(int N)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "numsGame(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n\n ob = Solution()\n print(ob.numsGame...
eJy1lMGOgjAQhj2Y+AR780B6NqalLeA+iYmz2YNy8FI9YGJiND7E7vs6wihV2woR/gNtCNP++f5hzsP/8WhQav6Fm8WBrc12V7DviAkws0oZm0Qs32/zZZGvfje7ov7iBIYdJ5GzbOYp454ywUltrpPXOjCxBiPTYCG3nk+H6NvleBCtklZFq37vzPd8uixGQFmaaCVxJ2KpdJKGCTuPUfiehK5J6JuEzknBFGw0vjivTgVHz23yRAMJCUxKApORGiTlhVcpqeH5Gk34E7/RUz3js8J25v5JB5St/9D/b/6DV89euh3hfaHrhNASdxMk...
706,066
Repeated String Match
Given two strings a and b, find the minimum number of times a has to be repeated such that b becomes a substring of the repeated a. If b cannot be a substring of a no matter how many times it is repeated, return -1. Examples: Input: a = "abcd", b = "cdabcdab" Output: 3 Explanation: After repeating a three times, we g...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1618484723, "func_sign": [ "static int repeatedStringMatch(String a, String b)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1618484723, "func_sign": [ "repeatedStringMatch(self, a, b)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n for _ in range(t):\n A = input().strip()\n B = input().strip()\n ...
eJytU8EOwiAM9bAPWThPk6knv8TEGgMbBy+VKSbbjMaP0H/1pjBHVJIaIZau3YHXwuP1nFzvyaCz+c38LA5sjWqv2SxlOSAXdrlsF8tSJmslCy3L1Wav+71jwBMgO2apX6AALEy0TmCnBLYGbAjIMKf6cUDBOdWKxNVNa9xl46H35EI8I9n7C0UlYGmT+QjwhACrarvTymUbQm/eduaytYjzS/PIpYxQhyevDyaD395oDXrdkGIj0T6TKpzKV4k/1IgBOzYJHD00PeXhc8O5P+Rx86cq7Qv5/WCRUgD+oxiWl9EDBKa32Q==
702,738
Maximize sum after K negations
Given an array of integers of size N and a number K., You must modify array arr[] exactly Knumber of times. Here modify array means in each operation you can replace any array element either arr[i] by -arr[i] or -arr[i] by arr[i]. You need to perform this operation in such a way that after K operations, the sum of the ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617735976, "func_sign": [ "public static long maximizeSum(long a[], int n, int k)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\nclass GFG {\n\tpublic static void main(String[] args) th...
{ "class_name": "Solution", "created_at_timestamp": 1617735976, "func_sign": [ "maximizeSum(self, a, n, k)" ], "initial_code": "# Initial Template for Python 3\n\ndef main():\n T = int(input())\n\n while T > 0:\n sz = [int(x) for x in input().strip().split()]\n n, k = sz[0], sz[1]\n ...
eJylks1uwjAQhHvgQUY+s5V/4iD1SSrhqgeaQy+GQ5CQEFEvfQN4X9YtSFA6biqixMphv52Z9X5MDp+Th6/nedCf+da859W6N08wLmUHPcRZa6Yw3WbVLfru7XW57s8l1qY8pGx2U1yTHj5lC3GMJFw4KaJ8jusSvEEsOM4v4T3BI0IJ7RGgnZh44N7Vl0RECIUjlS6shwRIozykJS3Es/Qt2mK/DE8P/UiHSoDv6ekACNrU7lvXAZVtYbYvo8c/ss9+bSKe1P+si83IwrF1bE43wiXi7X6P9c0WuS6jGi6l/2pVetwTt1x03cbL/vEI...
702,807
Remove all duplicates from a given string
Given a string str which may contain lowercase and uppercase characters. The task is to remove all duplicate characters from the string and find the resultant string. The order of remaining characters in the output should be same as in the original string. Examples: Input: str = "geEksforGEeks" Output: "geEksforG" Ex...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1619436605, "func_sign": [ "String removeDuplicates(String str)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main {\n\n public static void ma...
{ "class_name": "Solution", "created_at_timestamp": 1619436605, "func_sign": [ "removeDuplicates(self,str)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n tc = int(input())\n while tc > 0:\n str = input().strip()\n ob = Solution()\n ans = ob....
eJzNV8lu2zAQ7aHnfkPgc1Agza037bsl70tdFFqoXZQiS14SNOhHtJ/UWz+qImUYSW3Gsg2n0bsYoIbz+DjzNP7x/tefD+/wM/5d/fjy0ApgVhatz1et2xmkLJsFruBLoaImMM3u8nl/MFyu1vfklSqKsiyGcRyOc13BE/1ADhUlVmNNg6mRZZ1unvfm/aIcjsbrSfX+/XQ9WY2Xo8WwHBT9eS/v3nUyI9VhO9FiNVJCOZB80RNcHnAOazMWbVKt66sWWGXALoDzLS2LDeeXaD2i8zAOt+UUq5hQxecZncfTGOHA1vfrqycSfqpS0gzL...
701,314
Panagram Checking
Given a string s check if it is "Panagram" or not. Examples: Input: s = "Bawds jog, flick quartz, vex nymph" Output: 1 Explanation: In the given input, there are all the letters of the English alphabet. Hence, the output is 1. Input: s = "sdfs" Output: 0 Explanation: In the given input, there aren't all the lette...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1619237458, "func_sign": [ "public static boolean checkPangram(String s)" ], "initial_code": "//Initial template for JAVA\n\nimport java.lang.*;\nimport java.io.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG\...
{ "class_name": "Solution", "created_at_timestamp": 1619237458, "func_sign": [ "checkPangram(self,s)" ], "initial_code": "# Initial Template for Python 3\n\nimport atexit\nimport io\nimport sys\n\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput = iter(_INPUT_LINES).__next__\n_OUTPUT_BUFFER = io.String...
eJy1lM1OwzAQhDkgnmOVc4XgCjcuIE4gOCBRhJzYSdy6duo4cRJExYU3gPdl7RTaSv1zJXqKVHl2dubTfhx/f54c+d/TDD+e3yIui8pEFxCdD+VjzmBa8WQMsVZWQqoaGFWTogRVMw0EBOlaoCobymgAEWsKlhhGX1VlFiIz/PN9AKvKdwRFJy3EqGi5ySHlNUOljkkQfFopjYOyMlj3oci5bEClEAs3YloRbboBitGMuYG1ssGiN8pCzRouM9HO86AkNdCxWJPSJxKseYvuKLElCIzSJ8EzKP/c976DVV1hPknMFe1itB3RtLfYOxdt...
700,273
Find the number of islands
Given a grid of size n*m (n is the number of rows and m is the number of columns in the grid) consisting of '0's (Water)and '1's(Land). Find the number of islands.Note:An island is either surrounded by water or the boundary of a grid and is formed by connecting adjacent lands horizontally or vertically or diagonally i....
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int numIslands(char[][] grid)" ], "initial_code": "import java.util.*;\n\nclass GFG {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int tc = scanner.nextInt();...
{ "class_name": "Solution", "created_at_timestamp": 1637684577, "func_sign": [ "numIslands(self, grid)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n for _ in range(int(input())):\n n, m = map(int, input().strip().split())\n grid = []\n for i...
eJztV8tOwzAQ5MAX8AVWzhVap4RWfAkSRRygBy6hh1ZCQiDu3BD8L3l7Zx+JKtEeEK0aJa69Hu/Mjp330+/Ps5Pmc/1R3dy8ZI/lZrfNrkIWV2URilUZQwxUfatnam6rX3vbtNcdKHVo22M2C9n6ebO+364f7p522y5mFe5tVWavs4ATXYZlG6ebqo3WP3QT9OGHRoZNAqAeJwtY3zm44oUDbBEW7SywyBjY8gEUy0b/L8AhhMvi+tjmDrZYjSKZJWvaHhoxaENORdbTcAqALi004gowIoqDTwSPieIom500zGkqDSmGQEcSHccHpHbq...
703,460
Palindromic Series
You have given a number n. He has to create a lowercase alphabetical string from that number and tell whether the string is palindrome. a = 0 , b = 1….. and so on. The number of digits represents the character and you have to repeat the string till the sum of all digits.Note: No number will start with zero. Consider al...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public static boolean pallan(int n)" ], "initial_code": "// Initial Template for Java\n\n// Initial Template for Java\n\n/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\n\nclass...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "pallan(n)" ], "initial_code": "# Initial Template for Python 3\n\nfor _ in range(0, int(input())):\n n = int(input())\n ob = Solution()\n ans = ob.pallan(n)\n if ans == True:\n print(\"true\")\n else:\n ...
eJxrYJkazsoABhEBQEZ0tVJmXkFpiZKVgpJhTJ5lTJ6SjoJSakVBanJJakp8fmkJVLKkqDQ1Jq8OKF+ro4CmycLczBSnxrTEnGJcOg2NjE1MzcwtcFuLVzcMkOVoKCBHL8i/JsZGhgZkOdvIxMwChMnSbGxqbmkIJMgLMANLqNPJczgEkBNiQBeT62hjRAqjxO8QY1DTHJKhMTEUuo4qjotBiWEUp8Ldak6BY0H6EZFBfjpCTUpk5SEivEyxf0FOtCCvZMKIV+Kya+wUPQBrLK9b
703,541
Perfect Reversible String
You are given a string ‘str’, the task is to check that reverses of all possible substrings of ‘str’ are present in ‘str’. If yes then the answer is 1, otherwise, the answer will be 0. Examples: Input: n = 2, str = "ab" Output: 0 Explanation: All substrings are "a", "b","ab" but reverse of "ab" is not present in str...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617565167, "func_sign": [ "public int isReversible(String str, int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GfG\n{\n public static void main(String args[])\n {\n Scanner sc = new ...
{ "class_name": "Solution", "created_at_timestamp": 1617565167, "func_sign": [ "isReversible(self, str, n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input().strip())\n str = input().strip()\n ...
eJxrYJk6iYUBDCK6gYzoaqXMvILSEiUrBSXDmDwgSlTSUVBKrShITS5JTYnPLy1ByNbF5CnV6iigajECaiFVjzFQT1IyDk0GuDVVVVWRaJMJyKbEJBKtAulKJNlXpmBfJZGpjdTgMANrI906iL6U1DQS7YM6MyaGVIeCowB3HBAKFlCqxJMs8Tg3iZxgBSe0mGQ8AYQvqcXE4E42eMIHT/DgDdXEJDyZD48PkTQDOcihhSyBO4viCgJw8opBTmRQiohyJXaKHgAfSIMf
706,233
Minimum steps to make product equal to one
Given an array arr[] containing N integers. In one step, any element of the array can either be increased or decreased by one. Find minimum steps required such that the product of the array elements becomes 1. Examples: Input: N = 3 arr[] = {-2, 4, 0} Output: 5 Explanation: We can change -2 to -1, 0 to -1 and 4 to ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1616192424, "func_sign": [ "static int makeProductOne(int[] arr, int N)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read =\n new Buf...
{ "class_name": "Solution", "created_at_timestamp": 1616192424, "func_sign": [ "makeProductOne(self, arr, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n arr = list(map(int, input().split...
eJytlN1qwzAMhXexvYfwdV1sp2rrPclgGb3oclEKaSkpDEbLHmJ730lOGM3IcX9oHGQTcj7JsuSvx5/d00N6XtayeP00q3q7b8wzGV/WXNbWO+fIUZpijGTFmBGZ6mNbLZvqfbHZN52iiFEUx7I2hxH1SVMl0enrAMQDgndtMBqJ6HVWjIDaAXAhuByQickWVFyC8lNAUhcq7hjnJ+BglomUdddqAstCjQ8SupozUc8mc8RljRsP61FSM0DbKvMGcHNHlQrQ9sqQ/pLS1YQjTh8AnkNEHlImgtTBhBglclBrGbq7Q6EUAI1O9F+bXdll...
711,970
Cheapest Flights Within K Stops
There arencities and m edges connected by some number of flights. You are given an arrayflightswhereflights[i] = [fromi, toi, pricei]indicates that there is a flight from the cityfromito citytoiwith costpricei. Examples: Example 1: Input: n = 4 flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]] src = 0 dst =...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1662019333, "func_sign": [ "public int CheapestFLight(int n,int flights[][],int src,int dst,int k)" ], "initial_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\nclass GFG {\n public static void main(String[] args) throws IOExcept...
{ "class_name": "Solution", "created_at_timestamp": 1667207782, "func_sign": [ "CheapestFLight(self,n,flights,src,dst,k)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n test_cases = int(input())\n for _ in range(test_cases):\n n, edge = map(int, input().sp...
eJytVMFqwzAM3WHsO4TPbbElO4V+yWApPWw59JL2kEJhrN1HtP872Y4TBlaaNjXGlkF+T9KT/ft6Pb+9hPF+ZOPjW23r/aFRK1CmrBF40WDAac1GWfujmoGqjvvqs6m+NrtD07oHl1NZq58Z/EchwIhivIsBjAZPlOHmRkSjLBobroc1AiyKUVqwOVwESgQEtiXgCEggIJGgAJeKGfFdC+93xg47r2Hnyd5WysJJJEtYDmbheYLhiYLhoEgJFl0FC55362yTMpS4KXFTXzhJmduCY4LFjOAowNqHBSfQkxqVC9vht/FGy0SGnqvXJQjT...
701,374
M-Coloring Problem
You are given an undirected graph consisting of vvertices and a list ofedges, along with an integerm. Your task is to determine whether it is possible to color the graph using at mostmdifferent colors such that no two adjacent vertices share the same color. Returntrueif the graph can be colored with at mostmcolors, oth...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1728031496, "func_sign": [ "boolean graphColoring(int v, List<int[]> edges, int m)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader...
{ "class_name": "Solution", "created_at_timestamp": 1728031496, "func_sign": [ "graphColoring(self, v, edges, m)" ], "initial_code": "def main():\n t = int(input())\n for _ in range(t):\n n = int(input())\n edges_input = list(map(int, input().split()))\n m = int(input())\n ...
eJzNVttKw0AQ9cFHPyLkuchespvELxGMiGgEQWLRFARR/Aj9Ut988sxJbWtNQpumid3ZzQxsmDNnLunb4cfX0QF/p59Qzp7D22I6K8OTILRZ4bJCBTpQgcG22BEsg22xI2gWO8IZZQWu+42v4+nwdNDgo3pbXpXreJl2OAnC/GmaX5X59cX9rJzDurm8e8yz4jUrllr5MKuU8GUSrISgs0KrJaglEIftYcWwElgprBgrwUqxFEE1IGjxZtRqHJahIkQsv+ZBK4qmGIqlRBRH8ZSYklBSkVZ+2rhI/iZIAZsGNgNsFtgiYHMCzQuyWIAl...
703,567
Minimum Swaps for Bracket Balancing
You are given a string S of 2*N characters consisting of N ‘[‘ brackets and N ‘]’ brackets. A string is considered balanced if it can be represented in the form S2[S1] where S1 and S2 are balanced strings. We can make an unbalanced string balanced by swapping adjacent characters. Calculate the minimum number of swaps n...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int minimumNumberOfSwaps(String S)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n Buffe...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "minimumNumberOfSwaps(self,S)" ], "initial_code": "# Initial Template for Python 3\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n S = str(input())\n ob = Solution()\n print(ob.m...
eJxrYJnKy8YABhFsQEZ0tVJmXkFpiZKVgpJhTF50LBBEA0FMnpKOglJqRUFqcklqSnx+aQlUkVlMXh1QslZHAVUnWBtIcyxuveY49IIsBNsci1OrAS5ro2EQp1ZTnFqhtuLWaoTLwSDfQkIKt5NN8IYU2WEF0gVGeLXjDi9YFMficboFbn/DohlMkpxK4DGNx3KcTgdbCgsCtAgkHCLGRMUlqgBmbJEb3bGxGA5GNTwPLEiy65HTP/GpA0+WgKUOfDFkSWFQohcX5AZtdCyym7GmT0gyB+IYCjINqf4iPdYpDQmU4CS5jImdogcAyocL...
701,368
Minimum Platforms
Given arrival and departure times of all trains that reach a railway station. Find the minimum number of platforms required for the railway station so that no train is kept waiting.Consider that all the trains arrive on the same day and leave on the same day. Arrival and departure time can neverbe the same for a trainb...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615979900, "func_sign": [ "static int findPlatform(int arr[], int dep[])" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws I...
{ "class_name": "Solution", "created_at_timestamp": 1615979900, "func_sign": [ "minimumPlatform(self,arr,dep)" ], "initial_code": "# Initial Template for Python 3\n\nimport atexit\nimport io\nimport sys\n\n# Contributed by : Nagendra Jha\n\nif __name__ == '__main__':\n test_cases = int(input())\n\n ...
eJy1VMtOw0AM5MCBz4hyrpC9u86Dz+AEIogD5MAl9JBKlRCIj4D/xeOEFKRuaR7tYeRuHM+MY+/H+dftxZn9bq41uHtNn5v1pk2vkpSrRqrGeSkTImIFJgVHifOe9Ekg/Pd2KIgkQXa6StJ6u64f2/rp4WXT9uV81bxXTfq2Sv5yZFVDBSoVqFQiKjVi5VQAERUgLgKeICoDnjAgUISNI2yFlsvAkbFKzkCZBY1ynOU4y3GWB0Ei2DJnOQCxHICzHICMVcBwJKATlBKUEnAK6gk4eoEDuTVBIE7QaPEAqBaBCZIfO848iXmKyHIRWblS...
702,128
Prerequisite Tasks
There are a total of N tasks, labeled from 0 to N-1. Some tasks may have prerequisites, for example to do task 0 you have to first complete task 1, which is expressed as a pair: [0, 1]Given the total number of tasks N and a list of prerequisite pairs P, find if it is possible to finish all tasks. Examples: Input: N = 4...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public boolean isPossible(int N,int P, int[][] prerequisites)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n\tpublic static void main(String args[]) throws IOExcepti...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "isPossible(self,N,P,prerequisites)" ], "initial_code": "# Initial Template for Python 3\nif __name__ == '__main__':\n test_cases = int(input())\n for cases in range(test_cases):\n N = int(input())\n P = int...
eJxrYJnqzsoABhEOQEZ0tVJmXkFpiZKVgpJhTJ6hARAAqZg8SyBQADKVdBSUUisKUpNLUlPi80tLoGojU4tj8uqA0rU6CqhGmIKRgQLINAWjmDwjBeOYPGMFk5g8Ezzm+eXjMM4QqIccZ5iBnWEIstII5BZjkFtMQG4xBbmFquYZkWGeETiUDckKYggyICc4jcE2Q2OHbP2IYCDZ7RADjAg5AIcBIGtB2nHowhJtVI033O7F6s4YiH8NYGFmCo43PBmEcDqDixMbBgZEh5YBNkcT62H0mEUkNdKSGDSCSfEdEbFMUpKB5i6islfsFD0A...
704,897
Odd Game
Given an array of length N, starting from 1 to N. At each iteration, you remove all elements at odd positions, until only one element is left. Find the last remaining element. Examples: Input: N = 5 Output: 4 Explanation: Initial Array- {1,2,3,4,5}. After 1st Iteration- {2,4}. After 2nd Interation- {4} Threfore, the ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static Long oddGame(Long N)" ], "initial_code": "\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read =\n new BufferedReader(...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "oddGame(self, N)" ], "initial_code": "# Initial Template for Python 3\nimport math\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n\n ob = Solution()\n print...
eJyllEFqwzAQRbtI72G0DkUzGmkmOUmgLl20XnSjZuFAoLT0EMlJuuvpKuQ4oJJREmcWxkaar8/TH3/P9r/3d7lWP+nl8cO8xfWmN8vGQBvB5mqjmTem2667l757fX7f9IctHglF2viVdnzOm7J5MZbe7oKwXQAqCoCOfGDRFQKDFQmkCPjBv3WqAAYh59MpmgWLpDYPiyf7OJlyOBGccPCpGyaDQyAmcaFi3RECM2oeeKzpHiyJjj0vniZeHF5VgbqEInaTcgoTlKLFR21Ygk/IdFjlxFSs6aE7BKeMUCVGZ6bnv1y8Ue+6m8nP9ur7...
703,576
Snake Case
Given a Sentence S of length N containing only english alphabet characters, your task is to write a program that converts the given sentence to Snake Case sentence. Snake case is the practice of writing compound words or phrases in which the elements are separated with one underscore character (_) and no spaces, and th...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static String snakeCase(String S , int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\nclass GFG {\n public static void main(String args[]) throws IOExce...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "snakeCase(self, S , n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n\n S = input()\n\n ob = Solution(...
eJydk81Kw0AQxz3oeww5F7H25i1ai4ql9QsER4Ztummi6e6aTWxUFN9Bvfi07pb0UHBC22EDWXZ/8/Gf2c/tn9+drbndfrmfu7cgVaYsggMI2qg6+6iuE3lRptHjYa5nqqers3Jq7OBZ5u7gXLy+dPUkaEEgKyOjQo5Jl0XtoEjkkydHnox19eBJ7Uh3kDkS1Qeq4L0Fy0HdEoxHwSPhmkjHIcBC1IAJYNNjMacjAEMRcVV1vPqphVMLIVxLW7BCp5bcElRI2+BMwAiOoAsSejCBhK1iRBGNSVJME64e9/XTCgYx3AyHx5cg1BgyPZM5...
706,374
Shortest Prime Path
You are given two four digit prime numbers num1 and num2.Find the distance of the shortest path from Num1 to Num2 that can be attained by altering only single digit at a time such that every number that we get after changing a digit is a four digit prime number with no leading zeros. Examples: Input: num1 = 1033 num2 ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "int solve(int num1,int num2)" ], "initial_code": "//Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n//Position this line where user code will be pasted.\nclass GFG{\n public static void main(String args[]...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "solve(self,num1,num2)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n num1, num2 = map(int, input().split())\n ob = Solution()\n ...
eJytUzEOwjAMZIAnsDFYmQtqarWJeQkSRQzQgaV0aCUkBOIR8F+cNiCKWJySKYpy9t35fBs/ZpNRe1ZTvqzP6lBWTa2WoHRe6pg0kEFUEajiVBW7uthvj03tv8z5zzUv1SWCLyBmGoxJ5cAYCWxmSQpM0BigLNPyjjEBUSLu6DDg0FIgpikBmyqnmnBHSwHjcBqttUbeETkARHJgO8d3EnwpDBhsZ7OvxDq8gU4Nm6gDXPxBzQWIBlBjXgFB6DHpqug2/N6vMMN6VR3FAQq7rfrckpAN8yEKxf3J19eD1N/NffEEsraAGA==
714,333
Dominant Pairs
You are given an array of integers of size n where n being even.. You have to calculate the number of dominate pairs (i,j).Where a pair is called dominant if (0<=i<n/2, n/2<=j<n, arr[i]>=5*arr[j] )theserelation arefulfilled.For examplein arr=[10,3,3,1] index i=0, j=3 form a dominating pair Examples: Input: n=4 arr={10...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1679378090, "func_sign": [ "public static int dominantPairs(int n, int[] arr)" ], "initial_code": "import java.io.*;\nimport java.util.*;\nclass IntArray\n{\n public static int[] input(BufferedReader br, int n) throws IOException\n {\n Strin...
{ "class_name": "Solution", "created_at_timestamp": 1679378090, "func_sign": [ "dominantPairs(self, n : int, arr : List[int]) -> int" ], "initial_code": "class IntArray:\n def __init__(self) -> None:\n pass\n\n def Input(self, n):\n arr = [int(i) for i in input().strip().split()] # ar...
eJy1VEtOwzAQZQH3GHldo4xJbIeTIBHEArJgE7pIpUoIxCHgEOw4IuPntmqqDqSWsKVRrBm/9+bjvJ9/fl+cYd18ycfti3kalqvRXJPhbnDdYLmSRbDdYBZk+vWyfxj7x/vn1bgJFc+bOF8XNL1f7+7bVhbBlEH5bthTQhPYZCNsUHFbBTceSNzD2lBtlUf6lUATzuKwDQhq2CtYt8sCNIQzXIhqSmoEKqAlQnCAIh2FRTiEQfAF/WRsqVNDeXPeKgR7vYeWRZbUQIohqsj6kxuWkkw5tRXFikJFHrm1FCmQDucaDQ+qfG5H7hPnRnHu...
703,889
Number of factors
Find the number of factors for a given integer N. Examples: Input: N = 5 Output: 2 Explanation: 5 has 2 factors 1 and 5 Input: N = 25 Output: 3 Explanation: 25 has 3 factors 1, 5, 25 Constraints: 1 <= N <= 100000
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int countFactors(int N)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\n BufferedRe...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "countFactors(self, N)" ], "initial_code": "# Initial Template for Python 3\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n\n ob = Solution()\n print(ob.countF...
eJydk8EKAiEURVvMh4jrIXyONNkntGsXNNGiXLSxWTgQRNFH1P+mhgTBVWbeStDjffc+fVbvTTWLtV37xe7Gz7YfHF8xTp0lXjNurr05OnM6XAb323p0lt9r9ndehAJQswCUBIAE57Uv1BlilEZdIZF2pAJB4xoSUqGAUcLBO7JCmdaEaMamTDhlhR0RsoSY6EhHmNJw/ZvAF0GXnsrowzdb4GA+LYlCtMusZMprgnTIqOwYT8nXxGl9fzjmkuX9a/4BSOxWEg==
702,769
Count Number
You are given an integer array arr of size n, along with two additional integers k and x. Your objective is to determine the number of distinct subsets of size k from the array where the absolute difference between the maximum and minimum elements of each subset is at most x. Return the number of valid subsets of size ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public long getAnswer(int[] arr, long k, long x)" ], "initial_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int t =...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "getAnswer(self, arr, k, x)" ], "initial_code": "# Main function\nif __name__ == \"__main__\":\n t = int(input())\n for _ in range(t):\n arr = list(map(int, input().split())) # Read the array elements\n k, ...
eJy9VMtuwjAQ7KHqd4x8RpXXdhyHL0HCVQ+QAxeXQ5AqVSA+An6TG/fakQgvLciQdh1Fm1jex8x416/b/dtLa6NddMY/Yhbmi0YMIciH9IDEAKL+nteTpp5+fi2a4/7KB7Ec4OKQPBgyXB80JJPJcplwtVL6JypOMeMr9zwUNAwKWJRwqGJfPhRwXBwjMyKBYl8KpEEGVIAsqAQ5UAWVKo6/OOTYPEcKqoN1nuu8svNs4sfk83OG7OlXLxBraDaS4tmOsEFLGIlCwkqUEi4C0crRhwQyGzWHuFYCXELL5yDFAsqUfnaNeuhD/4MCGaU/...
714,166
Maximum Length
Given the maximum occurrences of a, b, and c in a string. Your task is to make the string containing only a, b, and c such that no three consecutive characters are the same. If the resultant string equals to a+b+c, return the length (a+b+c) otherwise -1. Examples: Input: a = 3, b = 3, c = 3 Output: 9 Explanation: No ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1727768110, "func_sign": [ "int solve(int a, int b, int c)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass FastReader{ \n BufferedReader br; \n StringTokenizer st; \n\n public FastReader(){ \n ...
{ "class_name": "Solution", "created_at_timestamp": 1727768110, "func_sign": [ "solve(self, a, b, c)" ], "initial_code": "# Initial Template for Python 3\n\nfrom collections import Counter\n\nfor _ in range(int(input())):\n a, b, c = map(int, input().split())\n obj = Solution()\n res = obj.solve(...
eJytU0EOwiAQ9NCHbDhXw1I56EtMrPGgHLxgD21iYmp8hP7Kmx+SUuRiplXi0pCSMtOZgb1m92c28bV6uJf1WRxs1dRiSYJLy7IrWnRF/ULkJMypMrva7LfHpg6bld9T2ktpRZvTJw3FCTAU7hPAa6+inxnAvToGBMEABE8RkP1/3YNsQ82S3AAohAlxYyDUqUhBcxpgCipoDtOEtnCKCtlKjl/LkfyHkO8LwzHZpFSZ/GEmHIr+g4TYgXK0Bcc4UizE+/9lFw4TcWBICpJ/THJzm70AK/Bpxg==
703,758
Even Odd Sum
Given an array Arr[] of N integers.Find the sum of values of even and odd index positions separately. Examples: Input: N=5 Arr={1,2,3,4,5} Output: 9 6 Explanation: The sum of elements at odd places i.e at 1st,3rd and 5th places are (1+3+5=9) Similarly,the sum of elements at even places i.e. at 2nd and 4th places ar...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "ArrayList<Integer> EvenOddSum(int N, int Arr[])" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass GFG {\n public static void main(String args[]) throws IOException {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "EvenOddSum(self,N,Arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n Arr = list(map(int, input().strip().spl...
eJydlL8KwjAQxh30PY7MIpfU2NYnEaw4aAeX6NCCIIqLm6O+rxetStWvf0xLUkju1y/3HXfsXs+9zn1MTvIx3amV2+SZGpPSiZOXVZ9Uut2kiyxdztd5VuwyceIOiVP7PpWDjMSxDIplgOj3AQCxTwhTaQW84HEGwEYCKzAfK8LRHQhwWja8oI+ndaI8R5OhgIZkaUQhRRSLLgAyVlT9QqGA7z8GXniRTyhXV1x9mDhvGj28gxAtmxG898tbMFd6bJA6/rdef5caMoE1KjQY0z4DBuXV397gHLyLKmxRVdZWZMaEf1ilTVxvVqlPcFTb...
703,423
Maximum sum of subarray less than or equal to x
Given an array arr[] of integers and a number x, the task is to find the sum of subarray having a maximum sum less than or equal to the given value of x. Examples: Input: arr[] = [1, 2, 3, 4, 5], x = 11 Output: 10 Explanation: Subarray having maximum sum is [1, 2, 3, 4]. Input: arr[] = [2, 4, 6, 8, 10], x = 7 Outpu...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public long findMaxSubarraySum(int[] arr, long x)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader br =...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "findMaxSubarraySum(self, arr, x)" ], "initial_code": "if __name__ == '__main__':\n t = int(input())\n for _ in range(0, t):\n # n=int(input())\n a = list(map(int, input().split()))\n k = int(input())...
eJytVMtOxDAM5IDEb4x6rpCd1mnLlyBRxAF64FL20JWQEIiPgP/FMQVWyyZ97E4qNVKUseMZ+/38s7g4M1znurl5yR77zXbIrpBx239/WY6se95090P3cPe0Hf7O3/TwNcfeJTLsbGIEP+eHaTBrhTCJCOkcMfE/+g2EBjUqeAhKFHCWsMTpJM7kCAWhJAjBEypCrfSWa9u7RI4ump9QIAy8gX6kYkm9V+JkSKwQK0oqMcrGgNqAygBvgBjavphQyNllH3WZU1lKTdGrTLXKpZVm9ZUqVYBLsIA9uALX4EarZJ5I+eFoyzmiiTfJms6h...
702,078
Generate Parentheses
Given an integer N representing the number of pairs of parentheses, the task is to generate all combinations of well-formed(balanced) parentheses. Examples: Input: N = 3 Output: ((())) (()()) (())() ()(()) ()()() Input: N = 1 Output: () Example 1:
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public List<String> AllParenthesis(int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG{\n \n public static void main(String args[])\n {\n Scanner sc = ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "AllParenthesis(self,n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n for i in range(0, t):\n n = int(input())\n ob = Solution()\n result = ...
eJyEvc0OrVuSXUWDR+ABStlaIblBYf7EkyC5BA2oBp3EjbJkCYF4dDLP/mJGxJyjCsm69+5x1p4rfmbE2idtyf/vf/k//1f/4X/5L/7D//WX/+Ov//E//ctf/qd/+Mt/809//dv/+W//8u/+4S///J//4z//b//yz//7//p//qd/+f70vap/+uur97d//j9/+4/3d/AHvb/D/q96+q8/R//+h/2n9fpP6+lP6zWrn/jfv/B9o15/o15/o15NKArnL//3v/uHlco//tNf/7t/NY8v8vqSeOu/J5Ff/PPfX7hfNkr77RK8XY6ngpzivF2o...
703,302
Decreasing Sequence
A sequence arr[0], arr[1], …, arr[n-1] is called decreasing if arr[i] >= arr[i+1] for each i: 0 <= i < n-1. You are given a sequence of numbers represented by array arr[] and a positive integer k. In each operation, you may subtract k from any element of the sequence. You are required to find the minimum number of oper...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int minMoves(int arr[], int k)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\nimport java.util.HashMap;\n\npublic class Main {\n\n public static void main(String[] args) th...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "minMoves(self, arr, k)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n tc = int(input())\n\n while tc > 0:\n arr = list(map(int, input().strip().split()))\n\n k = int(in...
eJy9VMtKxEAQ9CD4G8Wcd2SeSdYf8OZZMOJBc/AS95AFYVnxI/R/naQn66LTmUTU6UAFQqq7q6vn9fT96uxkONeX4eVmJx7bzbYTFxC6brUaDtbDIagISoKCwBM4AktgCIhHrCCa501z3zUPd0/bLiZRdftSt2K/QjrzL2EgXFiAHBkSL1EOGfWQURAZFZFREhk1IbR9U0wRpmKq8KEBaA+jYDysgvVwCs7Dh8ItQ7fmm8Lxo8bg5fGZ+SSd4elbHurWLByLBYWJoWMcGuE04QiDvIHGwsGjQInQBK+Gy8nB4RjfzDRhCn41ejsEL7he...
705,235
Exit Point in a Matrix
Given a matrix of size n x m with 0’s and 1’s, you enter the matrix at cell (0,0) in left to right direction. Whenever you encounter a 0 you retain it in the same direction, else if you encounter a 1 you have to change the direction to the right of the current direction and change that 1 value to 0, you have to find ou...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int[] FindExitPoint(int n, int m, int[][] matrix)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String[] arg...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "FindExitPoint(self, n, m, matrix)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n n, m = input().split()\n n = int(n)\n m ...
eJzVVktuwjAQ7aKrnmLkNarGCSDUkyDViEWbRTcuiyBVqlpxiPaM3XEG/I9DPJCYj2giWZlk5s3n2TPZ3P9uH+7MNf9TD8+f7E2u1jV7AsaF5KAXNgJWfayql7p6Xb6va/cdAUHIbyHZ1wjadoWxExIJU06bciiM3xynhY+YND/guIRSW6IGUAugkwikgkaawMTaokVT4YARNTAagbcU3DvIKNcYxhY1wDtElwJaz2Q1Swp4ClMf+V7A6AWbVRCiL3upmztjKygIbGH4OoWUG1/Q0YxITGhiF7NJI9zNy04pCM3Yf8I7zcWBDTWDWaDU...
709,989
Maximum Meetings in One Room
There is one meeting room in a firm. There areNmeetings in the form of(S[i], F[i])whereS[i]is the start time of meetingiandF[i]is the finish time of meetingi. The task is to find the maximum number of meetings that can be accommodated in the meeting room. You can accommodate a meeting if the start time of the meeting i...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1650388626, "func_sign": [ "public static ArrayList<Integer> maxMeetings(int N, int[] S, int[] F)" ], "initial_code": "import java.io.*;\nimport java.util.*;\nclass IntArray\n{\n public static int[] input(BufferedReader br, int n) throws IOException\n...
{ "class_name": "Solution", "created_at_timestamp": 1650388626, "func_sign": [ "maxMeetings(self, N : int, S : List[int], F : List[int]) -> List[int]" ], "initial_code": "class IntArray:\n def __init__(self) -> None:\n pass\n\n def Input(self, n):\n arr = [int(i) for i in input().strip...
eJztV0FuFDEQ5MATeEBrTxwisNv2jM1LkFjEAXLgMuSQSEgIxCPgv1R1e7KbTWaTrAgsKKtYM+mx293V1eWZ709/vnz2xH6vn+PmzZfVx+ns4nz1SlZlPcWwnopEqRIkSZFBmsQgup5GUdwPkvFslBglqqT1VLGGMwoec3IQWBIfcmrjRBV6jUrv8IqhGAUD/wcZMEaMSkPxp7jjvAgbVpUgmfbik6P22W12EWlWeo+cGBuXDdwPzrAjoosIkPmpKOJWSwApjXTPFGBEvEx4RIKWtOcYkUwWmzRwSazwT7ca6UqTaIZr0QHeRKtow46r...
705,026
Find Prime numbers in a range
Given two integers M and N, generate all primes between M and N including M and N. Examples: Input: M=1,N=10 Output: 2 3 5 7 Explanation: The prime numbers between 1 and 10 are 2,3,5 and 7. Input: M=2, N=5 Output: 2,3,5 Explanation: The prime numbers between 2 and 5 are 2,3 and 5. Constraints: 1<=M<=N<=10**6
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "ArrayList<Integer> primeRange(int M, int N)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n B...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "primeRange(self,M,N)" ], "initial_code": "# Initial Template for Python 3\n\nimport math\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n M, N = map(int, input().strip().split(\" \"))\n ...
eJw03b2uNjvTLWQCAsRRLH0xwbzbdtnFkSCBRAA7IAGCjYREQsRx43F57Vda4+3H/efuu2aVPbpq+P/9r/+H//b/+2/+q//x//mP/+1//z//r//8H//9P//x+5/+998/vz//+4//7p//+E//9//5n/6X//yf/tf/+f/4v/7zv4d8/4x/1j/7n989cPzzuxv9zzf++fqf8ftn7H/m7585/pn7n3WP63/q90/tf/bvnz3+2f3PGf+c/qfvWX+50b3AX7b7Xu5uf3d75Lr5/9s273/r/nvdf9fdf6/027npbT+3vfPf/Xeu17cbt09f+nKv...
702,829
Smallest factorial number
Given a numbern. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Examples: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. Constraints: 1 <= n <= 10**4
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1619174988, "func_sign": [ "int findNum(int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\n\npublic class GFG\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n \n ...
{ "class_name": "Solution", "created_at_timestamp": 1619174988, "func_sign": [ "findNum(self, n : int)" ], "initial_code": "# Initial Template for Python 3\nif __name__ == '__main__':\n t = int(input())\n\n for _ in range(t):\n n = int(input())\n ob = Solution()\n print(ob.findN...
eJydlEEKwjAQRV30ICXrIpPUWPAkghEX2oWb2EULgigeQm/mzsuYhIhV/BPargrh5b/5HXrN7s9sEp7lw72sTmJvm64Vi1xIYyWJIhf1sam3bb3bHLo2ns20sRdjxbnIvwmNCEUIkQRTIKMho4gLwkmYwllzkgQohSmvwczFDAaxCqeVhCW9CdMI5HQ0hao48Z3qbue+vGaj3akZk145kqJFFQYgvOIlucYVV92AeXybeC0Tu8m3+WuQuA02GzQGNZQQ+zj1hxzh9b9p9vfUq3t9m74AyN13BQ==
704,179
Coin Change (Minimum Coins)
Given an array coins[]represent the coins of different denominations and a target value sum. You have an infinite supply of each of the valued coins{coins1, coins2, ..., coinsm}. Find the minimum number of coins to make the change. If not possible to make a change then return -1. Examples: Input: coins[] = [25, 10, 5],...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1730718619, "func_sign": [ "public int minCoins(int coins[], int sum)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1730718619, "func_sign": [ "minCoins(self, coins, sum)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n k = int(input())\n arr = list(map(int, input().split()))\n...
eJydVEsOgjAQdaH3mHSNhhYq1pOYWONCWbipLjAxMRoPoSsv67QS/oNSklJKmNd5H/oYv96TkbtWT3xYX9nBnM4ZWwIT2nCOIwR71wbXLACWXk7pLkv32+M5K7+8azPlbmK3ACoo+DLRJgIB8Y/6diEP8XITCBzSLiiIkMBQSiECbi8BmQiJKDRI3AWC3UXaLLSJHRWiNmdPilDS6QfoU6GnmioO3c5EEaVZvpWACFVLgNMIilMYUpv5cK5KdaSOSELBzho8WNRvpQuHl7Ci0ioVp4QMdpvXIAJNkUoYi+z9o9bb8ujLx0FdhMXby9oZ...
702,692
Kth boom number
Boom numbers are numbers consisting only of digits 2 and 3 only. Given an integer K, return the K-th Boom number. Examples: Input: K = 5 Output: 32 Explanation: The Boom series is 2, 3, 22, 23, 32, 33, 222.... and, for K=5, answer = 32. Input: K = 100 Output: 322323 Explanation: The 100th boom number is 322323. ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public static String BoomNumber(long K)" ], "initial_code": "// Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\nclass GFG {\n public static void main(String[] args) throws IOExcep...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "BoomNumber(self, K)" ], "initial_code": "# Initial Template for Python 3\n\ndef main():\n T = int(input())\n while(T > 0):\n K = int(input())\n ob = Solution()\n print(ob.BoomNumber(K))\n T -=...
eJyVU0EOgjAQ9MBDSM/EtFs94EtMxHhQDl4qB0hMjMRH6DO9+QDpliZwmAX2QJuwMzszLK/k80tWXPtvdzk81NVVTa12qTKFMypLVXmvynNdXk63pu5fUeHawqlnlo77CfRb0G8RPxqwQQA0wWiIQJAtgljCIEPIi+0K+jFaw2ke50cKUBHtwcQMxBfAkw8KkjEHH8wXHz11X0goziaQEs5HVEUDTcJ4ISWPjzZgzsGB5AKLj/PD6RdY57lGjqIc1iPI8YSSq8V6JtdpljJxH8cfazrs8E8tjTymMyee43v9B6Prd3k=
707,514
Scrambled String
Given two stringsS1andS2of equal length, the task is to determine if S2 is a scrambled form of S1. Examples: Input: S1="coder", S2="ocder" Output: Yes Explanation: ocder is a scrambled form of coder. ocder / \ oc der / \ o c As "ocder" can represent it as a binary tree by partitioning it ...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1621256084, "func_sign": [ "static boolean isScramble(String S1,String S2)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\nclass Geeks\n{\n public static void main(String args[])throws...
{ "class_name": "Solution", "created_at_timestamp": 1621256084, "func_sign": [ "isScramble(self,S1: str, S2: str)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n for i in range(t):\n S1, S2 = input().split()\n if Solution().isSc...
eJy9VU1PwzAM5YDE34h6npB25ciNC2cQRSht3SZt4qRJumVDIH4E/F+y8qHBWmkLZVWbWLb8XPm9OC+nb1dnJ/1zcxmMu8eEo+5cckGSeYo0ywsoK8brRkhUujXWkW6x9KvdiLMpJjOSgNeQOygeVOc+ka5Vis8h+jQjP/ENxULJ3kOW3DFUzuaGykzA4WAMhFBEbbbR5FuwI9ner8JLwhKMiHzLpRZgwNPNTsIXPGCoB6FlBF6uNjheU+fAIMFgK+1c6A6Mw432Zr3yy0XnrGm1QimamrOqJFDkGR0M9ZHDywzppZfLmkSUGW9Owcsy...
712,547
Graph and Vertices
Given an integer n representing number of vertices. Find out how many undirected graphs (not necessarily connected) can be constructed out of a given n number of vertices. Examples: Input: 2 Output: 2 Input: 5 Output: 1024
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1667798898, "func_sign": [ "static long count(int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nclass GFG {\n public static void main(String[] args) throws IOEx...
{ "class_name": "Solution", "created_at_timestamp": 1667544361, "func_sign": [ "count(self, n)" ], "initial_code": "# Initial Template for Python 3\n\n# Position this line where user code will be pasted.\nif __name__ == '__main__':\n t = int(input())\n\n for _ in range(t):\n n = int(input())\...
eJx83buudt1y7XUCJK6A3FrxDsbhGSeuBAlLBOCAxOzAWwIhEJdO/f59OiDwtr28vu9953wOffRevapVa63+3//2f/zv/8//7r/5n/6vf/xv//qf/8u//eN/+Kd/7P/8r/v2z//6j//0T//4l//jP//L//Jv//K//s//+3/5t7+/Pa/9/Z3Psb3vex7//K//z/zk//2f/un///vHf/z7+3V/x3P9zvP93fez7d/2Xe/3e87reuff9vveftsx//K+977v97a99/Eex+8/eK/rP36v63me6z6+d7uPedf7/L3v8X7f893nsV377z2u+Sjz...
704,399
Euler Totient Function
Find theEuler Totient Function (ETF)Φ(N) for an input N. ETFis the count of numbers in {1, 2, 3, …, N} that are relatively prime to N, i.e., the numbers whose GCD (Greatest Common Divisor) with Nis 1. Examples: Input: N = 11 Output: 10 Explanation: From 1 to 11, 1,2,3,4,5,6,7,8,9,10 are relatively prime to 11. Input...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static long ETF(long N)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader re...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "ETF(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n ob = Solution()\n print(ob.ETF(N))\n ...
eJydkz0KAjEQhS32IGHqRSbZjaz2dh5AMGKhKWziFlkQRPEQel83EV0tXiROFch8vPl5cy3ui2IUYznvH6sT7V3beZoJksZJKgXZY2u33u42h84PXxfj6FyK73yVmS8ZADUEIMEAmYYA0KRuGHG9FCfUGIJBDw0u/CFOIzGFCKVziQYVptHENSd8UFUqiaVG+IPlfM234msJufaVPKijsiXcu4atKsw8a46bgYNC/aaMje35x1nHEzIucX2fh7S+jR+RTlUp
706,253
Number of subsets with product less than k
Given an array arr[] of N elements. Find the number of non-empty subsets whose product of elements is less than or equal to a given integer K. Examples: Input: N = 4 arr[] = {2, 4, 5, 3} K = 12 Output: 8 Explanation: All possible subsets whose products are less than 12 are: (2), (4), (5), (3), (2, 4), (2, 5), (2, ...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1616601041, "func_sign": [ "static int numOfSubsets(int[] arr, int N, int K)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read =\n ne...
{ "class_name": "Solution", "created_at_timestamp": 1616601041, "func_sign": [ "numOfSubsets(self, arr, N, K)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n arr = list(map(int, input().spli...
eJytlM2KwjAUhV3oe1yyFmmSJrU+iTAZXMx0MZvoooIgig+hr+PO95qbTBiqclqrJi00DefL/TnkMDxdRoM45mf++NiKH79a12JGQjpvnJcZNZ6wjkOMSVSbVfVVV9+L5bpOGs2ivfNiN6ZrkmUlKdKUk6GwMICgNCCEwxXdzbChcgDjLYQrnNfUmPxHlQijLKBMY4FKmlJBljPLA8jg+shCAVL+nx0jLZIboDZ/5Y0vg/rWtgzymxkyAxwjUZv5AJsaDGuAaqmTRbo8VrTUoGHW5IyGZ9u9Aq2bQnvKf51efo+ZkQ1Ta/u78c4QTzvi...
710,028
Smallest sum contiguous subarray
Given an array arr[]ofNintegers. Find the contiguous sub-array(containing at least one number) which has theminimumsum and return its sum. Examples: Input: arr[] = {3,-4, 2,-3,-1, 7,-5} Output: -6 Explanation: sub-array which has smallest sum among all the sub-array is {-4,2,-3,-1} = -6 Input: arr[] = {2, 6, 8, 1, 4...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1646210347, "func_sign": [ "static int smallestSumSubarray(int a[], int size)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\nclass Geeks\n{\n public static void main(String args[])\n ...
{ "class_name": "Solution", "created_at_timestamp": 1646210402, "func_sign": [ "smallestSumSubarray(self, A, N)" ], "initial_code": "# Initial Template for Python 3\nimport math\n\nfrom sys import stdin\n\n\ndef main():\n T = int(input())\n while T > 0:\n N = int(input())\n A = [int(x)...
eJytkzsOwjAQRCngHiPXLMraMb8r0FEhEUQBKWhCiiAhIRCHgPtivgHBJg7guIhk7XjnzXpfPw4btcsaDdzPeKMWSbrKVB+Ko8TtQDWh4nUaz7J4Pl2usttpECW7KFHbJt5KiIPrEkof57JEiUKJgM4F8Gsz5skPPOR0sZx1rUHDIISVzMmlxCANMqAQJNUTW0Gh7eLE46sYrH2BekHhDVdLSbvLOuiCeuCzIIOdPTZg548tuF3Zoz5T4grxc1FiImRhasvscPlkf42qyKRE6/5ai/L7yCX04+L6zC8h41mk/aHnVK5Y/kNFYl1hLieH...
714,000
Knight in Geekland
Knight is at (start_x,start_y) in Geekland which is represented by an NxM 2D matrix.Each cell in the matrix contains some points. In the ith step, the knight can collect all the points from all the cells that can be visited in exactly i steps without revisiting any cell.Also, the knight has some magical powers that ena...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1676008615, "func_sign": [ "public int knightInGeekland(int arr[][], int start_x, int start_y)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n static BufferedReader br;\n static P...
{ "class_name": "Solution", "created_at_timestamp": 1676008615, "func_sign": [ "knightInGeekland(self, arr, start)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n test_cases = int(input())\n for _ in range(test_cases):\n n, m = map(int, input().split())\n ...
eJzlVs1OwzAM5sCdR+BTDpwmlJ+mPzwJEkUcoAcuZYdOQkIgHgLeFzfJQjsW1HZQpdrcZk7sOPFnN/H76efF2Yn5XZ8Tc/PCHuv1pmFXYKKsBajh4NSwFVj1vK7um+rh7mnTOCUSvZU1e12hP1NCupmCc9DrmZGGRDuprAsUxt4OFQscLciX4BNARwXQUVAuSgYnA5X567D0jMQ8QeIj2JqyGYAAEzAuAsY1tDNO+7bUspqWMs2A8cCKMrBiitQh1QnFt2+7Hg6Tehq5mRy5A5giIzkUR8JbB1OOjCMn47nhUjOaGA3pwxndjJEJ63LU...
712,207
Aggressive Cows
You are given an arrayconsisting of nintegers which denote the position of a stall. You are also given an integer k which denotes the number of aggressive cows. You are given the task of assigning stalls to kcows such that the minimum distance between any two of them is the maximum possible. The first line of input con...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1729852696, "func_sign": [ "public static int aggressiveCows(int[] stalls, int k)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String[] args) throws IOException {\...
{ "class_name": "Solution", "created_at_timestamp": 1729852696, "func_sign": [ "aggressiveCows(self, stalls, k)" ], "initial_code": "# Initial Template for Python 3\n\nimport bisect\n\n# Main\nif __name__ == '__main__':\n t = int(input())\n\n while t:\n t -= 1\n\n A = [int(x) for x in ...
eJy1lUtOAzEQRFkgcY3SrCPkbo9/nASJQSwgCzYmi0RCQiAOATdkxyVoG09CPs7kx0iRvXBqql91j9/PP78vzvJz/SWbm5fmMU5m0+YKDXWRFAgaFgHEoBbkwArMXTTNCM34eTK+n44f7p5m0/Iv08W3LjavI6xK9Y9ImsW+33WRK4qhfyrKSSS50gqtEmlYBafgFULW76KtKLOqmc1Fp+oNmMAe2qI1MFJdWxGjauU9QerxmawojjW0E9NddHvSZNE0cFlTJ1kKYA0O0JQ1Ca1G62DkXIAlWAdHcBouwGv4gOC66GvF8NYY+wDn8Qmo...
714,120
Max min Height
You have a garden with n flowers lined up in a row. The height of ith flower is ai units. You will water them for k days. In one day you can water w continuous flowers (you can do this only once in a single day). Whenever you water a flower its height increases by 1 unit. You need to maximize the height of the smallest...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1677585954, "func_sign": [ "long maximizeMinHeight(int n, int k, int w,int [] a)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\nclass GFG{\n\tpublic static void main(String [] args) thro...
{ "class_name": "Solution", "created_at_timestamp": 1677585954, "func_sign": [ "maximizeMinHeight(self, n, k, w, a)" ], "initial_code": "# Initial Template for Python 3\n\nfor _ in range(int(input())):\n n, k, w = map(int, input().split())\n arr = [int(i) for i in input().split()]\n print(Solutio...
eJzFVbtOw0AQpKDgM1auI3R7D9+Zr6ADCSMKSEFjUiRSJATiI+B/mV27iIXv4mAk4iK7vvPczOx6/XH+dXNxpr/bawR3r9Vzt9ltqyuquO3YEBtDARH9uNquWlG13m/Wj9v108PLbjs8GLD0jtW3FY3hLKAEERHNurJH2Jg5ggM5Q77t8A+EmjxF/EvGiGtKyPLUmwwsnjLk2s4BwSomAzNlcUTjtAUB+ikKv4YELUrO4MRKNylR9gQhUTc0QhhHJuR13vOiH1j1AOudSOqKVXhGFgo+s83hwgUjfCYao9gcttAcIIvKNWJHUpsgnrmP...
705,579
Transitive closure of a Graph
Given a directed graph, determine whether a vertex j is reachable from another vertex ifor all vertex pairs (i, j) in the given graph. Here,vertexjis reachable from another vertexi means that there is a path from vertex i to j.The reachability matrix is called the transitive closure of a graph. The directed graph is re...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static ArrayList<ArrayList<Integer>> transitiveClosure(int N, int graph[][])" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG{\n public static void main(String args[])t...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "transitiveClosure(self, N, graph)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n graph = []\n for i in...
eJztWdtKAzEQ9cHP8CHsc5FJwQt+ieCKD1rQl7YPLQii+BH6v+6l2WQmZ5K0sthiXSzJzNnT7FwO2fTz9HtxdtL93T43g7u36mW+XK+qG1PZen5Rz62xhpqrmTUf/aQdbib9sJu4YYetJqaavS5nj6vZ08NivXKcxl2Ozo2JjYmNqRt/NKzvE8NXeNmukDZrpJ6U+CqJr7Nbnh14h3tyC/fM4be0C9vVBx/oyodchl2E3k9FYqLkDAnyvGVJsptnGHcO43DNEusjEZhYgnk0WAmAMghKgQwzheWwTZisSC8Fda2VgMdQIYYSGBhGSy7r...
700,388
Maximum Difference
Given an integer array arr of integers, the task is to find the maximum absolute difference between the nearest left smaller element and the nearest right smaller element of every element in array arr. If for any component of the arr, the nearest smaller element doesn't exist then consider it as 0. Examples: Input: arr...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1723128541, "func_sign": [ "public int findMaxDiff(int[] arr)" ], "initial_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Stack;\n\npublic class Main {\n public static void main...
{ "class_name": "Solution", "created_at_timestamp": 1723128540, "func_sign": [ "findMaxDiff(self, arr)" ], "initial_code": "if __name__ == \"__main__\":\n t = int(input())\n for _ in range(t):\n arr = list(map(int, input().split()))\n ob = Solution()\n print(ob.findMaxDiff(arr))...
eJytlE8LgkAQxTvU9xj2LOG0adonCTI6lIcu5kEhiCLo1rm+b0/JDqsTNbZ/QFne29+8gb0MH7fRoB6LKz6WR7PL8rIwczKcZFjGI5Me8nRTpNv1vixeh36SnXF48shR+M34WRpQa/a4npiEH9GUBVML+RQ7oJgmFH7AshIWdBYeAdQziuDDMkYs1gZdBD0I4GXhKfdHNKHWVIRMNUtFU/FURKGGRN8SLAV1R3x/aEe/fnRkyYowHRhW0iBW1ubaXC0XpaXy6d061kfd/20RC62Kw9vgVOs8h99Rr+7jJ6PmkL4=
701,358
Nearly sorted
Given an array arr, where each element is at most k away from its target position, you need to sort the array optimally.Note: DO NOTuse STL sort() function for this question. Examples: Input: arr[] = [6, 5, 3, 2, 8, 10, 9], k = 3 Output: [2, 3, 5, 6, 8, 9, 10] Explanation: The sorted array will be 2 3 5 6 8 9 10 Inp...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1731518152, "func_sign": [ "public void nearlySorted(int[] arr, int k)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\nclass GFG {\n...
{ "class_name": "Solution", "created_at_timestamp": 1731518152, "func_sign": [ "nearlySorted(self, arr, k)" ], "initial_code": "# Initial Template for Python 3\n# Position this line where user code will be pasted.\n# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n ...
eJy1VUlOAzEQ5MCBZ7TmHCG3l/GYl0QiKAfIgUvIIZGQEBKPgP9S7TFDFttZBhK1bMVV1U532f64/prfXMXPdIrJ/VvzvFxt1s0dNTxbsqJAHXlqyZElQ5rwq5stmwk1i9fV4nG9eJq/bNaJMoBA8CAGYgXw+4T2dB0WIGkUaUcaGFPRBJQFJViT11NYVAJTQCCcgBVZzC1Gp0DTxRScqCKhtyR26Jms+KcmFkYKJIXiepqIt2AcqY5C3oDoJJA/SAREh/CIFmERqF+Q6tlizkFCJZldai/X9fKSN7cfp35L0WJ0MiI85t4N26w1cauS...
703,416
Maximum value K
Given an array arr[] of positive integers, find the maximum value of k such that there are at least k elements in the array that are greater than or equal to k. Examples: Input: arr[] = [2, 3, 4, 5, 6, 7] Output: 4 Explanation: 4 elements [4, 5, 6, 7] are greater than equal to 4. Input: arr[] = [1, 2, 3, 4] Output:...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "int findMaximumNum(int[] arr)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n public st...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "findMaximumNum(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n arr = list(map(int, input().split()))\n ob = Solution()\n ...
eJy1VcFOxCAQ9eDBz3jh6sYMtBTwS0xc40F78FL30E1MjMaP0P+V7exuRJ1WCBKax4T0zfBmGN5OP8zZyTSuzuPi+lk9DJvtqC6h9HrQBENoCC3BEjqCI3hCIGii9aBWUP3Tpr8b+/vbx+14+DNuvcbdlxW+800DYRoMnsExdAyWoWVoGAyDZphxr0X3yJkF54NBxic6MAv6aWSvRF+d4GufoyRlPjVdanapaQ9mvo6WaWqCHMSS2F+LtRhKijVxvyuZ5ijwUVuB1co3IMDDoYsUbSTc1aGOM2Jkb6GtwOjzSr7kMlS7JixZkBQXtTFz...
701,203
Equilibrium Point
Given an arrayarrof non-negative numbers. The task is to find the firstequilibrium pointin an array. The equilibrium point in an array is an index (or position) such that thesumof all elementsbeforethat index is thesameas thesumof elementsafterit. Examples: Input: arr[] = [1, 3, 5, 2, 2] Output: 3 Explanation: The eq...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1729449104, "func_sign": [ "public static int equilibriumPoint(int arr[])" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n\nclass Main {\n\n public static void main(String[] args) throws IOException {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1729449104, "func_sign": [ "equilibriumPoint(self,arr)" ], "initial_code": "# Initial Template for Python 3\n\nimport math\n\n\ndef main():\n T = int(input())\n while T > 0:\n arr = [int(x) for x in input().strip().split()]\n ob = Sol...
eJzNVUtuwjAQ7QKp1xh5DWg8dsLnJEgYddFm0Y3LIpGQEIhDwIHYcSycMbQpSkhslQrLir/P783Hzq53OL2+cJkdXWe+Fp92WeRiCkIaK/FaRB9Etlpm73n28fZV5D97tsaKTR8qwNRY7bBAoEBDAm5M5Vj6eQRCUAj6/qED3zQPbliVscqzSu6R6zna9DLntLj2LiNVOG4Olzwf4oRf3guGBvlbIqsjNtt5OGGrR8aOjZ2UMlro4751IpAJx0yeshDtY9Huvr8RkfBCTcWGhQdoClJMyA6qraSb177rvxsQHpAOqdE1Zg8O2qCrWf5y...
714,326
Bit Magic
Given an integer array arr[] of size n which contains only 1 and 0. Your task is to make the array perfect. An array is said to be perfect if for each i from 0 to n-1 arr[i]==arr[n-1-i] is satisfied. Examples: Input: n = 4 arr = {1,0,0,0} Output: 1 Explanation: We can take index 0 and 3 and apply the operation. Arr...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1679290206, "func_sign": [ "public static int bitMagic(int n, int[] arr)" ], "initial_code": "import java.io.*;\nimport java.util.*;\nclass IntArray\n{\n public static int[] input(BufferedReader br, int n) throws IOException\n {\n String[] s...
{ "class_name": "Solution", "created_at_timestamp": 1679290206, "func_sign": [ "bitMagic(self, n : int, arr : List[int]) -> int" ], "initial_code": "class IntArray:\n def __init__(self) -> None:\n pass\n\n def Input(self, n):\n arr = [int(i) for i in input().strip().split()] # array i...
eJxrYJlazMIABhE5QEZ0tVJmXkFpiZKVgpJhTB4QGSjpKCilVhSkJpekpsTnl5ZAZQ1i8upi8pRqdRQwtBiSogWX+ZgmGwEdo4DLbEMczgFqMsSpCZcfTMA2ASGpngdrBEFSnWkGcqaBAn7NuGw1hWg2JEOrBcxesG9JNcCA+MgzUSA3aKBOhLiRPCNAyRiIY2LITM+wZERq6EJSLMj3pDsYainprjWAWkxmmsed6PE4FkkzzNcEU1LsFD0AvE5dkg==
702,813
Min Subsets with Consecutive Numbers
Given an array of distinct positive numbers, the task is to calculate the minimum number of subsets (or subsequences) from the array such that each subset contains consecutive numbers. Examples: Input: arr[] = [100, 56, 5, 6, 102, 58, 101, 57, 7, 103] Output: 3 Explanation: {5, 6, 7}, {56, 57, 58}, {100, 101, 102, 10...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617820784, "func_sign": [ "public int numOfSubset(int[] arr)" ], "initial_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = Integer.parseInt(sc...
{ "class_name": "Solution", "created_at_timestamp": 1617820784, "func_sign": [ "numOfSubset(self, arr)" ], "initial_code": "def main():\n t = int(input())\n for _ in range(t):\n nums = list(map(int, input().split()))\n ob = Solution()\n print(ob.numOfSubset(nums))\n print...
eJytVUtqG0EUzMKQaxSzFmHerz85icE2XiRaZKN4IYMhxPgQ8fGyy0H8Xo9kReCWx5IGVK3WjF51varuebp4/vf5U7su//qXq1/Dj9Xd/Xr4ioGuVzUuQxvSNORpKNNQQWO7rlfDAsPy4W75bb38fvvzfr2r8ug3fy+wX5ogMHg1EIEEZKAMqmACC9jAGVwh/qBADJIhFUpQgRo0Q2uXla1Dy1AkFF82iEEKSqACHsEMVnACF8gIYYhCEqRAR6j/UaEJWmB9tV3e1qbWM2y71zrZuto6rAESwAF0REeDxKU4SIAGWEAKyAGlLSOADtvW...
702,673
Taking 1 out of 3 consecutives
Given an array arr[] consisting of non-negative integers, your task is to find the minimum sum of the array such that take one of the elements from the first 3 consecutive elements and then from the ith position where the previous element was taken, do the same operation for the next three from ith position and so on. ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1617361584, "func_sign": [ "public static int minSum(int arr[])" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n pub...
{ "class_name": "Solution", "created_at_timestamp": 1617361584, "func_sign": [ "minSum(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n\n while t > 0:\n arr = list(map(int, input().split()))\n ob = Solution()\n ...
eJydVEsKwkAMddGDPGZdpNO/nkSw4kK7cFO7aEEQxUPoUd25MM5YQfC1HdPSBMLL5yXNxbs9vImRxV2M5VHtqrpt1BxKF5WGVj5UeajLTVNu1/u2eTuDojoXlTr5+EaEkIdgQoLRgRFINmsRvCb4mRGYb25VZlVqVWJVzOIaL4v+qQo/rH87HadZdOtlORwnpmViEWIkSJFB+JPsjKiETUBwmeATiRNJPA0aglMD8zIcLT9AyEADLff3SvfBkD+0ASz16F3Ne5eVsch+PcpE140zhXZc7vN6HQj3C9HV6VJlMPIcra7TJ1bzcO4=
705,724
Longest Path in a matrix
Given a n*mmatrix, find the maximum length path (starting from any cell) such that all cells along the path are in strictly increasing order. Examples: Input: matrix = {{1,2,9},{5,3,8},{4,6,7}} Output: 7 Explanation: The longest increasing path is {1,2,3,6,7,8,9}. Input: matrix = {{3,4,5},{3,2,6},{2,2,1}} Output: 4...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1616434992, "func_sign": [ "public int longestIncreasingPath(int[][] matrix)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nclass GFG\n{\n public static void main(String[] args) throws ...
{ "class_name": "Solution", "created_at_timestamp": 1616434992, "func_sign": [ "longestIncreasingPath(self, matrix)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n n, m = input().split()\n n = int(n)\n ...
eJztl8FuE0EMhjlw5hl+5VyhHc+M7eFJkCjiAD1wCT20EhJC4iHg0bjxMPzjZMum2WVbFKSqag9tNl2P7c//72y+Pf/x68Wz+Hn9ky/efNl83F5eX21eYZPOt2lAGvqfAa2hOZqhKVpFK2gZTdB4mye4wDO8wCtc4QZ3OGMY7gOswRxmMIVVWIFlmMAYrQkq0Awt0ApVqEEdyhhG64DaUB3VUBW1ohbUjCqojC4JRVAySkGpKIpiKI7CGEaXAbkhO7IhK3JFLsgZWZAZLQkikAwpkApRiEEcwhhGC/tvSI5kSIpUkQpSRhKkjgc8BawG...
701,756
First n Fibonacci
Given a number N, find the first N Fibonacci numbers. The first two number of the series are 1 and 1. Examples: Input: N = 5 Output: 1 1 2 3 5 Input: N = 7 Output: 1 1 2 3 5 8 13 Constraints: 1<= N <=84
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617726205, "func_sign": [ "public static long[] printFibb(int n)" ], "initial_code": "//Initial Template for Java\n/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\nclass GFG {\n\tpublic static void main (...
{ "class_name": "Solution", "created_at_timestamp": 1617726205, "func_sign": [ "printFibb(self,n)" ], "initial_code": "# Initial Template for Python 3\n\n# contributed by RavinderSinghPB\nif __name__ == '__main__':\n t = int(input())\n for tcs in range(t):\n\n n = int(input())\n res = ...
eJzs3bmubevSpWWEuAAuYei30+h1wT3gI5ESBqSBk2AkEhICcenE8/aZQhiHFIjEOn9xzt5rzTlG718RRYsWLf73/+y/+s//y//0P/mv/5d/+e//7f/4P/27f/kvfv+y/ut/O//3L//q9y//5n/+H//Nf/vv/s1/99/8D//Tv/v3f/n71//2f5u//V//1e//+ivb/82v/MNf2v9vf2n7R792/Ad+bf9Hv/j8h3/z/D2/df9t628/fuf82/tbj+O37ftvv+/ftS6/97l/6/nev+18jt+xPuvvuq/zty7vcf3W+17no57rvH/HtV/P7z6X...
711,088
Shortest Distance in a Binary Maze
Given a n * mmatrix grid where each element can either be 0 or 1. Youneed to find the shortest distancebetween a given source cell to a destination cell. The path can only be created out of a cell if its value is 1. Examples: Input: grid[][] = {{1, 1, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 1}, {1, 1, 0, 0}, {1, 0, ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1656178906, "func_sign": [ "int shortestPath(int[][] grid, int[] source, int[] destination)" ], "initial_code": "// Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n// Position this line where user code will be ...
{ "class_name": "Solution", "created_at_timestamp": 1655871209, "func_sign": [ "shortestPath(self, grid: List[List[int]], source: List[int], destination: List[int]) -> int" ], "initial_code": "# Initial Template for Python 3\nif __name__ == \"__main__\":\n for _ in range(int(input())):\n n, m = ...
eJy9Uz1PwzAQZWBgY2M+eS7Ilzik4pcgUcQAGVhCh1RCQiB+BPxfHMf2+esKRoVaauz4vXd37y7vx59nJ0fmd32qNzcv4nHc7iZxBQI3I3aAnX7AvKRZtF92M4oO4PbSwd21YydQuiZ2AKXYuYK5lhEzgcbsTGGJnStgzA7LcWAfOzAiMMaz46iF2GH1BJZkasHx1NQwQJZ5YZnMNUYBKrECMTxvh/tpeLh72k229+ca9LYZxesK4olYwzpTJx+Tnhe6XOhr1EmPihFYKMqW0UPPFIGKKWJRs3z9x/AlQ2+gMQXNXG8mYK2VLbS2JmuP...
705,156
Make Zeroes
Given a matrixof size n xm. Your task is to make Zeroes, that means in whole matrix when you find a zero,convert its upper, lower, left, and right value to zero and make that element the sum of the upper, lower, left and right value. Do the following tasks according to the initial matrix. Examples: Input: matrix = {{1...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public void MakeZeros(int[][] matrix)" ], "initial_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nclass GFG\n{\n public static void main(String[] args) throws IOException\n {\n BufferedReader...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "MakeZeros(self, matrix)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n n, m = input().split()\n n = int(n)\n m = int(m)\n...
eJzVVstu2zAQ7CHHfsRA56DYJUWRzJcUqIocEh96UXNwggJFgHxE+7/dJSlZkkXATp0UjRHIfGhmdpez9MvV7+ePH9Lf5yf58uVn8214eNw3N2i4HxxcPxAYBhatjjt4BMR+YJlmsAFbsCyxA3dgDw5gWTcEI+8ZGAvTNtdodj8ednf73f3t98d9oehAGRpKU7CxBscaHWt4mWier7EUb2HlRcVXcJHeDwm/oiUrkTcsVIq+k8UcI7eaC5Zt86T0Q8SoO6GIcBl2VTrZTClyJ09VVhBIAy86WmXZktBpOKUuh9joSMEscTIVscyb5NHB...
703,196
Find missing in second array
Given two integer arrays a of size n and b of size m, the task is to find the numbers which are present in the first array a, but not present in the second array b. Examples: Input: n = 6, m = 5 a[] = {1, 2, 3, 4, 5, 10} b[] = {2, 3, 1, 0, 5} Output: 4 10 Explanation: 4 and 10 are present in first array, but not in ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "ArrayList<Integer> findMissing(int a[], int b[], int n, int m)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\n// Driver cla...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "findMissing(self,a,b,n,m)" ], "initial_code": "# Initial Template for Python 3\n\nt = int(input())\nfor _ in range(0, t):\n # n=int(input())\n l = list(map(int, input().split()))\n n = l[0]\n m = l[1]\n a = list...
eJy1VEtOxDAMZYE4x1PWE5Rvy3ASJIpYQBdsyiw60kgIxCHgUuy4EXFpm7aqO80IUilyUvvFeX7O+/nn98VZM26+gnH7Ip6q3b4W1xC6qDRoUt0oKhkXYgNRHnblQ10+3j/v6y6qd0BRvRWVeN1gDOrhh6AYYEJh2w3I3hy5R4c5V3B5yeOJaQWt6NIGFg4eGXJcYfu7G04Oizxs+vDTBifNHMXD+4bS6TfYTEMMGdJEeXsYBeMnS1iODgbRwIyKDKb4kfuTZWBhA6QnATiabHOEJdO0quBK2QctKSwAgPInJmyAjjbcgkg4zAyukSEo...
712,383
Number of Longest Increasing Subsequence
Given an integer arrayarr, returnthe number of longest increasing subsequences. Examples: Input: n = 5 arr = [1,3,5,4,7] Output: 2 Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7]. Constraint: 1 <= n <= 2000 1 <= arr[i] <= 10**5
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1731309711, "func_sign": [ "public int numberofLIS(int arr[])" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {...
{ "class_name": "Solution", "created_at_timestamp": 1731309711, "func_sign": [ "numberofLIS(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n arr = list(map(int, input().split()))\n ob = Solution()\n ...
eJylVMtKBDEQ9KD/UeS8SF4zSfwSwRURHdDLuIdZWBDBj9D/tXp0hcEkTnQOSRhS1dXVnX49fX84O5m/y1serp7V47jbT+oCymxHo5Fg0cEhwGgDE9UGajjshrtpuL952k9fl/12VC8bLOGeGHiCI1IB53K4Dj3jRQI95GxhCnCbgzOoIeaIFqZEJQUKk6fQGlYWsshGItnIJVspmyxXpBrJIZCrg1+dCf84wvo5jSCuWGbSk6VnPqHMkzUlYa6GgxFvTKulECn+MwPGpyCukWvJilCwFUnTQwRNQ9GxPahJrK4USGepaqKQ4hytqUyr...
702,987
Check if the number is balanced
Given an integer N which has odd number of digits, find whether the given number is a balanced or not. Examples: Input: N = 1234006 Output: 1 Explanation: Total number of digits in N = 7. Middle digit is 4. LHS = 1+2+3 = 6 and RHS = 0+0+6 = 6. LHS is equal to RHS. Input: N = 12345 Output: 0 Explanation: LHS = 1+...
geeksforgeeks
Easy
{ "class_name": "Sol", "created_at_timestamp": 1619001190, "func_sign": [ "Boolean balancedNumber(String N)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass GfG\n{\n public static void main (String[] args)\n {\n \n Scanner sc = new Scann...
{ "class_name": "Solution", "created_at_timestamp": 1619001190, "func_sign": [ "balancedNumber(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n for tc in range(t):\n N = input()\n ob = Solution()\n if ob.balancedN...
eJxrYJnqzsIABhEOQEZ0tVJmXkFpiZKVgpJhTJ6hko6CUmpFQWpySWpKfH5pCUJKqVZHAU2xAUnKLUGAJPONSHOOkTGJGgyBNhiS6GUQINVZJqZm5ji0GGANKQtzM1MTY1K0GII8g8c32DWB4xCIyIkcNL3kRABQWx5OW7G7mAjn4ggfnE7DGTQ4fAgyilC04k48pCY3SuLTEJGWyMkekFDDqyd2ih4AV51IfQ==
702,696
Non-Repeating Element
Find the first non-repeating element in a given array arr of integers and if there is not present any non-repeating element then return 0 Examples: Input: arr[] = [-1, 2, -1, 3, 2] Output: 3 Explanation: -1 and 2 are repeating whereas 3 is the only number occuring once. Hence, the output is 3. Input: arr[] = [1, 1, ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int firstNonRepeating(int[] arr)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scanner = ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "firstNonRepeating(self, arr)" ], "initial_code": "for _ in range(0, int(input())):\n arr = list(map(int, input().strip().split()))\n ob = Solution()\n print(ob.firstNonRepeating(arr))\n print(\"~\")\n", "solution...
eJyllUtuE0EQhlmw4BilWWfQVL+HkyBhxAK8YGOycCQkBOIQcDp2nISvxun2JJkGJ5Q9rZL99WOq/qr+/vzn7xfPFnv9C+fNl+Hj4frmOLySQXcHnarJuPLjhjfO1aR5w5UM+8/X+/fH/Yd3n26OdeG20u7wbXcYvl7J3W3HKPYNMnoZHVvLJCpOvASx3zvrjr6z3lxyisE75ZTNVedDTLnMrN9crSaumvhqKy9Uk1jt/FvneG3rzimzZCl8CKAoL2xHFPWiQTSKJtEsWpZv7ka2s/Y5emnZZdlhtIfXLzJmGdP9mLcDjMvjenv2kqhV...
716,016
Fraction pairs with sum 1
Given a list of N fractions, represented as two lists numerator and denominator, the task is to determine the count of pairs of fractions whose sum equals 1. Examples: I nput: N = 4 numerator = [1, 2, 2, 8] denominator = [2, 4, 6, 12] Output: 2 Explanation: Fractions 1/2 and 2/4 sum to 1. Similarly fractions 2/6 and 8...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1690782495, "func_sign": [ "public static int countFractions(int n, int[] numerator, int[] denominator)" ], "initial_code": "import java.io.*;\nimport java.util.*;\nclass IntArray\n{\n public static int[] input(BufferedReader br, int n) throws IOExcep...
{ "class_name": "Solution", "created_at_timestamp": 1690179870, "func_sign": [ "countFractions(self, n, numerator, denominator)" ], "initial_code": "# Initial Template for Python 3\n\nfor _ in range(int(input())):\n n = int(input())\n numerator = list(map(int, input().split()))\n denominator = li...
eJy9VMtOwzAQ5ID4jlHOFcquYyfhS5Aw4gA5cDE9pFIlRNWPgH/lBrsuRa1SB9wGkigvZ2d2die7Pn/7uDiL2/W73Nw8F49hvuiLKxTkg/OBYMEwqCAPDKc3aEDsQzFD0S3n3X3fPdw9LfptXOnDSlZfZthH0wWDWuAaAa3QgkjAyAgRqBQSUgKrF7JK4pIkKY7GBysUEVowqAEzuFRyUPWFrG8rsJxtWkVKBGtNDu5aHy2UFRG1pN+qKM2Do8ZMJWRH8aIaG0v00xegWiTnJ7A9MuM2BdJWpz2Sio2G+1btw76obDijbtBoGw3A4rEy...
713,971
Valid Compressed String
A special compression mechanism can arbitrarilydelete 0 or more characters and replace them with the deleted character count. Given two strings,Sand T whereS is a normal string and T is a compressedstring,determine if the compressed string T is valid for the plaintext string S.Note:If T consists of multiple integers ad...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1675771112, "func_sign": [ "static int checkCompressed(String S, String T)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader read =\n new ...
{ "class_name": "Solution", "created_at_timestamp": 1675771112, "func_sign": [ "checkCompressed(self, S, T)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n S = input()\n T = input()\n\n ob = Solution()\...
eJy1VMtOwzAQ5IDEb1Q5V4iNlSpwSxM3SevEru2+IIgD9MDF9NBKSAjER8CnceNjcKpUpaShdQo+eb3y7K5nxq/H758nR8s1/tCbqyfrXs0Wc+uiYUGmvLYf4E4Yxd0eSVLK+lzIwXA0nlxmyimSTp491zlX55w8ZzUb1vRxNr2dT+9uHhbzAu8sUy+Zsp6bjc0iESaEjignQaaQDhBFHAWGIJudZgpQWoEAVQjlpWFczxCGTWREdQPMlpFd1UPVFAHGjGCPp3Ea6gix1nJriEJoGgrJ9UWJhVxCEZSfuNI2xWKchtxLkgLM9wTWhy5P...
701,393
Minimum Jumps
Given an array arr[]of non-negative integers. Each array element represents the maximum length of the jumps that can be made forward from that element. This means if arr[i] = x, then we can jump any distance y such that y ≤ x.Find the minimum number of jumps to reach the end of the array starting from the first element...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1729070508, "func_sign": [ "static int minJumps(int[] arr)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\n Buffer...
{ "class_name": "Solution", "created_at_timestamp": 1729070508, "func_sign": [ "minJumps(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n # n = int(input())\n Arr = [int(x) for x in input().split()]\...
eJzNVEtuwjAQ7aJSrzHyGqGxEzfASSo1VRclCzaURZCQEBKHgFux64U6nnFcGj7VoBKI5fg7772xx7N+3H49PfD3sqPO69JMprN5bUZgbDl1SBUysFRyQCoWHLcZ/5FHNlTTA1MtZtVHXY3fP+d1BCEAs+rBb1hPsx6GBOLYOFAICYKPrdBipEWedZG+Ice0FvYJluzifRpJFrvRBM1xWraRdZnNiaexdakX9sgoT3Y/KC6qaOZ5pPLbBd/J7wEU8EwK8qRKjYNwtGhgGEVFHPTrODxb6LX5PQ81dlngU1/LniHxXjGU7ygYj+WFpFyk...
704,751
Geometric Progression
Given a Geometric Progression with first term as 1, common ratioas 2 and a number N. Find out the sum of all the terms of this geometric progression if there are total 2**N terms in GP.Note: Since the answer can be very large, print the answer modulo 10**9+7. Examples: Input: N = 1 Output: 3 Explanation: The series =...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static Long geoProg(Long N)" ], "initial_code": "//Initial Template for Java\n\n//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOExceptio...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "geoProg(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n\n ob = Solution()\n print(ob.geoProg(N...
eJylk01KA0EQhV3oPYYGd4NUVf9VeRLBCS50FtlMsphAQBQPofe1aQOJkNdJtJmBGYrvdf28+rj+6m+u6nm4LR+Pr245rTezu+8cD1N5XN+5cbsen+fx5Wm1mXdBP0zvJfjWd78JgQRHgHiISEQME4SUJfsQjSGK2cAxalDCKGYlGadIilNu0VGSUBIJLbpRdNCcyAIq2upp9MyLShZt3t7MIKhPUtoOJcpLw3BQygSlyFLwmg1I4SRQ+fQPvxDzfnrVrdgC5kmUOZ3owU7vx/t/bgM3igrFTZYtZsQeHwgf/DXU0fLXNp/jthMbel5y...
702,766
Equal Point in Sorted Array
Given a sorted array arr[ ] of N positive integers. Your task is to find an index i in the array from where the number of elements smaller than arr[i] in the left side of the indexis equal to the number of elementsgreater than arr[i] in the right side of the index.If no such index exists, print "-1". Examples: Input: N...
geeksforgeeks
Easy
{ "class_name": "Compute", "created_at_timestamp": 1615292571, "func_sign": [ "static int findEqualPoint(int arr[], int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\nclass GFG\n{\n\tpublic static void main(String[] args) throws IOExce...
{ "class_name": null, "created_at_timestamp": 1615292571, "func_sign": [ "findEqualPoint(arr, n)" ], "initial_code": "# Initial Template for Python 3\n\ndef main():\n T = int(input())\n while T > 0:\n n = int(input())\n arr = [int(x) for x in input().strip().split()]\n print(fin...
eJxrYJnKxMoABhG/WRgYoquVMvMKSkuUrBSUDGPyQEhJR0EptaIgNbkkNSU+v7QEKmsQk1cXk6dUq6OAqsUIqEXBCIcmXUMcuozBuhSMcejDqw0ISXSjCVQb6e40hekkV68RGJLqTzOEtWRYbA73LgSSqt8Cot8I5niczjfCZoAC3P1AI/D7AKt+QwVKIgwa2yCM3wRcaQXZAHKyAlY3kOoIiElQo7CaSJz5OIIJOYRBpkPTDCjBkupSaEZGyWSkpXYMx1DgGrhBhBNO7BQ9AHvcgMg=
703,355
Longest Palindromic Subsequence
Given a String, find the longest palindromic subsequence. Examples: Input: S = "bbabcbcab " Output: 7 Explanation: Subsequence "babcbab" is the longest subsequence which is also a palindrome. Input: S = "abcd" Output: 1 Explanation: "a", "b", "c" and "d" are palindromic and all have a length 1. Constraints: 1 ≤ |S...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1616468717, "func_sign": [ "public int longestPalinSubseq(String S)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GfG\n{\n public static void main(String args[])\n {\n Scanner sc = new Sca...
{ "class_name": "Solution", "created_at_timestamp": 1616468717, "func_sign": [ "longestPalinSubseq(self, S)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n s = input()\n ob = Solution()\n ans = ob.longe...
eJytVFuqwjAQ9UP3UfItQhW5cFciWJFJOm2jkpQapUUUF6Hb8M/9OVdUruhYIg0E8uiZOXN6Mvv28dxpXcfoRIvxRmiTr5z4DUQYmbKSUMoKqjIyohsILHNUDuOpXbnbVz+R2dHlths8Q0FLm+WZlRpYbBhyYAkqTtJY0cIfndgiRZwvl3PElDZ8hD6bX8WYpJme8VgOarSDBaxpOm0+sB9yAWhImt6KF6BQAV8th5NApPl0HE+VAWV0yCfkkO9UqiHBqn11mfzSZvcSXgIVdGKfj7yrvLvQ1ttwwPPzZvn3R3xFfDiu+Zwf28NL9Lp+...
704,462
Right most non zero digit
You will be given an array A of N non-negative integers. Your task is to find the rightmost non-zero digitin theproduct of array elements. Examples: Input: N = 4, A = {3, 23, 30, 45} Output: 5 Explanation: Product of these numbers are 93150. Rightmost non-zero digit is 5. Input: N = 5, A = {1, 2, 3, 4, 5} Output: 2 ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int rightmostNonZeroDigit(int N, int[] A)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\n...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "rightmostNonZeroDigit(self, N, A)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n A = list(map(int, input().sp...
eJy1VMtKxEAQ9CB+R5HzKvOeiV8iGPGgOXiJe8jCgihevXnQ/7W7N+tjSccNrhUoQkKqqyY183z8/npyJLh4oZvLh+quW6766hyVbbrYdNYwwNdwS8+rBap2vWxv+vb2+n7VD1+c0qsnevu4wE8da5quZqAwkBlIDEQGAgOeAceAZYC/VKYVZZiYdiTmcirYjLXQdVTXfmv6G6sqtSKSPpfQCXvhIByFE7Oq6/SU7MdCYVVQS5vJKBw8AiISsioQJn6y3QaVnBJTUkpIZKbCVAtNraeWO/AQMmrIqiGzJsw2SsWxDs7DB4SImJAyckGZ...
712,393
Maximum Sum Combination
Given two integer array A and B of size N each.A sum combination is made by adding one element from array A and another element of array B.Return the maximum K valid sum combinations from all the possible sum combinations. Examples: Input: N = 2 K = 2 A [ ] = {3, 2} B [ ] = {1, 4} Output: {7, 6} Explanation: 7 -> (A ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1666338023, "func_sign": [ "static List<Integer> maxCombinations(int N, int K, int A[], int B[])" ], "initial_code": "// Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nclass GFG {\n pub...
{ "class_name": "Solution", "created_at_timestamp": 1666730720, "func_sign": [ "maxCombinations(self, N, K, A, B)" ], "initial_code": "# Initial Template for Python 3\n# Position this line where user code will be pasted.\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N,...
eJytVktu3DAM7SKrnoLwOij0oSypJynQKbJoZ9GNm8UEKFC06CGS+5aP+tSDiTwfZEaiaZki6acnyn/vXvL7d/r75ET5/Gv6vjw+HaaPNNndEijsFmsoU6JIs+jkyBNjeLqnaf/zcf/1sP/28OPp0GYFsqzNo+2WP2L6+56OHXtycCyeDSWjMZwhb8ZuvSErJgN/M7E4kdCllQQwxEfZWD8M4DL1NggiSQoEwRAjVSQsI6H9Fa32P7IZv1QBQDGobRA6UoSQF3GyBIl8IHbEebdwhib3MirPxCIO4+VE2aIlri3GUcRUlh4Z5ixdpuYo...
703,113
Check if array contains contiguous integers
Given an array arr. Determine if all the unique elements are contiguous integers. Examples: Input: arr[] = [5, 2, 3, 6, 4, 4, 6, 6] Output: Yes Explanation: The elements of array form a contiguous set of integers which is [2, 3, 4, 5, 6] so the output is "Yes". Input: arr[] = [10, 14, 10, 12, 12, 13, 15] Output: N...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1616519854, "func_sign": [ "boolean areElementsContiguous(int arr[])" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1616519854, "func_sign": [ "areElementsContiguous(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n arr = list(map(int, input().split()))\n ob = Solutio...
eJylVEtOw0AMZYE4x2jWFUrsOB8OwRpEEAvIgk1aqamEhEAcAg7EjmNhv4kCqpqmmYwru4o0b56fPx/nXz8XZzg33/rn7tU/t5td56+cT+s2Tey4Sk8JXzl8SkMgv3K+edk0j13z9LDedf3N22Zbt+91699Wbg/QkRq7TE3UcrVCrVSrnKGHn72aDg8RPMNn8DLy8vV67OFkwBzYhxBge9xEQshDKEIoQwjJp0lE1gcMhOamIchCkIQgB0EKAuoC5uaL2fr0ZREUpOxLoTRVJVVI1VFlVBVVRNWoHEWo8NdM1b+WKuBzeIHPYqCVrxXU...
713,538
Select Nodes
Given Nnodes of a tree and a list of edges. Find the minimum number of nodes to be selected to light up all the edges of the tree. An edge lights up when at least one node at the end of the edge is selected. Examples: Input: N = 6 edges[] = {(1,2), (1,3), (2,4), (3,5), (3,6)} Output: 2 Explanation: Selecting nodes 2 ...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1673865673, "func_sign": [ "public int countVertex(int N, int[][] edges)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1673865673, "func_sign": [ "countVertex(self, N, edges)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n edges = []\n for _ in range...
eJy9lM1OwzAQhDkgnmPlc4UydmwnfQ0uCIw4QA5cTA+phISKeAh4X3bjiB+VbZUE0YNVJZlvZtZOXk/fr85Oht/lBf+5fjYPebPtzZoMUoZZkemeNt1d393fPm778VaV8kvKZrein89blpBVRFBEbhDJ4iYq/ZeSvamWxSsMqzBQjRArECeQmhjsKaQcKKYcqUm5oTblllApeK/hf80oRkGWKG6NuLXiJmEiAeIHOxjKdCoC6wCC1i5oGzKxXTFDMZPUtiRwJUFNQx9PYDk4LwPAgRkBTswQtGS1GUE7NmFvRm4MqZCcAoqH206kfe7d...
703,181
Rope Cutting
You are given array arr of length of ropes. A cut operation is performed on ropes such that all of them are reduced by the length of the smallest rope. Return the number of ropes left after every cut operation until the length of each rope is zero. Examples: Input: arr[] = [5, 1, 1, 2, 3, 5] Output: [4, 3, 2] Explan...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1616692607, "func_sign": [ "public ArrayList<Integer> RopeCutting(int arr[])" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass Main {\n public static void main(String args[]) {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1616692607, "func_sign": [ "RopeCutting(self, arr)" ], "initial_code": "# Initial Template for Python 3\n# Position this line where user code will be pasted.\n\nif __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n arr = list(map(...
eJy9U0FqwzAQzKHkHYPOIWQly7bykkJdekh9SA9ODg4EQkIf0f63q0V1S4MUOzaVYSSz2tWOZvT+8Pk2n8l43PDi6aS2zf7QqjUUVQ2pBVR93Nebtn592R3aEFpVzaVq1HmBP/tXfgxNwtU3uIKGQQaLHAVKOFCsCcfhgrdZ3m44jZJM4PwQLAULwVzQCmaCRlALxrofePS4abgGXW66Qqpzr4JljsTlDIgXDpoT3EQ3EuTQQRATJMmCKHbkMV08UudGkz7mXVgw5ZK8CV3sEnuR/m1q+S+RcvbtinHD9PIOH5Bslabs1f2T5uicn09s...
704,384
Firing employees
Geek is the founder of Geek Constructions. He always maintains a black-listof potential employees which can be fired at any moment. Examples: Input: N = 4 arr[] = {0, 1, 1, 2} Output: 1 Explanation: The hierarchy is as follows (Geek) Rank 1 / \ Rank 2 Rank 3 / Rank 4 Performan...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int firingEmployees(int arr[], int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG{\n public static void main(String args[]) throws IOException { \n S...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "firingEmployees(self, arr, n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n arr = list(map(int, input().stri...
eJylk0FOw0AMRVkgzvGVdYXG9sxkwkmQCGIBXbAJXbQSEgJxCDgAO46Jk0mpAnHL0DiLLvqfvx3/19P3z7OT4bn80B9XT9V9t9qsqwtU1Hah7RwoV7VAtXxcLW/Xy7ubh816/Be33UvbVc8LTKXktlrWEi2vFQyKNyixh/SAXiyG2BnilMW5d9CKhYA8A4/6iBoJDciVYngeA9L1cCls/CaTrQ7YHqxogxcNHk9m3NnbGQTJ8HpQAEVQXWhZ3O6M+Nt4tp6bZvt5gL59Gi1kE9a+yWoY3HZH8yv/MQ4ogRqwrkE16k/AHhzAEVyDE7iB...
701,189
Print 1 To N Without Loop
Print numbers from 1 to n without the help of loops. You only need to complete the function printNos() that takes N as parameter and prints number from 1 to N recursively. Don't print newline, it will be added by the driver code. Examples: Input: n = 10 Output: 1 2 3 4 5 6 7 8 9 10 Input: n = 5 Output: 1 2 3 4 5 Exp...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617185372, "func_sign": [ "public void printNos(int n)" ], "initial_code": "// Initial Template for Java\n\n/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\n\nclass Main {\n public static void main(Str...
{ "class_name": "Solution", "created_at_timestamp": 1617185372, "func_sign": [ "printNos(self,n)" ], "initial_code": "# Initial Template for Python 3\n\nimport math\n\n\ndef main():\n T = int(input())\n\n while T > 0:\n N = int(input())\n\n ob = Solution()\n ob.printNos(N)\n ...
eJzt3M2OXGcRgGEWXEhp1hHqr/5P1uy4ASQGsQAv2AxZOBISCuIi4Cq4Sd4aJciR3A4YmzieiuTEi3I8Xc85X/306f7bz//xq3/+7PmfX/+S3/zmLw9/fPrq69cPX8qDPj7F7fb4lPOvhy/k4dWfv3r1+9ev/vC7P339+tuYIyomLiEpJS2XnJucI0flmByXE3JSTslpOZfoTZQ/o6Im6qIhmqIl2qKX2E3siPG/NDEXC7EUK7EWu8Rv4kdcxfkbXTzEU7zEW/ySuEkcCZUwCX6gkEiJkmiJS/ImeSRV0iRdkp83JUuyJS+pm9SRUimT...
701,223
Binary Array Sorting
Given a binary array arr of size n. The task is to arrange the array in increasing order.Note: The binary array consists of only 0 and 1. Examples: Input: n = 5 arr = 1 0 1 1 0 Output: 0 0 1 1 1 Explanation: After arranging the elements in increasing order, elements will be as 0 0 1 1 1. Input: n = 10 arr = 1 0 1 1 ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1730639424, "func_sign": [ "public void binSort(int[] arr)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\nclass Geeks {\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new Inp...
{ "class_name": "Solution", "created_at_timestamp": 1730639424, "func_sign": [ "binSort(self, arr)" ], "initial_code": "# Driver code\nt = int(input()) # number of test cases\nfor _ in range(t):\n arr = list(map(int, input().split())) # input array\n Solution().binSort(arr) # sort the binary arra...
eJzFlM0OgjAMxz2Y+BrNzsR0Hn0SEzEelAOXyQESEyPxIfR9dRUMbOso8YsFMljX/vov3WV6K2YTulb5Y7I+qdwUVamWoHRqUCWgsmOR7cpsvz1UZbOEqalTo84J9O01Y68ZewRvcBF9S44BvMFR+ZasT45LsxzIxsVwnAXtAeem4O5n3rG/vQ56iIrXSjwsXs+SF0/IL+cMZDpSE8cn/l19McAT9W0K60bSQBTOzsYCCtsuxqFRx/6WZp3dHyI2hMwy27cmp+EOCJILZPpFITsYJJMoVmtZk3Hs/xjRLvCqNUWInyjBXPAbx3onA/v4...
702,022
Roman Number to Integer
Given a string in roman no format (s) your task is to convert it to an integer.Various symbols and their values are given below.I 1V 5X 10L 50C 100D 500M 1000 Examples: Input: s = V Output: 5 Input: s = III Output: 3 Constraints: 1<=roman no range<=3999
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int romanToDecimal(String s)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String[] args) throws IOException {\n BufferedR...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "romanToDecimal(self, s)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n ob = Solution()\n S = input()\n print(ob.romanToDe...
eJytkz9vwjAQxRn4IJFnVNnEbeyul8VSvEYnNRUDZOiSMgSpEqLqh4BPysbUNP+kqDzDgCcP/vnuvXf3Mz9d5rP28Lm5vO3FR7Xd1eI1EqqovPcpEWXMnDvnxCIS5de2XNflZvW5q/uHsTGmqL6LShwW0fQD8kyOAWetBRhnLgeQ1oDxlAYwpSHYdIgoi5jeFCgtNkjan59MADNWInVDDlihMdCaxpusjRCwS50kSGkaSFDDBD2NLk27n7QTTEzizz1hKUouEZaHR+QlxgXHWb5nIVRgsgnO2jMq3inuPPu/lC4L2ohbuR5R/qiMWrND...
705,298
Preorder Traversal and BST
Given an array arr[ ]of size Nconsisting of distinct integers, write a program thatreturns1 if given array can represent preorder traversal of a possible BST, else returns0. Examples: Input: N = 3 arr = {2, 4, 3 } Output: 1 Explanation: Given arr[] can represent preorder traversal of following BST: 2 ...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static int canRepresentBST(int arr[], int N)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "canRepresentBST(self, arr, N)" ], "initial_code": "# Initial Template for Python 3\n\nimport sys\nsys.setrecursionlimit(10**6)\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input(...
eJytVDtOxDAUpIB7jFyvkB3Hn+UEdLRIBFFAChqzRVZaabWIQ8B9mRcsFopEvLCprMgzfvOx384/bi7Oxu/2mou7vXkum+1grmBcV0JXnEWAQ0LLhTUrmH636R+H/unhZTsct752xRxW+I1PXcnwhEe0pHBafOQIaIj3REc9ONfZKcI1SnhL7UGQDcFJL9w1WCOPR5PGk0bJQfMT5xfrJo2z09pl7DE7OhjgtadniV4iFzSJkjCJjeJGUJI5zvnNRAYfkCxiwNoiy88F3oi4WOOtac1VdMqpWZ1OK3SKLYeZBs6E+LPA/2yw+vLiFCWu...
704,386
Shreyansh and his bits
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N. He is a little weak in maths. Help him find the nu...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "long count(long n)" ], "initial_code": "//Initial Template for Java\n\n//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG\n{\n public static void main(String args[])throws IOException\n {\...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "count(self, N)" ], "initial_code": "if __name__ == '__main__':\n ob = Solution()\n t = int(input())\n for _ in range(t):\n N = int(input())\n print(ob.count(N))\n print(\"~\")\n", "solution": "c...
eJxrYJmawcIABhGJQEZ0tVJmXkFpiZKVgpJhTB4QKekoKKVWFKQml6SmxOeXlkAlDWLy6oCStToKqDqMcOowxKHDmGQ7TEm2wwynDiMcOgxxW4LLWYa4bTHB5XfSA9gYdwib4vK9CU4tZngcBtKG2zKckYOkGxK7RjExkKSE0yxLXCEKMYb0FELAPpyJF2/iwhW8UF8iWUu6zWYQz5KeTJHtBoczObaDEjs5YYzmbSIMiZ2iBwDBe21O
712,573
Longest String Chain
You are given an array ofwordswhere each word consists of lowercase English letters. Examples: Input: n = 6 words = ["a","b","ba","bca","bda","bdca"] Output: 4 Explanation: One of the longest word chains is ["a"," b a","b d a","bd c a"]. Input: n = 2 words = ["abcd","dbqca"] Output: 1 Explanation: The trivial wor...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1669098109, "func_sign": [ "public int longestChain(int N, String words[])" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\nclass GFG{\n static FastReader sc=new FastReader(System.in);\...
{ "class_name": "Solution", "created_at_timestamp": 1667461130, "func_sign": [ "longestChain(self, N, words)" ], "initial_code": "# Initial Template for Python 3\n# Position this line where user code will be pasted.\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int...
eJylVF1qwzAM7sN6D+HnUtqFdqUnGcxj+C9ZoThhdVmSsbFDbJfZ224223FpMqoEp0aSA0HSJ+mTP2++f6cTf+5/7MfDG9np4mjIFsiSaiuMzICoslDCKPmUH8357wfV5H0GXZeVdQHmxGtjsCArJMhyYaNwIVUKZ+uMVeDA3RHhktC5BJJqjaRae7zcinAqvVGNTSNj3VJdV+UrlFUd2bXNqd4sZG7BCNAAa+IdEjOxaKCqe9AkWPupLiILSFwbOWDdx9wsdqYNcGZAsBeQeQZK7SHdHZ4hy5kZR74h2mHuJ9q5zOjwh5xRzgrZpm0k...
709,865
Min Chars to Add for Palindrome
Given strings. The task is to find the minimum characters to be added at the front to make string palindrome. Examples: Input: s = "abc" Output: 2 Explanation: Add 'b' and 'c' at front of above string to make it palindrome : "cbabc"fxtlsgypsfa Input: s = "aacecaaa" Output: 1 Explanation: Add 'a' at front of above ...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1644560979, "func_sign": [ "public static int minChar(String s)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n p...
{ "class_name": "Solution", "created_at_timestamp": 1644560979, "func_sign": [ "minChar(self, s)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n for _ in range(int(input())):\n s = input()\n obj = Solution()\n ans = obj.minChar(s)\n pri...
eJydU8sKwjAQ9NAPKTkXsb5Av0QwItskasUmJbRQEEW8edf/tbUtijDFmFNgmZ2dndmL97h5vddbXMvP8shineYZm/ss5Jq4ZoHPVJEqkSm5NnnWFAdcn8viKfC/EBGEhABiSShB1pkqIUmJM8qazLhzRaSpYxsTAHPmKZwRKR1iLa1JFITOoFdCqs12F++doa1nnBBy1D0vZJxCB/70wP5AiqIp3jqh0LAr1/UN1R2a60B9xnB+WQmoO1Uy6phgMUNkN+cR55/bcB2lvLhSB745ZME7aHCJbbxX9/4TgK6GfQ==
702,997
Count of Palindromic substrings in an Index range
Given a string S of lowercase englishalphabetic characters and a substring range starting from q1 and ending at q2,the task is to find out the count of palindromic substrings in the given substring range. Examples: Input: N = 7 S = "xyaabax" q1 = 3 q2 = 5 Output: 4 Explanation: The substring in the given range is "...
geeksforgeeks
Medium
{ "class_name": "Sol", "created_at_timestamp": 1615292571, "func_sign": [ "int countPalinInRange(int N, String S, int q1, int q2)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass GfG\n{\n public static void main (String[] args)\n {\n \n ...
{ "class_name": null, "created_at_timestamp": 1615292571, "func_sign": [ "countPalinInRange(n, s, q1, q2)" ], "initial_code": "# Initial Template for Python 3\n\nt = int(input())\nfor tc in range(t):\n n = int(input())\n s = input()\n q1, q2 = list(map(int, input().split()))\n print(countPalin...
eJzVlM9KxDAQxj14ELz5BKHnRZqk//RJBCOSJtkl0E5L7S7tiuJD6PuaZFfWg7OrPbha6KS0/U1mvjDfy+nbxdlJuG7O3cPtY2ShXfbRNYkSATwWsB7GcXBhPbrbBR+Hj3cCUsJSAbQQ0MrKgu6a2jyYuuk02Eq2AmJCcwGMCYCmgVpqWVdmZSpt7NwarezKKp+GZi6N+0uWUun5QitZllJAQiiNZiQyQ2tUb/R9s+y3BXJHPLvUaVjoZrkKMXqakU+tUPfZZfbFxEgyinC+ogCiVSAg92AgGUJmCJl4EZT2KEfQBEHTgJZh2wRhc4TN...
702,689
Rearranging array
Given an arrayarrofdistinct integers. Rearrange the array in such a way that the first element is the smallest and the second element is the largest, the third element is the second smallest and the fourth element is the second largest, and so on. Examples: Input: arr[] = [4, 5, 1, 2, 3] Output: [1, 5, 2, 4, 3] Expla...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1617647549, "func_sign": [ "public static ArrayList<Integer> Rearrange(int[] arr)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass Main {\n public static void main(String args[])...
{ "class_name": "Solution", "created_at_timestamp": 1617647549, "func_sign": [ "Rearrange(self, arr)" ], "initial_code": "if __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n arr = list(map(int, input().split()))\n ob = Solution()\n ans = ob.Rearrange(arr)\n p...
eJzVVLuqFEEQNRD8jcPEF+lHVXWVf2BmKLhioBuYrDfYC4IofoT+r3V610Rvo6MmDj3LwnSdOo/q/vzw67NHD+bz/Gn+efFhe3u6vTtvT7DVw6mWwyngGDAoBB0NFWW7wXZ8f3t8fT6+efXu7vy9IHd/Opy2jzf4AUb5onZUQU2IilrwE/AKVhewLfvVLNWEiQmaDbLNQI3Ek8R2NmLH7GuojrYi31bktfCFBMQhA2KQpCyQDskuFVLQA93RB7qhK3oq6ugNPfkVtKSTrQeaoSmaoKXghlaTD8kmMbK2SV+mjr0u6dL8UuZPBhe0JZIn...
704,604
Smallest number with sum of digits as N and divisible by 10^N
Find the smallest number such that the sum of its digits is N and it is divisible by 10**N. Examples: Input: N = 5 Outptut: 500000 Explanation: Sum of digits of 500000 is 5 and divisible by 10 **5 . Input: N = 20 Output: 29900000000000000000000 Explanation: Sum of digits of 29900000000000000000000 is 20 and div...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public String digitsNum(int N)" ], "initial_code": "//Initial Template for Java\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nclass GFG\n{\n public static void main(String[] args) throws IOException\n {...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "digitsNum(self, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n n = int(input())\n ob = Solution()\n ans = ob.digitsNum...
eJzt3c9u4kYAB+Ae9kGQz6jyH2xDnqRSp8oh4ZDLhANIkaJI+xB9kb5hbZLdbAomrdZliPN9CqPE2MMA9iiYn2e+fvnt7q8vv/z+mN3FzW6bXc2yIsQi74SYzWfZ+mGzvtmub6/vd9tvK6wAxpUDAAAAAAAAAADABISYPc1nPyRzyxD7nNx7+dzUOT5gclJ3hwAAAAAAAAAAADCCEI2DC4wtdc8GAAAAAAAAAAAAYzgYB7cKsd4vb/Zlm58YDLdOnebjw0i8nwMAAADApxBik/pUIByX+uAAAAAAAIApCLFNfcofLkLqYxEAAAAAAAA+...
713,590
Minimum Days
Given a string S of length N containing only lowercase alphabets. You are also given a permutation P of length N containing integers from 0 to N-1. In (i+1)'th day you can take the P[i] value of the permutation array and replace S[P[i]] with a '?'. Examples: Input: N = 4 S = "aabb" P[] = {2, 1, 3, 0} Output: 2 Explan...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1673953503, "func_sign": [ "public static int getMinimumDays(int N, String S, int[] P)" ], "initial_code": "import java.io.*;\nimport java.util.*;\nclass IntArray\n{\n public static int[] input(BufferedReader br, int n) throws IOException\n {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1673953503, "func_sign": [ "getMinimumDays(self, N : int, S : str, P : List[int]) -> int" ], "initial_code": "class IntArray:\n def __init__(self) -> None:\n pass\n\n def Input(self, n):\n arr = [int(i) for i in input().strip().split(...
eJztVstu2zAQ7CHHfkFOW52DQqTe/ZICYRDo5bdpJ5Zs2UWLfkT7vx2SUOI2VCy5SJBDaIuwxeXsY2Yp/bz4/enjBz2+XuLH9TdnKtd15XwhxxMyFDJNsyzPhfTIpYB8YsSFZC4WsrzQVypkQjFFFGoDjziMYMACIQ+H/b5pdrvttq6raiOkqwBg48M2xJ6YEmK4yYhhm0fMd67IKZt1mVdlcbuqq8dofgDTzOaP8/2KjuJFXNxtA/57xha4iYlFxEJiAdxoZ1w7dskaPw9MkuVoPJnO5oulXK3v7jdVvd01+wPWfeIw5sSRElIY6qEj...
704,205
Assign Mice Holes
Given, N Mice and N holes are placed in a straight line. Each hole can accommodate only 1 mouse. A mouse can stay at his position, move one step right from x to x + 1, or move one step left from x to x -1. Any of these moves consumes 1 minute. Write a program to assign mice to holes so that the time when the last mouse...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1720415146, "func_sign": [ "static int assignMiceHoles(int N , int[] M , int[] H)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n...
{ "class_name": "Solution", "created_at_timestamp": 1720415146, "func_sign": [ "assignMiceHoles(self, N , M , H)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n M = list(map(int, input().spl...
eJy1VDtOxDAUpIB7jFyvURx/knASJIIoIAVN2CIrrYRAHAIuSkfH2AlFVnkhRsK25G/G82ae83b+8XVxlsr1Jwc3z+qx3x8GdQVl2p6tYFM7qO647+6H7uHu6TBMB7j12vbqZYf5V2Xba1PEgrEj0DidljPxPPE8tEWBEo4TB13CwMILSEZAMkWiBt1A19AVdECEdhGdmDqdQYMaFQI8HC/hVdI10j1kbDBV6oGpZrL1p7rBj7Oxi85gLvTsQKbKdpQmQiW9PYwkrxcg6hg2XaF4DQxjt8SI8TuKWRMYhmI6mJCpRDS9jMF6JPtiRpQ/...
701,296
String Rotated by 2 Places
Given two strings a and b. The task is to find if the string 'b' can be obtained by rotating(in any direction) string 'a' by exactly 2 places. Examples: Input: a = amazon b = azonam Output: 1 Explanation: amazon can be rotated anti-clockwise by two places, which will make it as azonam. Input: a = geeksforgeeks b = g...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1730221104, "func_sign": [ "public static boolean isRotated(String s1, String s2)" ], "initial_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass GFG {\n\n public static void main(String[] args) {\n Scanner sc = new Sc...
{ "class_name": "Solution", "created_at_timestamp": 1730221104, "func_sign": [ "isRotated(self,s1,s2)" ], "initial_code": "# Initial Template for Python 3\n\nimport atexit\nimport io\nimport sys\n\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput = iter(_INPUT_LINES).__next__\n_OUTPUT_BUFFER = io.Strin...
eJy9U+0KgjAU7Uf0HLL+hQT97UmCFrHpLMvuTGeZUfQQ9b7NTzLQ8AqNuQ8u5x7v2bmP4WsyGmRjMdaH5ZW44EeKzA0yo8A4Bc6IaRAR+8JSwl7LSBVxh3mhoHCnQG6m8QVk6dcAVEHUiNN8GDpu2TpmC31AkObodMXVylOZOKrebJR7d3x8SfQsd6xyzmbr7vbeAaR/DEIVnc46mf6rpDGKYAqkYsqVoESYzvJK4eNSBHpkd3+nL2yGYdFPzdrful1r+19i550LKEfmbq6aGFMppdhGzij/6st6C9YUoDhj9RCu4oY+8nc0WtBFvtVz...
701,741
Zero Sum Subarrays
You are given an array arr[] of size n. Findthe total count of sub-arrays having their sum equal to 0. Examples: Input: n = 6, arr[] = {0,0,5,5,0,0} Output: 6 Explanation: The 6 subarrays are [0], [0], [0], [0], [0,0], and [0,0]. Input: n = 10, arr[] = {6,-1,-3,4,-2,2,4,6,-12,-7} Output: 4 Explanation: The 4 suba...
geeksforgeeks
Medium
{ "class_name": "Solution", "created_at_timestamp": 1729757496, "func_sign": [ "public int findSubarray(int[] arr)" ], "initial_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n int t = sc.nextInt(); //...
{ "class_name": "Solution", "created_at_timestamp": 1729757496, "func_sign": [ "findSubarray(self, arr)" ], "initial_code": "def main():\n t = int(input()) # Number of test cases\n for _ in range(t):\n # Input array as a space-separated list of integers\n arr = list(map(int, input().s...
eJy1VMFugzAM7WHqd1g511USCGv3Fb1t0ph66Dj0wjhQqVK1aR/R/e/shB2QeG3RaAJOgvDDfn7m++HneT6L42Ujm9eT2dfNoTVPZFxZF8SOOKOcPLFcBWXEuRhnFmSqY1Pt2up9+3FoO59Q1l9lbT4X1AeyFIgD/S3A21ng7mwc5DSevgFQjwCJXReDrDplFwDEGkAEicOqp9y6EcB4AjAFpOTuEyWGMlvrUGbY20SQizmSj49G1lyLRgrIapSlSFNkL1GHEHOA6FO9xFdtF9stIaIacJSRV6Pist3Jj1QEJ2GNA4NaxwpD6Q1C2en6...
705,336
N-Queen Problem
The n-queens puzzle is the problem of placing n queens on a(n×n) chessboard such that no two queens canattack each other.Given an integer n, find all distinct solutions to the n-queens puzzle. Each solution contains distinct board configurations of the n-queens placement, where the solutions are a permutation of [1,2,3...
geeksforgeeks
Hard
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public ArrayList<ArrayList<Integer>> nQueen(int n)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) thr...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "nQueen(self, n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n\n ob = Solution()\n ans = ob.nQueen(n)\...
eJztXcuuJcdWZMCHlHps0M56Jx+CkNwWA/CASXMHvhISAvER8Jt8A312ZqyIWFnutsxFl0F6Yp+IXZWVr/XO9H/85X/99N9/8f7n7/7263/8+K+f/unLH/74y6e/WT6Vz1+Oz18+/bB8+vlf/vDzP/zy8z/+/T//8ZdO/vhDWbblWNZlX35aPv7av/738RX7+OsDbXz76wMv/Zftv9bO4R3l/ReeWvtfePLjL/xu63/hPT8tn7/8+9fv/LcfFv/48xsf//GqUz5x+/rXR2P4yI+GPho8rbnz2w1e3x2ta2kNY8SuBQ03BE1eMaqtySuN...
702,844
Sort the Half Sorted
Given an integer array of which both the first halve and second halve are sorted. The task is to merge these two sorted halves of the array into a single sorted array.Note: The two halves can be of arbitrary sizes (i.e. if first halve of size k then the second halve is of size N-k where 0<=k<=N). Examples: Input: N = 6...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public static void sortHalves(int arr[], int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\nclass GfG\n{\n public static void main (String[] args)\n {\n \n Sc...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "sortHalves(self, arr, n)" ], "initial_code": "# Initial Template for Python 3\n\nt = int(input())\nfor tc in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n ob = Solution()\n ob.sortHalves(ar...
eJytVEFOwzAQ5AD/GOXcRbYT14GXIBHEAXLgYnpIJSQE4hHwO258hNmoUAJdN5VILo4ys54ZT/Jy/PZxcjReF+9cXD5Wd3m1HqpzVL7LocsRUne5WqDqH1b9zdDfXt+vhw1EakR0+ZmApwWmXO+6LGeQFpIgS0iEg0dAjcYeaBCsTSjNESHenuihCEskDZpU01pLZw0kjPooc48nRviNLrqJmhqCQ+3QOERnzpzCCvNof0yAdymiL4w1Kekkh5/HQzelkX/BxaJ4R0JUBVGxfEiMLTDbCK58iPZOGzCJSnBK4VpZfEVmaWMPrXACtark...
703,189
Find minimum adjustment cost of an array
Given an array, arr[] of positive integers and an integer target, replace each element so that the difference between adjacent elements is less than or equal to a given target. We need to minimize the adjustment cost, the sum of differences between new and old values. We need to minimize ∑|A[i] Anew[i]| where 0 <= i <=...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "long minAdjustmentCost(long arr[], int target)" ], "initial_code": "// Initial Template for Java\n\n// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted....
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "minAdjustmentCost(self, arr, target)" ], "initial_code": "if __name__ == '__main__':\n t = int(input())\n for _ in range(0, t):\n a = list(map(int, input().split()))\n k = int(input())\n ob = Solutio...
eJydVMtOBCEQ9KD/UeG8MQ2zDPR+iYljPOgcvIx7mE1MjGY/Qr/Km19k06vxBSM4TBgyQNFVXc3++Pn15EifsxcZnN+bm2m7m80Gxg6TJVgP6Z0OnLw0TN6sYMa77Xg1j9eXt7v5Y4PMPQ6TeVjhO4wnrAndAYZACbiAUYKwYMbPLiGXYmFXQAqE4BEJ0YMJnPjph/VX1OmwQLMUohCracKlEViocgQHcK9xrsEd2IFFhX/AeSw0odFM++CPTpMsqe5FQUo6cppKAbYqqQlRiKBwv/3jmv3TwTkUepG4BY6WDLysd09/qNxT9kj1umjS...
702,960
Remove Consecutive Characters
Given a string S. For each index i(1<=i<=N-1), erase it if s[i] is equal to s[i-1] in the string. Examples: Input: S = aabb Output: ab Explanation: 'a' at 2nd position is appearing 2nd time consecutively. Similiar explanation for b at 4th position. Input: S = aabaa Output: aba Explanation: 'a' at 2nd position is a...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public String removeConsecutiveCharacter(String S)" ], "initial_code": "// Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "removeConsecutiveCharacter(self, S)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n\n for tcs in range(T):\n s = input()\n ob = Solution()\n pr...
eJy1Vttu2zAM3UMf9xGBsbcVBea97UsGzENhyUp8lRxf4svQoB/R/e9I2WncRoxld2HiXK3DIx5S5PPd36+fP2n7+QU+/PrjRDKvK+fHxvnuSZ/xQGx3aGEYxUmaSZXvi7KqD03b9cMNAWc+fip87gf45knnfuOINhe8EsGjqqsRcYQzIh0HMI11fAcH352n+82Em+vJHpYNF9wNxsA4WAAmwEgWuAifrz4F4eFMceTYdl07XiS6YV9thw+TEwgxV7IUvK6iA5LmoQ/7rkRRejIUaaqUalSRBoEn80LtCj/LIolykP4neFOwo8YbwPS3...
703,574
Binary representation of next number
Given a binary representation in the form of a string(s) of a number n, the task is to find a binary representation of n+1. Examples: Input: s = "10" Output: 11 Explanation: "10" is the binary representation of 2 and binary representation of 3 is "11" Input: s = "111" Output: 1000 Explanation: "111" is the binary r...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "String binaryNextNumber(String s)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n\nclass GfG {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System....
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "binaryNextNumber(self, s)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n T = int(input())\n for i in range(T):\n S = input()\n ob = Solution()\n ans = ob.binaryN...
eJylVLEOgjAQdTCObu6kMzHXqItfYmKNgzK4IAMkJkbjR+j/Wsr1CqF3YCyQFK7v3b13La/pZzGbuLGb28n+ri55UZVqm6iNybW9wT7aTerLvdih0kRltyI7ldn5eK1KxDQL6sUACME39+FpcvVIk1aSNUUBKElIRFMb1cAmRTy0CHQg0J5AxypYuWiTG0FcHu1rwaI5QTRa4qAnDgQXO6iIPV5dtIQ6KPQnCmC95RLQGKMhTkELhijYIshQliH41WfYuGZS49Fu3zeJ1m+pBkVawo5nPGseQa/g9iBWQg+Dpcym0y1HZYxgjma32Z8e...
705,585
Print the pattern
Write a program that receives a number n as input and prints it in the following format as shown below. Like for n = 2 the pattern will be: 1*2*5*6 --3*4 Examples: Input: n = 3 Output: 1*2*3*10*11*12 --4*5*8*9 ----6*7 Explanation: If the pattern shown in question is followed, this will be the output. Constraints: ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "static List<String> pattern(int n)" ], "initial_code": "//Initial Template for Java\n\nimport java.io.*;\nimport java.util.*;\n\nclass GFG{\n public static void main(String args[])throws IOException\n {\n Buffered...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "pattern(self, n)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n n = int(input())\n\n ob = Solution()\n ans = ob.pattern(n...
eJzsvc2OZTmyZqeBnkHjixo6OoFNMyNpW0+gRxCgAjSQ7kCTUg9uAw0IavTT6DnFtU5kVlRm/LhHeHhEVsVF5UHeQ89zzv72Js24+Bn53//H//X/+5/+l//hf/t//vJ//e0//5f/+Mv//G9/GX/92/jLf/q3v/z7f/3P//5//Me//5//+//9X/7j16an+Ovf/ttf//aX//c//ds//hfx0f8in+bT/uvffvllPtVH/uP85H88rqcRT6P4jP10P/V5h3//5Zcx+OQPfmR9+vc8jfO/+ynOBSWfdT+dzxp5vuVprKfR7z5/+ne/frlv8Zcf...
710,019
Can Make Triangle
Given an arrayA[]ofNelements, You'd like to know how many triangles can be formed with side lengths equal to adjacent elements from A[]. Examples: Input: N = 4 A[] = {1, 2, 2, 4} Output: 1 0 Explanation: output[0] = 1 because we can form a triangle with side lengths 1,2 and 2. output[1] = 0 because 2+2 < 4 so, we c...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1646060316, "func_sign": [ "int[] canMakeTriangle(int A[], int N)" ], "initial_code": "//Initial Template for Java\nimport java.io.*;\nimport java.util.*; \n\nclass FastReader{ \n BufferedReader br; \n StringTokenizer st; \n\n public FastReader(...
{ "class_name": "Solution", "created_at_timestamp": 1646060316, "func_sign": [ "canMakeTriangle(self, A, N)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n A = list(map(int, input().strip()....
eJytVEsKwjAQdaH3GLIWSZq2UU8iWHGhXbiJLioIongIPag7l05CS1vpZEoxaWko5L03v/cYvz6TkV+rNx7WV3Gwp3MhliBUZpPMKlkt6D4uqlWfxBREfjnluyLfb4/nogIEtzN7z6y4TaFNlToqSMBABHPQJARy40uAGASBxg4KCYjxcUPk9CT4IWAkSFrK3EnRGIxGmsh9SRTlcQJylPR66IeNk0t9XcTOyjI/GXqCVrdoe3QPgRO7TLs8J4E60YXWEGORUzBDutZz64Hk7nI6+DbVFKZvV8iy7ZhZ4oZJct2LQKbVh6FJUKHx5kOm...
702,917
Count increasing Subarrays
Given an array arr[]of integers, count the number of subarrays in arr[] which are strictly increasing with size greater or equal to 2. A subarray is a contiguous part of array. A subarray is strictly increasing if each element is greater then it's previous element if it exists. Examples: Input: arr[] = [1, 3, 3, 2, 3, ...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int countIncreasing(int[] arr)" ], "initial_code": "import java.io.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\npublic class Main {\n public static void main(String[] args) {\n ...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "countIncreasing(self, arr)" ], "initial_code": "if __name__ == \"__main__\":\n t = int(input())\n for _ in range(t):\n arr = list(map(int, input().split()))\n solution = Solution()\n print(solution.c...
eJy1VsuOEzEQ5MCFvyjNeYXcfpsvQSKIA+TAZdhDVloJsdqPgP+luj2JEjFOsgESuceeGferqnv8/PpXffPKfu+Fkw/fp6/z/cNueocpbGaBR0BE2syJl8Cl8K6Dd+gyOESH5JAditvM0x2m7eP99vNu++XTt4fdokv46Gkzd+m9XaYfdzgy5/eK/aJY12pGOGjXBY7IkXBwCxkFFQ0yNt2NZbdmU/YhDuQ4njQKASf/rv9oDDV2/+KaWrphmT+JFyIHvQtETJdDa42j8g1LnGXOKZRccR76ZtVhmob+hNbzZrKeTV780zGzJESLYGVI...
703,724
Odd or Even
Given a positive integer n, determine whether it is odd or even. Return a string "even" if the number is even and "odd" if the number is odd. Examples: Input: n = 15 Output: odd Explanation: The number is not divisible by 2 Input: n = 44 Output: even Explanation: The number is divisible by 2 Constraints: 0 <= n <=...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1619085344, "func_sign": [ "static String oddEven(int n)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.util.*;\n\nclass GFG {\n public static void main(String args[]) throws IOException {\n BufferedReader rea...
{ "class_name": "Solution", "created_at_timestamp": 1619085344, "func_sign": [ "oddEven(ob,n)" ], "initial_code": "# Initial Template for Python 3\nif __name__ == '__main__':\n t = int(input())\n for _ in range(t):\n N = int(input())\n ob = Solution()\n print(ob.oddEven(N))\n ...
eJxrYJnqw8IABhGuQEZ0tVJmXkFpiZKVgpJhTJ6Bko6CUmpFQWpySWpKfH5pCVQqtSw1LyavLiZPqVZHAVWLIQ4t+SkpOHQYkW6JJRCQbI+hARCQ4SEjYxPSdZmamVuQ7kQjEzMLMlxobGpOTmiQHlWGZEWwoaGxMSgxkeFIYNhbkh3fZLgUGnHkaCUrbYFCxpyMcAG6E+RQctxpSG5cQBIarryA0Bg7RQ8AuHVhmg==
703,450
Maximum number of partitions that can be sorted individually to make sorted
Given an array arrsuch that elements are in range [0, 1, ....n-1]. Our task is to divide the array into the maximum number of partitions that can be sorted individually and then concatenated to make the whole array sorted. Examples: Input: arr[] = [2, 1, 0, 3] Output: 2 Explanation: If divide arr[] into two partiti...
geeksforgeeks
Easy
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "public int maxPartitions(int[] arr)" ], "initial_code": "// Initial Template for Java\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\n//Position this line where user code will be pasted.\n\nclass GFG {\n pub...
{ "class_name": "Solution", "created_at_timestamp": 1615292571, "func_sign": [ "maxPartitions(self, arr)" ], "initial_code": "# Initial Template for Python 3\n\nif __name__ == \"__main__\":\n t = int(input())\n while t > 0:\n arr = list(map(int, input().split()))\n ob = Solution()\n ...
eJzt2EGOJkcRBlAWXIF9qtcWqszIzMjkJEgMYgGzYDN4MZaQEIhDwH3YcS1etGQLhBrPeLzE3ljW13/3X++rrIj660///s+f/eT1n1/+w3/86k8vv//w9TcfX37RXvq7D6s9rbfRos22W7bTbuv+V299tB6tz9ZX67v1bP20ftt4Xr5qL+//+PX73358/7vf/OGbj99+2n734S/vPrz8+av2n7/j+tT06cvvCL+rtzc/4o1PePxk/Y3dZ5z6O9/4+fnmz3/7Hdenfcs3Pn88b/yC/jzt3nZ9cLa7213tznaj3dFub/dpx1U47fjdux3f...