question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get-maximum-in-generated-array | [C++] DP Solution Explained | c-dp-solution-explained-by-ajna-jhep | Kinda of a dull, boring problem, but I get practice is made of that too.\n\nFirst we want to get 2 edge cases out the way, with the first in particular being ot | ajna | NORMAL | 2021-01-16T20:20:39.750392+00:00 | 2021-07-17T12:24:27.487040+00:00 | 3,384 | false | Kinda of a dull, boring problem, but I get practice is made of that too.\n\nFirst we want to get 2 edge cases out the way, with the first in particular being otherwise annoying: when we are given `n < 2`, we can just return `n`.\n\nIn all the other cases, we will create 2 variables:\n* `arr` is an array of `n + 1` (sin... | 20 | 0 | ['Dynamic Programming', 'C', 'C++'] | 3 |
get-maximum-in-generated-array | ✅Python3 || 23ms/Beats 97.74% | python3-23msbeats-9774-by-abdullayev_akb-vnm8 | \n\nPlease UPVOTE if it helps \u2764\uFE0F\uD83D\uDE0A\nThank You and Happy To Help You!!\n\n# Python3\n\nclass Solution:\n def getMaximumGenerated(self, n: | abdullayev_akbar | NORMAL | 2023-02-08T12:46:26.510583+00:00 | 2023-02-08T12:56:02.041423+00:00 | 1,454 | false | \n\nPlease UPVOTE if it helps \u2764\uFE0F\uD83D\uDE0A\nThank You and Happy To Help You!!\n\n# Python3\n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n dp=[0,1]\n for... | 15 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | Simple Java solution | simple-java-solution-by-ottomonempire-6uah | As you read the problem statement, the algorithm will be same, if we follow it. \nBelow is the easy to understand solution. However feel free to optimise this f | ottomonempire | NORMAL | 2020-11-08T04:10:31.134944+00:00 | 2021-01-15T12:28:42.352009+00:00 | 2,880 | false | As you read the problem statement, the algorithm will be same, if we follow it. \nBelow is the easy to understand solution. However feel free to optimise this further and come up with better solution.\nSpace complexity will be O(n+1).\n\n```\n public int getMaximumGenerated(int n) {\n if (n == 0)\n ret... | 14 | 1 | ['Dynamic Programming', 'Java'] | 4 |
get-maximum-in-generated-array | Python generators are like space shuttles | python-generators-are-like-space-shuttle-pkyv | Constructive solutions were posted before, but did you know that generators allow you get rid of used array parts, like a space shuttle gets rid of spent fuel t | haiduc | NORMAL | 2021-01-15T21:34:30.880264+00:00 | 2023-05-09T18:52:17.963802+00:00 | 733 | false | Constructive solutions were posted before, but did you know that generators allow you get rid of used array parts, like a space shuttle gets rid of spent fuel tanks?\n\n```\nfrom queue import deque\n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n \n def arrgen(n):\n yield... | 13 | 0 | ['Python3'] | 1 |
get-maximum-in-generated-array | Simulate the Generated Array.. | simulate-the-generated-array-by-admin007-4bsu | \n public int getMaximumGenerated(int n) {\n if (n <= 1) return n;\n int[] nums = new int[n + 1];\n nums[1] = 1;\n int max = 1;\n | admin007 | NORMAL | 2020-11-08T04:33:30.077446+00:00 | 2021-01-15T21:20:28.602333+00:00 | 1,531 | false | ```\n public int getMaximumGenerated(int n) {\n if (n <= 1) return n;\n int[] nums = new int[n + 1];\n nums[1] = 1;\n int max = 1;\n for (int i = 1; i < (n + 1) / 2; i++) {\n if (2 * i <= n) {\n nums[2 * i] = nums[i];\n max = Math.max(max, n... | 11 | 3 | [] | 3 |
get-maximum-in-generated-array | Easy Python Solution O(n) with Explanation | easy-python-solution-on-with-explanation-y0vn | \tclass Solution:\n\t\tdef getMaximumGenerated(self, n: int) -> int:\n\t\t\tif n==0: return 0\n\t\t\tarr = [0, 1]\n\t\t\tfor i in range(2, n+1):\n\t\t\t\tif i%2 | shadow_sm36 | NORMAL | 2020-11-08T04:25:43.249269+00:00 | 2020-11-08T04:25:43.249317+00:00 | 2,202 | false | \tclass Solution:\n\t\tdef getMaximumGenerated(self, n: int) -> int:\n\t\t\tif n==0: return 0\n\t\t\tarr = [0, 1]\n\t\t\tfor i in range(2, n+1):\n\t\t\t\tif i%2==0:\n\t\t\t\t\tarr.append(arr[i//2])\n\t\t\t\telse:\n\t\t\t\t\tarr.append(arr[i//2] + arr[i//2 + 1])\n\t\t\treturn max(arr)\n\t\t\t\nThe Basic Idea is that giv... | 10 | 2 | ['Python', 'Python3'] | 6 |
get-maximum-in-generated-array | [C++] Easy Solution - DP | c-easy-solution-dp-by-afrozchakure-3pmb | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == 0) return 0;\n vector<int> f(n+1, 0);\n f[0] = 0;\n f[1] | afrozchakure | NORMAL | 2020-11-08T04:12:49.759453+00:00 | 2021-01-15T12:24:32.394560+00:00 | 1,939 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == 0) return 0;\n vector<int> f(n+1, 0);\n f[0] = 0;\n f[1] = 1;\n int maximum = 1;\n for(int i=1; i<= n /2; i++)\n {\n if(i*2 > n || (2*i + 1) > n)\n break;\n ... | 9 | 2 | ['Dynamic Programming', 'C', 'C++'] | 2 |
get-maximum-in-generated-array | Python simple solution | python-simple-solution-by-tovam-qbaj | Python :\n\n\ndef getMaximumGenerated(self, n: int) -> int:\n\tif not n:\n\t\treturn n\n\n\tnums = [0] * (n + 1)\n\tnums[1] = 1\n\n\tfor i in range(2, n + 1): | TovAm | NORMAL | 2021-11-03T23:54:15.784432+00:00 | 2021-11-03T23:54:15.784471+00:00 | 1,042 | false | **Python :**\n\n```\ndef getMaximumGenerated(self, n: int) -> int:\n\tif not n:\n\t\treturn n\n\n\tnums = [0] * (n + 1)\n\tnums[1] = 1\n\n\tfor i in range(2, n + 1): \n\t\tif i % 2:\n\t\t\tnums[i] = nums[i // 2] + nums[i // 2 + 1]\n\n\t\telse:\n\t\t\tnums[i] = nums[i // 2]\n\n\treturn max(nums)\n```\n\n**Like... | 8 | 0 | ['Python', 'Python3'] | 0 |
get-maximum-in-generated-array | Awesome Code--->Python3 | awesome-code-python3-by-ganjinaveen-wthy | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | GANJINAVEEN | NORMAL | 2023-03-17T07:33:15.497555+00:00 | 2023-03-17T07:33:15.497605+00:00 | 699 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 6 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | Python3 O(n) space & time | python3-on-space-time-by-dark_wolf_jss-miac | \nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = [0,1]\n output = 0\n for i in range(2,n+1):\n toAp | dark_wolf_jss | NORMAL | 2021-12-11T12:47:48.655359+00:00 | 2021-12-11T12:52:53.888456+00:00 | 184 | false | ```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = [0,1]\n output = 0\n for i in range(2,n+1):\n toAppend = nums[i//2] if i%2 == 0 else nums[i//2] + nums[1+(i//2)]\n output = max(output, toAppend)\n nums.append(toAppend)\n retur... | 5 | 0 | [] | 0 |
get-maximum-in-generated-array | Java | Beats 100% | Easy iteration | java-beats-100-easy-iteration-by-u99omeg-0454 | \nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0 || n==1) return n;\n \n int nums[]=new int [n+1];\n \n | U99Omega | NORMAL | 2021-08-22T22:04:06.429613+00:00 | 2021-08-22T22:04:06.429644+00:00 | 758 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0 || n==1) return n;\n \n int nums[]=new int [n+1];\n \n nums[0]=0;\n nums[1]=1;\n int max=Integer.MIN_VALUE;\n \n for(int i=2;i<=n;i++){\n if(i%2==0){\n nu... | 5 | 0 | ['Dynamic Programming', 'Java'] | 0 |
get-maximum-in-generated-array | [Scala] self-referential lazy sequence | scala-self-referential-lazy-sequence-by-385vy | scala\nobject Solution {\n lazy val seq: LazyList[Int] = LazyList(0, 1, 1) #::: seq.tail.zip(seq.drop(2)).flatMap { case (a, b) => Array(a + b, b) }\n def get | nizhnik | NORMAL | 2021-01-15T09:04:30.990559+00:00 | 2021-01-15T09:04:30.990584+00:00 | 328 | false | ```scala\nobject Solution {\n lazy val seq: LazyList[Int] = LazyList(0, 1, 1) #::: seq.tail.zip(seq.drop(2)).flatMap { case (a, b) => Array(a + b, b) }\n def getMaximumGenerated(n: Int): Int = seq.take(n + 1).max\n}\n``` | 5 | 0 | ['Scala'] | 0 |
get-maximum-in-generated-array | C++ Faster Than 100% | c-faster-than-100-by-theriley106-h0a3 | cpp\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int array[n+1];\n int largestNum = 0;\n \n for (int i=0; i<n+ | theriley106 | NORMAL | 2020-11-09T01:21:48.880652+00:00 | 2020-11-09T01:21:48.880700+00:00 | 800 | false | ```cpp\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int array[n+1];\n int largestNum = 0;\n \n for (int i=0; i<n+1; i++){\n if (i==0){\n array[0] = 0;\n } else if (i==1){\n array[1] = 1;\n }\n \n ... | 5 | 0 | ['C'] | 1 |
get-maximum-in-generated-array | simple java solution || space optimized dynamic programming 100% faster | simple-java-solution-space-optimized-dyn-jvp1 | ```\n// if you found my solution usefull please upvote it\nclass Solution \n{\n public int getMaximumGenerated(int n) \n {\n if(n==0) return 0; // | Haswanth_kumar | NORMAL | 2022-10-18T18:22:11.337998+00:00 | 2022-10-18T18:22:53.093410+00:00 | 795 | false | ```\n// if you found my solution usefull please upvote it\nclass Solution \n{\n public int getMaximumGenerated(int n) \n {\n if(n==0) return 0; // base case\n int[] nums=new int[n+1];\n nums[0]=0;\n nums[1]=1;\n int idx=1;\n int cnt=0;\n int ans=1;\n for(in... | 4 | 0 | ['Dynamic Programming', 'Java'] | 2 |
get-maximum-in-generated-array | Easy for beginnners [C++] MOST OPTIMIZED 0ms 100% | easy-for-beginnners-c-most-optimized-0ms-abct | Idea\nIdea behind the solution is pretty easy - maintain an array of already obtained values to shortcut calculation on each step.\n## Important lesson for begi | sne4kers | NORMAL | 2022-10-16T21:55:34.809506+00:00 | 2023-06-06T21:48:30.864468+00:00 | 781 | false | ## Idea\nIdea behind the solution is pretty easy - maintain an array of already obtained values to shortcut calculation on each step.\n## Important lesson for beginners\nAlthough the division with `/ 2` and `% 2 == 1` is good enough to pass the problem, it misses an important lesson that division is an expensive operta... | 4 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'C++'] | 0 |
get-maximum-in-generated-array | 💯✅Dynamic Programming Easy to Understand short code | dynamic-programming-easy-to-understand-s-lwm9 | I think this code is self explainatory.But if have any query then comment down below..\n\nclass Solution {\n public int getMaximumGenerated(int n) {\n | deity0503 | NORMAL | 2022-10-03T16:54:45.599586+00:00 | 2022-10-03T16:54:45.599633+00:00 | 3,078 | false | I think this code is self explainatory.But if have any query then comment down below..\n```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0)return 0;\n if(n==1)return 1;\n int []arr=new int[n+1];\n arr[0]=0;\n arr[1]=1;\n int maxi=Integer.MIN_VALUE;\n ... | 4 | 0 | ['Dynamic Programming', 'Java'] | 2 |
get-maximum-in-generated-array | C++ || DP || 100% FASTER || SIMPLE SHORT SOLUTION | c-dp-100-faster-simple-short-solution-by-2ccu | \nint getMaximumGenerated(int n) {\n int dp[n+1];\n if(n==0){return 0;}\n if(n==1){return 1;}\n dp[0]=0;\n dp[1]=1;\n | sxkshi | NORMAL | 2022-09-20T06:49:15.748174+00:00 | 2022-09-20T06:49:15.748216+00:00 | 691 | false | ```\nint getMaximumGenerated(int n) {\n int dp[n+1];\n if(n==0){return 0;}\n if(n==1){return 1;}\n dp[0]=0;\n dp[1]=1;\n int maxi=dp[1];\n \n for(int i=2;i<n+1;i++)\n {\n if(i%2==0)\n {\n dp[i]=dp[i/2];\n }\n ... | 4 | 0 | ['Dynamic Programming', 'C', 'C++'] | 0 |
get-maximum-in-generated-array | [C++] Easy to understand one pass solution (100% time and 100% space) | c-easy-to-understand-one-pass-solution-1-alfr | This solution creates an array of the required size and updates the elements in the array while iterating up to n. Each element is calculated conditionally by c | bhaviksheth | NORMAL | 2021-01-15T21:58:09.836243+00:00 | 2021-01-16T23:57:12.492512+00:00 | 269 | false | This solution creates an array of the required size and updates the elements in the array while iterating up to n. Each element is calculated conditionally by checking if `i` is odd or even.\n\n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if (n < 2) return n;\n \n int nums... | 4 | 2 | [] | 1 |
get-maximum-in-generated-array | ✔️ 🔥 Simple C++ Solution 🔥 || Easy to understand || Must Check 🔥 | simple-c-solution-easy-to-understand-mus-b91k | Solution:\n\n---\n\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n if(n<2)\n return n;\n\n int arr[n+1];\n\n | codingstar2001 | NORMAL | 2023-06-08T06:26:57.600396+00:00 | 2023-06-08T06:26:57.600440+00:00 | 855 | false | **Solution:**\n\n---\n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n if(n<2)\n return n;\n\n int arr[n+1];\n\n int maxi = INT_MIN;\n\n arr[0] = 0;\n arr[1] = 1;\n\n for(int i = 2;i<=n;i++){\n if(i%2==1)\n arr[i] = a... | 3 | 0 | ['Dynamic Programming', 'C++'] | 0 |
get-maximum-in-generated-array | Recursion -> Memoization -> Tabulation | recursion-memoization-tabulation-by-tana-c4wy | Recursive\n\n int fun(int n) {\n if(n==0 || n==1) return n;\n \n if(n%2==1) {\n int a = fun((n-1)/2);\n int b = fu | TanayD304 | NORMAL | 2022-11-03T18:49:05.639679+00:00 | 2022-11-03T18:49:05.639714+00:00 | 450 | false | **Recursive**\n```\n int fun(int n) {\n if(n==0 || n==1) return n;\n \n if(n%2==1) {\n int a = fun((n-1)/2);\n int b = fun(((n-1)/2)+1);\n return a+b;\n } else return fun(n/2);\n }\n int getMaximumGenerated(int n) {\n if(n==0 || n==1) return n... | 3 | 0 | [] | 0 |
get-maximum-in-generated-array | Java Easiest Solution || 1Ms Runtime Faster than 90% Online Submission || Beginner Friendly Approach | java-easiest-solution-1ms-runtime-faster-23rn | \n//Approch :- 1 Primitive O(n + n) 2Ms Runtime\nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n+1];\n if(n | Hemang_Jiwnani | NORMAL | 2022-10-14T15:51:49.121239+00:00 | 2022-10-14T15:51:49.121274+00:00 | 1,011 | false | ```\n//Approch :- 1 Primitive O(n + n) 2Ms Runtime\nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n+1];\n if(n == 0){\n return 0;\n }\n arr[0] = 0;\n arr[1] = 1;\n for(int i=1;i<n;i++){\n if((2*i) < n+1){\n ... | 3 | 0 | ['Java'] | 1 |
get-maximum-in-generated-array | C++|| SIMPLEST SOLUTION || BEGINNER FRIENDLY || FULLY EXPLAINED | c-simplest-solution-beginner-friendly-fu-0h9y | first of all we eliminate the edge cases i.e n == 0;\n2. then we declare a vector, you can use a array, it\'s the same use here;\n3. we fill in the values of 0, | prasoonrajpoot | NORMAL | 2022-07-29T04:31:39.088273+00:00 | 2022-07-29T04:31:39.088313+00:00 | 346 | false | 1. first of all we eliminate the edge cases i.e n == 0;\n2. then we declare a vector, you can use a array, it\'s the same use here;\n3. we fill in the values of 0,1 indexes as given in the question.\n4. we Put in the exact conditions given in the question.\n5. we return the max_element (an stl function) to get the answ... | 3 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | C++ solution | 0s | faster than 100% | 9 lines code | c-solution-0s-faster-than-100-9-lines-co-t9k3 | \nint getMaximumGenerated(int n) {\n if(n==0) return 0;\n if(n==1) return 1;\n int nums[n+1]; nums[0] =0 , nums[1] = 1;\n for( | nova_007 | NORMAL | 2022-07-03T19:09:39.652841+00:00 | 2022-07-03T19:12:35.089084+00:00 | 130 | false | ```\nint getMaximumGenerated(int n) {\n if(n==0) return 0;\n if(n==1) return 1;\n int nums[n+1]; nums[0] =0 , nums[1] = 1;\n for(int i=1; i<(n+1)/2; i++)\n nums[2*i] = nums[i], nums[2*i + 1] = nums[i] + nums[i+1];\n if((n+1)%2) nums[n] = nums[(n)/2];\n int Max... | 3 | 0 | ['Array'] | 0 |
get-maximum-in-generated-array | JAVA 100% FASTER Solution | java-100-faster-solution-by-yash_sawant7-2e6v | \n\n\n\n\n\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n<=1)return n;\n int[] arr=new int[n+1];\n arr[0]=0;\n | yash_sawant724 | NORMAL | 2022-05-06T12:26:05.170101+00:00 | 2022-05-06T12:27:12.703816+00:00 | 485 | false | \n\n\n\n\n```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n<=1)return n;\n int[] arr=new int[n+1];\n arr[0]=0;\n arr[1]=1;\n \n for(int i=2;i<=n... | 3 | 0 | ['Dynamic Programming', 'Java'] | 0 |
get-maximum-in-generated-array | Go just do it | go-just-do-it-by-dchooyc-8ryx | \nfunc getMaximumGenerated(n int) int {\n if n < 2 {\n return n\n }\n \n a, max := make([]int, n + 1), 0\n \n a[0] = 0\n a[1] = 1\n | dchooyc | NORMAL | 2022-04-19T15:04:05.293028+00:00 | 2022-04-19T15:04:05.293068+00:00 | 190 | false | ```\nfunc getMaximumGenerated(n int) int {\n if n < 2 {\n return n\n }\n \n a, max := make([]int, n + 1), 0\n \n a[0] = 0\n a[1] = 1\n \n for i := 2; i <= n; i++ {\n num := a[i / 2]\n \n if i % 2 == 1 {\n num += a[(i / 2) + 1]\n }\n \n ... | 3 | 0 | ['Go'] | 0 |
get-maximum-in-generated-array | Simple C++ Solution | simple-c-solution-by-karthi_701-6qwf | class Solution {\npublic:\n int getMaximumGenerated(int n) {\n vectork(n+1000,0);k[0]=0;k[1]=1;int i=2;\n while(i<=n){\n if(i%2==0) | karthi_701 | NORMAL | 2021-09-25T10:20:20.040088+00:00 | 2021-09-26T08:58:46.972226+00:00 | 189 | false | class Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int>k(n+1000,0);k[0]=0;k[1]=1;int i=2;\n while(i<=n){\n if(i%2==0) {\n k[i]=k[i/2];\n }else{\n \xA0 \xA0 \xA0 \xA0 \xA0 \xA0 \xA0 k[i]=k[i/2]+k[i/2+1];\n }i++;\n }\n \xA0 if(n==... | 3 | 0 | [] | 1 |
get-maximum-in-generated-array | Simple Python 3 Solution, Easy to understand. | simple-python-3-solution-easy-to-underst-x8pd | \n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = [0,1]\n j = 1\n for i in range(2,n//2+2):\n nums | sethhritik | NORMAL | 2021-01-22T17:24:31.912986+00:00 | 2021-01-22T17:24:31.913031+00:00 | 133 | false | \n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = [0,1]\n j = 1\n for i in range(2,n//2+2):\n nums.append(nums[j])\n nums.append(nums[j]+nums[j+1])\n j+=1\n return max(nums[:n+1])\n \n``` | 3 | 0 | [] | 0 |
get-maximum-in-generated-array | 𝑒𝓁𝑒𝑔𝒶𝓃𝓉 O(1) space ^^ | elegant-o1-space-by-andrii_khlevniuk-3zh2 | \nint getMaximumGenerated(int n) \n{\n\tauto out{0};\n\tfor(auto i{1}, a{0}, b{1}; i<=n; out = max(out, a = exchange(b, (2*__builtin_ctz(i++)+1)*b-a)));\n\tretu | andrii_khlevniuk | NORMAL | 2020-11-10T12:43:13.678418+00:00 | 2020-11-15T14:34:47.579398+00:00 | 312 | false | ```\nint getMaximumGenerated(int n) \n{\n\tauto out{0};\n\tfor(auto i{1}, a{0}, b{1}; i<=n; out = max(out, a = exchange(b, (2*__builtin_ctz(i++)+1)*b-a)));\n\treturn out; \n}\n```\n\n**Brief explanation**\n\nGo over all `n+1` numbers keeping track of the maximum. It turns out you don\'t need to store the full array.... | 3 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | [Kotlin] Check Even-Odd | kotlin-check-even-odd-by-parassidhu-i6o4 | \n fun getMaximumGenerated(n: Int): Int {\n if (n == 0) return 0\n val res = IntArray(n + 1)\n var max = 1\n res[0] = 0 // Rule 1\n | parassidhu | NORMAL | 2020-11-08T04:15:09.831820+00:00 | 2020-11-08T04:15:09.831863+00:00 | 359 | false | ```\n fun getMaximumGenerated(n: Int): Int {\n if (n == 0) return 0\n val res = IntArray(n + 1)\n var max = 1\n res[0] = 0 // Rule 1\n res[1] = 1 // Rule 2\n \n for (i in 2 until res.size) {\n if (i % 2 == 0)\n res[i] = res[i/2] // Rule 3\n ... | 3 | 0 | ['Kotlin'] | 0 |
get-maximum-in-generated-array | Java | Pre Compute Array as told | java-pre-compute-array-as-told-by-abidee-7bzr | \nclass Solution {\n public int getMaximumGenerated(int n) {\n \n if(n == 0) return 0;\n if(n==1) return 1;\n \n int[] arr | abideenzainuel | NORMAL | 2020-11-08T04:07:58.865358+00:00 | 2020-11-08T04:08:34.622345+00:00 | 415 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n \n if(n == 0) return 0;\n if(n==1) return 1;\n \n int[] arr = new int[n+1];\n arr[0] = 0;\n arr[1] = 1;\n \n int max = 1;\n \n for(int i=2; i<arr.length; i++){\n i... | 3 | 2 | ['Java'] | 0 |
get-maximum-in-generated-array | Here's the simple Java solution. | heres-the-simple-java-solution-by-jagank-4p7g | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | jagankumaroffl | NORMAL | 2025-01-09T04:38:29.983818+00:00 | 2025-01-09T04:38:29.983818+00:00 | 203 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Java'] | 0 |
get-maximum-in-generated-array | Simple C solution | simple-c-solution-by-aswath_1192-5xsd | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Aswath_1192 | NORMAL | 2025-01-07T15:00:04.645827+00:00 | 2025-01-07T15:00:04.645827+00:00 | 50 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | Stern's Diatomic Sequence | sterns-diatomic-sequence-by-iyerke-7pck | Intuition\n Describe your first thoughts on how to solve this problem. \nThis is Stern\'s Diatomic Sequence.\n\n# Approach\n Describe your approach to solving t | iyerke | NORMAL | 2024-04-19T20:50:10.546605+00:00 | 2024-09-01T04:17:01.671905+00:00 | 96 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is Stern\'s Diatomic Sequence.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe apply proposition 4.3 in this paper:\nhttps://www.jstor.org/stable/10.4169/000298910x496714.\n\nNamely, $$a_{n+1}=a_n + a_{n-1}... | 2 | 0 | ['Python3'] | 2 |
get-maximum-in-generated-array | efficient JS | efficient-js-by-javad_pk-k05z | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | javad_pk | NORMAL | 2024-02-18T09:38:08.923722+00:00 | 2024-02-18T09:38:08.923755+00:00 | 77 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['JavaScript'] | 0 |
get-maximum-in-generated-array | Simple Java Solution | Detail Explanations | O(n) | DP | Please UPVOTE | Vrund Patel | simple-java-solution-detail-explanations-ai90 | Intuition\nThe problem asks for finding the maximum value in an array generated according to a specific pattern. To solve this, we need to simulate the generati | vrund297 | NORMAL | 2023-09-16T08:45:18.227176+00:00 | 2023-09-16T08:45:18.227205+00:00 | 337 | false | # Intuition\nThe problem asks for finding the maximum value in an array generated according to a specific pattern. To solve this, we need to simulate the generation process and keep track of the maximum value encountered during the process.\n\n# Approach\nThe code takes the following approach:\n1. If `n` is 0, return 0... | 2 | 0 | ['Dynamic Programming', 'Java'] | 0 |
get-maximum-in-generated-array | Simple DP solution C++ | simple-dp-solution-c-by-sunnyyad2002-0ec2 | Intuition \n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sunnyyad2002 | NORMAL | 2023-03-31T17:31:31.101448+00:00 | 2023-03-31T17:31:31.101487+00:00 | 1,890 | false | # Intuition \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -... | 2 | 0 | ['C++'] | 0 |
get-maximum-in-generated-array | ✅✅✅ very easy solution 0(n) | very-easy-solution-0n-by-najmiddin1-t0wo | \nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n<2: return n\n arr, m = [0, 1], 0\n for i in range(2, n+1):\n | Najmiddin1 | NORMAL | 2022-12-30T04:59:11.630389+00:00 | 2022-12-30T04:59:11.630436+00:00 | 1,101 | false | ```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n<2: return n\n arr, m = [0, 1], 0\n for i in range(2, n+1):\n arr += [arr[i//2]+arr[i//2+1] if i%2 else arr[i//2]]\n if arr[i]>m: m =arr[i]\n return m\n``` | 2 | 0 | ['Python', 'Python3'] | 0 |
get-maximum-in-generated-array | Java | java-by-niyazjava-vnid | \n\n public int getMaximumGenerated(int n) {\n if (n == 1) return 1;\n if (n == 0) return 0;\n \n int[] arr = new int[n+1];\n | NiyazJava | NORMAL | 2022-11-27T07:27:54.115176+00:00 | 2022-11-27T07:27:54.115222+00:00 | 417 | false | ```\n\n public int getMaximumGenerated(int n) {\n if (n == 1) return 1;\n if (n == 0) return 0;\n \n int[] arr = new int[n+1];\n arr[0] = 0;\n arr[1] = 1;\n int max = 0;\n\n for (int i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n arr[... | 2 | 0 | ['Java'] | 0 |
get-maximum-in-generated-array | JS faster than 100% (easy solution and optimize run time) | js-faster-than-100-easy-solution-and-opt-8drh | \n\n# Code\n# Solution 1: Recursion\n\n/**\n * @param {number} n\n * @return {number}\n */\n const getValue = (n) => {\n if (n === 0) return 0;\n if (n = | kunkka1996 | NORMAL | 2022-11-25T04:39:57.442591+00:00 | 2022-11-25T04:51:37.665651+00:00 | 1,030 | false | \n\n# Code\n# Solution 1: Recursion\n```\n/**\n * @param {number} n\n * @return {number}\n */\n const getValue = (n) => {\n if (n === 0) return 0;\n if (n === 1) return 1;\n\n if (n % 2) {\n ... | 2 | 0 | ['Memoization', 'JavaScript'] | 0 |
get-maximum-in-generated-array | c++ | easy | fast | c-easy-fast-by-venomhighs7-t2q4 | \n\n# Code\n\n//from sne4kers\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int> dp(n + 1, 0);\n if(n == 0)\n | venomhighs7 | NORMAL | 2022-11-22T12:11:57.212366+00:00 | 2022-11-22T12:11:57.212395+00:00 | 972 | false | \n\n# Code\n```\n//from sne4kers\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int> dp(n + 1, 0);\n if(n == 0)\n return 0;\n dp[1] = 1;\n int maxi = 1;\n for(int i = 2; i <= n; ++i){\n if(i & 1)\n dp[i] = dp[i >> 1] + dp... | 2 | 0 | ['C++'] | 0 |
get-maximum-in-generated-array | Java Solution using DP | java-solution-using-dp-by-astiksarathe-nvsr | \nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n + 1];\n int m = 0;\n \n if(n<=1) return n;\n | astiksarathe | NORMAL | 2022-09-18T14:53:15.238771+00:00 | 2022-09-18T14:53:15.238811+00:00 | 611 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n + 1];\n int m = 0;\n \n if(n<=1) return n;\n if(n == 2) return 1;\n \n arr[0] = 0; arr[1] = 1;\n for(int i = 2; i <= n; i++){\n \n if(i %2 == 0){\n ... | 2 | 0 | ['Java'] | 0 |
get-maximum-in-generated-array | Java | 1ms | java-1ms-by-aashishjn-bvw9 | \nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0)\n return 0;\n if(n==1)\n return 1;\n int d | aashishjn | NORMAL | 2022-08-06T13:26:45.720291+00:00 | 2022-08-06T13:26:45.720329+00:00 | 115 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0)\n return 0;\n if(n==1)\n return 1;\n int dp[] = new int[n+1];\n int max=1;\n dp[0]=0;\n dp[1]=1;\n for(int i=2;i<=n;i++)\n {\n if(i%2 == 0)\n ... | 2 | 0 | ['Dynamic Programming', 'Java'] | 0 |
get-maximum-in-generated-array | C++ Easy Well-Explained Solution (Dynamic Programming) | c-easy-well-explained-solution-dynamic-p-5l35 | We have to traverse from i=0 to i=n. Initialize vector m of size (n+1).\nm[0]=0, m[1]=1\nFor every iteration, \n\t1.Even i (i%2==0)\n\t\t m[i]= m[i/2];\n\t2.Odd | asmita010 | NORMAL | 2022-01-09T11:45:21.530726+00:00 | 2022-04-16T05:18:52.753892+00:00 | 177 | false | We have to traverse from i=0 to i=n. Initialize vector m of size (n+1).\nm[0]=0, m[1]=1\nFor every iteration, \n\t1.Even i (i%2==0)\n\t\t m[i]= m[i/2];\n\t2.Odd i\n\t\tex-9\n\t\tm[9]= m[(9-1)/ 2]+ m[((9-1)/ 2) +1] =m[8/2]+ m[8/2+1] =m[4]+m[5]\n\t3.Calculating Max value\nReturn Maximum value\n**Upvote** if th... | 2 | 1 | ['Array', 'Dynamic Programming', 'C'] | 1 |
get-maximum-in-generated-array | C++ || 0ms runtime || 100% faster | c-0ms-runtime-100-faster-by-yaswankar199-hv6j | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n==0) return 0;\n if(n==1) return 1;\n int max=0,d,q,i;\n vec | yaswankar1998 | NORMAL | 2022-01-04T11:20:48.581329+00:00 | 2022-01-04T11:20:48.581362+00:00 | 120 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n==0) return 0;\n if(n==1) return 1;\n int max=0,d,q,i;\n vector<int> nums(n+1,0);\n nums[0]=0;\n nums[1]=1;\n for(i=2; i<=n; i++) {\n d=i%2,q=i/2;\n if(d > 0) nums[i]= nums[q... | 2 | 0 | ['Dynamic Programming'] | 0 |
get-maximum-in-generated-array | c++/dp/100% fast and 99% fast used less space | cdp100-fast-and-99-fast-used-less-space-5o3x4 | \n if(n==0) return 0;\n int nums[n+1];\n nums[0]=0;\n nums[1]=1;\n for(int i=2;i<=n;i++){\n if(i%2==0) nums[i]=nums[i/2];\ | ravirkumar2422 | NORMAL | 2021-11-13T14:03:13.976464+00:00 | 2021-11-13T14:03:13.976511+00:00 | 148 | false | ```\n if(n==0) return 0;\n int nums[n+1];\n nums[0]=0;\n nums[1]=1;\n for(int i=2;i<=n;i++){\n if(i%2==0) nums[i]=nums[i/2];\n else nums[i]=nums[i/2]+nums[i/2+1];\n }\n int ans=0;\n for(int i=0;i<=n;i++){\n ans=max(ans,nums[i]);\n ... | 2 | 0 | ['Dynamic Programming'] | 1 |
get-maximum-in-generated-array | C++ | Dynamic Programing | 100% faster | Simple Maths | c-dynamic-programing-100-faster-simple-m-89tg | There is just a easy patter you can observe and can store element in array. The patter is the number for index 0, 1, 2 are fixed that is 0, 1, 1 respectively. F | avinash1320 | NORMAL | 2021-08-02T12:47:19.415428+00:00 | 2021-08-02T12:47:19.415512+00:00 | 225 | false | There is just a easy patter you can observe and can store element in array. The patter is the number for index `0, 1, 2` are fixed that is `0, 1, 1` respectively. From 3 onward the patter is if the `index `is `even` then `ans[i]= ans[i/2]` and if the `index` is `odd` then the `ans[i] = ans[i/2] + ans[(i/2)+1]`.\n```\nc... | 2 | 1 | ['Math', 'Dynamic Programming', 'C', 'C++'] | 0 |
get-maximum-in-generated-array | Java beats 100% | java-beats-100-by-sanket100-frar | \nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n+1];\n if(n<=1)return n;\n arr[0]=0;\n arr[1] | Sanket100 | NORMAL | 2021-07-23T19:35:22.562334+00:00 | 2021-07-23T19:35:22.562364+00:00 | 94 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n int[] arr = new int[n+1];\n if(n<=1)return n;\n arr[0]=0;\n arr[1]=1;\n int temp = 0,max=0;\n for(int i=2;i<=n;i++){\n if(i%2==0)arr[i]=arr[i/2];\n else {\n temp = (i-1)/2;... | 2 | 0 | [] | 0 |
get-maximum-in-generated-array | easy python | O(n) solution | easy-python-on-solution-by-abhishen99-dv23 | \nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n==0:\n return 0\n t=[0]*(n+1)\n t[1] = 1 \n | Abhishen99 | NORMAL | 2021-06-27T12:31:48.069125+00:00 | 2021-06-27T12:31:48.069202+00:00 | 260 | false | ```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n==0:\n return 0\n t=[0]*(n+1)\n t[1] = 1 \n for i in range(2,n+1):\n \n if i%2==0:\n t[i] = t[i//2]\n else:\n t[i] = t[i//2] +t[i//2 + 1]... | 2 | 0 | ['Python', 'Python3'] | 0 |
get-maximum-in-generated-array | Java faster than 100% | java-faster-than-100-by-otabek94_30-zrw3 | \nclass Solution {\n public int getMaximumGenerated(int n) {\n int i, j, max = -1000;\n int nums[] = new int[n + 1];\n \n for(i = | otabek94_30 | NORMAL | 2021-05-25T10:58:46.313738+00:00 | 2021-05-25T10:59:27.324135+00:00 | 58 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n int i, j, max = -1000;\n int nums[] = new int[n + 1];\n \n for(i = 0; i <= n; i++){\n if(i == 0){\n nums[i] = 0;\n }\n else if(i == 1){\n nums[i]=1;\n ... | 2 | 0 | [] | 0 |
get-maximum-in-generated-array | Java || Array || beats 100% || 0ms || T.C - O(N) S.C - O(N) | java-array-beats-100-0ms-tc-on-sc-on-by-yx5i0 | \n // O(n) O(n)\n\tpublic int getMaximumGenerated(int n) {\n\n if(n == 0)\n return 0;\n \n\t\tint[] ans = new int[n + 1];\n\t\tans[0 | LegendaryCoder | NORMAL | 2021-04-24T17:22:08.777182+00:00 | 2021-04-24T17:22:08.777226+00:00 | 79 | false | \n // O(n) O(n)\n\tpublic int getMaximumGenerated(int n) {\n\n if(n == 0)\n return 0;\n \n\t\tint[] ans = new int[n + 1];\n\t\tans[0] = 0;\n\t\tans[1] = 1;\n\t\tint max = 1;\n\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tans[i] = (i % 2 == 0) ? ans[i / 2] : ans[i / 2] + ans[i / 2 + 1];\n\t\t\t... | 2 | 0 | [] | 0 |
get-maximum-in-generated-array | Python3 simple solution best 90% users | python3-simple-solution-best-90-users-by-yupt | \nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n == 0:\n return 0\n elif n == 1:\n return 1\n | EklavyaJoshi | NORMAL | 2021-04-14T17:05:28.938069+00:00 | 2021-04-14T17:05:28.938110+00:00 | 136 | false | ```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n nums = [0,1]\n for i in range(2,n+1):\n if i%2 == 0:\n nums.append(nums[i//2])\n ... | 2 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | [c++] easy to understand | c-easy-to-understand-by-super_cool123-zti2 | **simple c++ solution \ntime complexity = O(n)\nspace complexity = O(n)\n\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n <= 1) | super_cool123 | NORMAL | 2021-01-16T06:27:16.239662+00:00 | 2021-01-16T06:27:16.239713+00:00 | 147 | false | **simple c++ solution \ntime complexity = O(n)\nspace complexity = O(n)\n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n <= 1) // base condition \n return n; \n vector<int>v(n+1); // create a vector of size+1\n v[0] = 0; // given in the problem statement\n ... | 2 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | [Scala] ❤ Get Maximum in Generated Array | good style | recursive and iterative | scala-get-maximum-in-generated-array-goo-0buz | Solution 1: recursive solution\n\nscala\nobject Solution {\n def getMaximumGenerated(n: Int): Int = {\n (0 to n).map(valueAtPositionK).max\n }\n\n def va | victoria_p_liao | NORMAL | 2021-01-16T01:26:24.979883+00:00 | 2021-01-16T02:41:05.892111+00:00 | 116 | false | Solution 1: recursive solution\n\n```scala\nobject Solution {\n def getMaximumGenerated(n: Int): Int = {\n (0 to n).map(valueAtPositionK).max\n }\n\n def valueAtPositionK(positionK: Int): Int = {\n if (positionK == 0) 0 else if (positionK == 1) 1 else {\n val kModTwo: Int = positionK % 2\n val kDivT... | 2 | 0 | [] | 1 |
get-maximum-in-generated-array | Easy java solution | easy-java-solution-by-abhishekjain581-y4dm | \nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n<1) return 0;\n int nums[] = new int[n+1];\n \n nums[0]=0;\n | abhishekjain581 | NORMAL | 2021-01-15T18:21:30.035894+00:00 | 2021-01-15T18:21:30.035922+00:00 | 54 | false | ```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n<1) return 0;\n int nums[] = new int[n+1];\n \n nums[0]=0;\n nums[1]=1;\n int i=1;\n int aa=1;\n while(aa<=n)\n {\n if((2*i)>n) break;\n nums[2*i]=nums[i];\n ... | 2 | 0 | [] | 2 |
get-maximum-in-generated-array | [c++] 0ms solution | better explanation stepwise | c-0ms-solution-better-explanation-stepwi-51ro | \n int getMaximumGenerated(int n) {\n if(n == 0) {\n return 0;\n }\n vector<int> v;\n v.push_back(0); // v[0] first ele | Ved_Prakash1102 | NORMAL | 2021-01-15T13:22:12.664069+00:00 | 2021-01-15T13:22:12.664092+00:00 | 176 | false | ```\n int getMaximumGenerated(int n) {\n if(n == 0) {\n return 0;\n }\n vector<int> v;\n v.push_back(0); // v[0] first element\n v.push_back(1); // v[1] second element\n int MAX = 1; // since 1 is max of v[0] & v[1]\n for(int i = 2; i <= n; i++) { // i... | 2 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | Simple java solution with explaination, 0ms, 100% faster | simple-java-solution-with-explaination-0-8sle | just use the rules mentioned in question and compute the array. while computing array keep track of maximum element till that index.\n2. when loop finishes max | kushguptacse | NORMAL | 2021-01-15T08:48:07.838793+00:00 | 2021-01-15T08:48:07.838832+00:00 | 122 | false | 1. just use the rules mentioned in question and compute the array. while computing array keep track of maximum element till that index.\n2. when loop finishes max is the answer.\n3. if n==0 return 0. else create array of size n+1. and set arr[1]=1.\n4. now check if arr[i] element is even. if yes just assign arr[i]=arr[... | 2 | 1 | ['Java'] | 0 |
get-maximum-in-generated-array | C++| 0ms faster than 100% | c-0ms-faster-than-100-by-aparna_g-drre | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n<=1) return n;\n vector<int> nums(n+1);\n nums[0] = 0;\n num | aparna_g | NORMAL | 2021-01-15T08:36:03.042882+00:00 | 2021-01-15T08:36:03.042912+00:00 | 180 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n<=1) return n;\n vector<int> nums(n+1);\n nums[0] = 0;\n nums[1] = 1;\n int ans = INT_MIN;\n for(int i=2;i<=n;i++) {\n if(i%2 ==0 )\n nums[i] = nums[i/2];\n else\n ... | 2 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | C++ Super Simple Short Solution 0 ms faster than 100% | c-super-simple-short-solution-0-ms-faste-8dy6 | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if (n == 0 || n == 1) return n;\n \n vector<int> arr(n+1);\n arr | yehudisk | NORMAL | 2021-01-14T21:43:10.541400+00:00 | 2021-01-14T21:43:10.541428+00:00 | 87 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if (n == 0 || n == 1) return n;\n \n vector<int> arr(n+1);\n arr[0] = 0;\n arr[1] = 1;\n int maxi = 1;\n \n for (int i = 2; i <= n; i++) {\n arr[i] = i % 2 == 0 ? arr[i/2] : arr[i / ... | 2 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | Easy and Clear Solution C++ 0ms (100%) | easy-and-clear-solution-c-0ms-100-by-moa-ja5b | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n==0)return 0;\n if(n==1)return 1;\n vector<int>nums;\n nums. | moazmar | NORMAL | 2021-01-07T01:35:05.349983+00:00 | 2021-01-07T01:35:05.350021+00:00 | 160 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n==0)return 0;\n if(n==1)return 1;\n vector<int>nums;\n nums.push_back(0);\n nums.push_back(1);\n int max=1;\n for(int i=2;i<=n;i++){\n if(i%2==0){\n nums.push_back(nums[i... | 2 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | Java 0ms, straight forward solution | java-0ms-straight-forward-solution-by-da-wvob | \npublic int getMaximumGenerated(int n) {\n int[] res = new int[n+1];\n if(n == 0) {\n return 0;\n } else if(n == 1) {\n | DanielYoung | NORMAL | 2020-12-22T05:14:03.371603+00:00 | 2020-12-22T05:14:03.371642+00:00 | 102 | false | ```\npublic int getMaximumGenerated(int n) {\n int[] res = new int[n+1];\n if(n == 0) {\n return 0;\n } else if(n == 1) {\n return 1;\n }\n \n res[0] = 0;\n res[1] = 1;\n int max = 1;\n for(int i = 1; i<=n/2; i++) {\n res[2*... | 2 | 2 | ['Java'] | 0 |
get-maximum-in-generated-array | C# - Brute Force O(N) | c-brute-force-on-by-christris-5i5y | csharp\npublic int GetMaximumGenerated(int n) \n{\n\tint[] result = new int[n + 1];\n\n\tif(n < 2)\n\t{\n\t\treturn n;\n\t}\n\n\tresult[1] = 1;\n\n\tfor(int i = | christris | NORMAL | 2020-11-08T04:04:58.812952+00:00 | 2020-11-08T04:04:58.812998+00:00 | 151 | false | ```csharp\npublic int GetMaximumGenerated(int n) \n{\n\tint[] result = new int[n + 1];\n\n\tif(n < 2)\n\t{\n\t\treturn n;\n\t}\n\n\tresult[1] = 1;\n\n\tfor(int i = 1; 2 * i <= n; i++)\n\t{\n\t\tint next = 2 * i; \n\t\tresult[next] = result[i];\n\n\t\tif(next + 1 <= n)\n\t\t{\n\t\t\tresult[next + 1] = result[i] + result... | 2 | 0 | [] | 0 |
get-maximum-in-generated-array | [Python3] create array as told | python3-create-array-as-told-by-ye15-55mx | \n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if not n: return 0 # edge case \n ans = [0, 1]\n for i in range(2, | ye15 | NORMAL | 2020-11-08T04:02:16.721863+00:00 | 2021-01-15T18:33:55.290867+00:00 | 262 | false | \n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if not n: return 0 # edge case \n ans = [0, 1]\n for i in range(2, n+1): \n ans.append(ans[i>>1] + (ans[i+1>>1] if i&1 else 0))\n return max(ans) \n```\n\nAlternative implementation via funcitons\n```\ncla... | 2 | 0 | ['Python3'] | 1 |
get-maximum-in-generated-array | ⭐️ [ Kt, Js, Py3, Cpp ] 🎯 Max of Generated Array | kt-js-py3-cpp-max-of-generated-array-by-wr9la | Synopsis:\n\nReturn the maximum of the generated array A.\n\n---\n \nContest 214 Screenshare:\n\n\n\nhttps://www.youtube.com/watch?v=xk32NZbA4tM\n \n---\n | claytonjwong | NORMAL | 2020-11-08T04:00:22.519202+00:00 | 2020-11-08T04:16:05.731848+00:00 | 402 | false | **Synopsis:**\n\nReturn the maximum of the generated array `A`.\n\n---\n \n**Contest 214 Screenshare:**\n\n\n\nhttps://www.youtube.com/watch?v=xk32NZbA4tM\n \n---\n\n*Kotlin*\n```\nclass Solution {\n fu... | 2 | 1 | [] | 1 |
get-maximum-in-generated-array | O(n) ☠️ | on-by-varuntyagig-tvu7 | Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | varuntyagig | NORMAL | 2025-02-03T06:18:44.420711+00:00 | 2025-02-03T06:18:44.420711+00:00 | 83 | false | # Complexity
- Time complexity:
$$O(n)$$
- Space complexity:
$$O(1)$$
# Code
```cpp []
class Solution {
public:
int getMaximumGenerated(int n) {
if (n == 0) {
return 0;
}
vector<int> nums(n + 1);
nums[0] = 0;
nums[1] = 1;
for (int i = 1; i < n; i++) {
... | 1 | 0 | ['Array', 'Simulation', 'C++'] | 0 |
get-maximum-in-generated-array | Easy Solution in C | easy-solution-in-c-by-sathurnithy-gy8h | Code | Sathurnithy | NORMAL | 2025-01-19T12:02:32.292861+00:00 | 2025-01-19T12:02:32.292861+00:00 | 63 | false |
# Code
```c []
int getMaximumGenerated(int n) {
if(n == 0) return 0;
if(n == 1) return 1;
int* arr = calloc(n+1, sizeof(int));
arr[1] = 1;
int max = 1;
for(int i=1; 2*i+1 <= n; i++){
arr[2*i] = arr[i];
if(arr[2*i] > max) max = arr[2*i];
arr[2*i+1] = arr[i] + arr[i+1];
... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | Easy Solution in Java | easy-solution-in-java-by-sathurnithy-xy6h | Code | Sathurnithy | NORMAL | 2025-01-19T11:56:32.403252+00:00 | 2025-01-19T11:56:32.403252+00:00 | 110 | false | # Code
```java []
class Solution {
public int getMaximumGenerated(int n) {
if(n == 0) return 0;
if(n == 1) return 1;
int[] nums = new int[n+1];
nums[0] = 0;
nums[1] = 1;
int max = 1;
for (int i = 2; i <= n; i++) {
if (i % 2 == 0) nums[i] ... | 1 | 0 | ['Java'] | 0 |
get-maximum-in-generated-array | EASIST JAVA CODE IN 4-5 LINES BEATING 100% in 0ms | easist-java-code-in-4-5-lines-beating-10-3xd0 | Complexity
Time complexity: O(n)
Space complexity: O(n)
Code | arshi_bansal | NORMAL | 2025-01-17T15:44:21.531248+00:00 | 2025-01-17T15:44:21.531248+00:00 | 71 | false | # Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public int getMaximumGenerated(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
... | 1 | 0 | ['Array', 'Math', 'Java'] | 0 |
get-maximum-in-generated-array | Solution in C | solution-in-c-by-vickyy234-eeyh | Code | vickyy234 | NORMAL | 2025-01-10T19:46:23.198496+00:00 | 2025-01-10T19:46:23.198496+00:00 | 27 | false | # Code
```c []
int getMaximumGenerated(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
int* nums = malloc(sizeof(int) * (n + 1));
nums[1] = 1;
int max = 1;
for (int i = 2; i <= n; i++) {
if (i % 2 == 0)
nums[i] = nums[i / 2];
else
nums[i] = nums[i / ... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | C solution | c-solution-by-pavithrav25-742f | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | pavithrav25 | NORMAL | 2025-01-07T04:35:45.210189+00:00 | 2025-01-07T04:35:45.210189+00:00 | 16 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | Beats 100%. 0ms. Three Lines Only Solution | beats-100-0ms-three-lines-only-solution-dwpfh | IntuitionThe constraints of this problem are small (only 100) and the maximum value returned is only 21. Moreover, all results are increase as n increases. Ther | charnavoki | NORMAL | 2025-01-03T14:50:15.658180+00:00 | 2025-01-03T14:50:15.658180+00:00 | 52 | false | # Intuition
The **constraints** of this problem are small (only **100**) and the maximum value returned is only **21**. Moreover, all results are increase as `n` increases. Therefore, it is very easy to precompute the values and **hard-code** the results. This guarantees the best performance.
```javascript []
var... | 1 | 0 | ['JavaScript'] | 0 |
get-maximum-in-generated-array | Better Runtime using Constructor Working Method ! | better-runtime-using-constructor-working-6x92 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe can pre-generate all possible arrays up to a given size and store them in a list. Th | NamedAdam | NORMAL | 2024-09-14T20:45:57.008479+00:00 | 2024-09-14T20:45:57.008516+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**We can pre-generate all possible arrays up to a given size and store them in a list. This allows us to quickly retrieve the maximum value for a given index in constant time.**\n\n# Approach\n<!-- Describe your approach to solving the pr... | 1 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | arey bhaisahaab n=0 case handle krnaa yaad se :D | arey-bhaisahaab-n0-case-handle-krnaa-yaa-65an | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yesyesem | NORMAL | 2024-09-05T19:07:46.906308+00:00 | 2024-09-05T19:07:46.906340+00:00 | 135 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
get-maximum-in-generated-array | easy understand solution | easy-understand-solution-by-inshhadd-0imb | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | inshhadd | NORMAL | 2024-02-18T09:07:58.826690+00:00 | 2024-02-18T09:07:58.826719+00:00 | 306 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['JavaScript'] | 0 |
get-maximum-in-generated-array | 📈 1646. Get Maximum in Generated Array | 1646-get-maximum-in-generated-array-by-m-tl13 | Intuition\nThe problem follows a simple pattern where each element in the array is generated based on specific rules defined in the problem statement.\n\n# Appr | muqimjon | NORMAL | 2024-02-16T06:54:11.135969+00:00 | 2024-02-16T06:54:11.136008+00:00 | 14 | false | # Intuition\nThe problem follows a simple pattern where each element in the array is generated based on specific rules defined in the problem statement.\n\n# Approach\nTo solve the problem, we can iterate through the range [0, n], generating each element of the array according to the given rules. We maintain a variable... | 1 | 0 | ['C#'] | 0 |
get-maximum-in-generated-array | Simple java code 0 ms beats 100 % | simple-java-code-0-ms-beats-100-by-arobh-fcga | \n# Complexity\n- \n\n# Code\n\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0||n==1) return n;\n int arr[]=new int[n+1] | Arobh | NORMAL | 2024-01-17T14:20:13.996062+00:00 | 2024-01-17T14:20:13.996112+00:00 | 12 | false | \n# Complexity\n- \n\n# Code\n```\nclass Solution {\n public int getMaximumGenerated(int n) {\n if(n==0||n==1) return n;\n int arr[]=new int[n+1];\n arr[0]=0; arr[1]=1;\n int... | 1 | 0 | ['Java'] | 0 |
get-maximum-in-generated-array | get-maximum-in-generated-array | get-maximum-in-generated-array-by-_suraj-4kms | Code\n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = []\n nums.append(0)\n nums.append(1)\n for i in | _suraj__007 | NORMAL | 2023-11-17T05:30:51.744494+00:00 | 2023-11-17T05:30:51.744527+00:00 | 505 | false | # Code\n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n nums = []\n nums.append(0)\n nums.append(1)\n for i in range(2,n+1):\n if i%2==0:\n nums.append(nums[i//2])\n else:\n nums.append(nums[i//2] + nums[(i//2) + 1... | 1 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | easy solution using only one for loop | easy-solution-using-only-one-for-loop-by-3h1s | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | leet1101 | NORMAL | 2023-10-25T09:23:50.000122+00:00 | 2023-10-25T09:23:50.000142+00:00 | 20 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)... | 1 | 0 | ['C++'] | 0 |
get-maximum-in-generated-array | Simplest code with runtime 45 ms | simplest-code-with-runtime-45-ms-by-hris-qw3m | \n\n# Code\n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n dp=[0,1]\n for i in range(2,n+1):\n dp += [dp[i//2] | hrishikeshprasadc | NORMAL | 2023-10-17T08:06:17.648110+00:00 | 2023-10-17T08:06:17.648136+00:00 | 176 | false | \n\n# Code\n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n dp=[0,1]\n for i in range(2,n+1):\n dp += [dp[i//2] if i%2==0 else dp[i//2]+ dp[i//2+1]]\n return max(dp[:n+1])\n``` | 1 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | DP | Python3 | dp-python3-by-joshua_mur-tlfm | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | joshua_mur | NORMAL | 2023-07-31T19:32:08.875273+00:00 | 2023-07-31T19:32:08.875290+00:00 | 52 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n dp = [0] * (n + 2)\n dp[1] = 1 \n ... | 1 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
get-maximum-in-generated-array | Beats 100% | Simple DP solution | beats-100-simple-dp-solution-by-anandsya-twln | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == | anandsyadav257 | NORMAL | 2023-07-10T09:19:48.552713+00:00 | 2023-07-10T09:19:48.552737+00:00 | 6 | false | # Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == 0) return 0;\n if(n == 1) return 1;\n int dp[n+1];\n dp[0] = 0, dp[1] = 1;\n int ans = 1;\n for(int i=2;i<=n;i++)\n ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Simulation', 'C++'] | 0 |
get-maximum-in-generated-array | bottom up approach easiest 9 lines code python | bottom-up-approach-easiest-9-lines-code-ja5f6 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Mohammad_tanveer | NORMAL | 2023-03-18T04:55:54.229024+00:00 | 2023-03-18T04:55:54.229068+00:00 | 931 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python3'] | 0 |
get-maximum-in-generated-array | JavaScript. Easy to understand code. | javascript-easy-to-understand-code-by-ze-fzmv | \n\n# Complexity\n- Time complexity:\nO(n)\n\n# Code\n\n/**\n * @param {number} n\n * @return {number}\n */\nvar getMaximumGenerated = function (n) {\n if (n | ZeemanFactor | NORMAL | 2023-02-12T18:34:05.088139+00:00 | 2023-02-12T18:34:30.923715+00:00 | 82 | false | \n\n# Complexity\n- Time complexity:\nO(n)\n\n# Code\n```\n/**\n * @param {number} n\n * @return {number}\n */\nvar getMaximumGenerated = function (n) {\n if (n == 0) return 0\n if (n == 1) return 1\n var dp = new Array(n + 1).fill(0)\n dp[1] = 1\n for (i = 2; i <= n; i++) {\n if (i % 2 == 0) {\n ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Simulation', 'JavaScript'] | 0 |
get-maximum-in-generated-array | [C++] 1646. Get Maximum in Generated Array | c-1646-get-maximum-in-generated-array-by-tpnk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | pyCERN | NORMAL | 2023-01-27T06:02:52.434691+00:00 | 2023-01-27T06:02:52.434738+00:00 | 125 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 1 |
get-maximum-in-generated-array | Simple Python Solution | simple-python-solution-by-mahmudul-hasan-jh18 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Mahmudul-Hasan-Robin | NORMAL | 2023-01-27T04:09:54.176114+00:00 | 2023-01-27T04:09:54.176150+00:00 | 103 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
get-maximum-in-generated-array | C++ | Short SImple solution | c-short-simple-solution-by-sarthak8008-t8dq | Did as directed !\n\n\nint getMaximumGenerated(int n) {\n // nums[2*i]=nums[i]\n // nums[even=i]=nums[i/2]\n // nums[2*i+1]=nums[i]+nums[i+ | sarthak8008 | NORMAL | 2022-10-11T15:41:54.550398+00:00 | 2022-10-11T17:17:42.216583+00:00 | 7 | false | Did as directed !\n\n```\nint getMaximumGenerated(int n) {\n // nums[2*i]=nums[i]\n // nums[even=i]=nums[i/2]\n // nums[2*i+1]=nums[i]+nums[i+1]\n // nums[odd=i]=nums[i/2]+nums[(i/2)+1]\n if(n==0) return 0;\n if(n==1) return 1;\n vector<int> nums;\n nums.push_back... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | C++ Simple Code Beats 100% in Time and 93% in Space | c-simple-code-beats-100-in-time-and-93-i-aixw | ```\nclass Solution {\npublic:\n int ans=0;\n int recur(int n)\n {\n if(n==0 || n==1)\n return n;\n else if(n%2==0)\n | rishabh2806 | NORMAL | 2022-10-10T14:29:29.406333+00:00 | 2022-10-10T14:29:29.406380+00:00 | 361 | false | ```\nclass Solution {\npublic:\n int ans=0;\n int recur(int n)\n {\n if(n==0 || n==1)\n return n;\n else if(n%2==0)\n ans=recur(n/2);\n else\n ans=recur(n/2)+recur(n/2+1);\n return ans;\n }\n \n int getMaximumGenerated(int n) {\n int ... | 1 | 0 | ['Recursion', 'C++'] | 0 |
get-maximum-in-generated-array | Runtime: 0 ms, faster than 100.00% of C++ online submissions ! | runtime-0-ms-faster-than-10000-of-c-onli-e26f | If you find this helpful, Please Upvote\nThank You !\n\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n if (n == 0 || n == 1) \n | dhairyashiil | NORMAL | 2022-10-02T18:42:44.645833+00:00 | 2022-10-02T18:42:44.645873+00:00 | 1,109 | false | ***If you find this helpful, Please Upvote\nThank You !***\n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n if (n == 0 || n == 1) \n return n;\n \n vector<int> vec(n+1);\n \n vec[0] = 0; // For nums[0] = 0\n vec[1] = 1; // For nums[1] = 1\n ... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | ✔ C++ || Simple DP Solution || Beginner Friendly | c-simple-dp-solution-beginner-friendly-b-wmox | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == 0 || n == 1)\n return n;\n vector<int> nums(n + 1);\n | BharatUpadhyay | NORMAL | 2022-09-10T09:05:00.764676+00:00 | 2022-09-10T09:05:00.764717+00:00 | 356 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n if(n == 0 || n == 1)\n return n;\n vector<int> nums(n + 1);\n nums[0] = 0;\n nums[1] = 1;\n for(int i = 2; i <= n; i++)\n {\n if(i % 2 == 0)\n nums[i] = nums[i/2];\n ... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
get-maximum-in-generated-array | C++ || Easy solution using DP | c-easy-solution-using-dp-by-shodydosh-jkdd | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int nums[n+1];\n int maxVal = 1;\n \n if (n == 1) return 1;\n | Shodydosh | NORMAL | 2022-08-17T01:07:35.184376+00:00 | 2022-08-17T01:07:35.184405+00:00 | 242 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int nums[n+1];\n int maxVal = 1;\n \n if (n == 1) return 1;\n if (n == 0) return 0;\n \n nums[0] = 0;\n nums[1] = 1;\n \n for(int i=0; i<=n; i++){\n if(i%2 == 0){\n ... | 1 | 0 | ['C', 'C++'] | 0 |
get-maximum-in-generated-array | Simple Python Solution | simple-python-solution-by-zip_demons-5fgd | Upvote if the solution if helpful. Comment for any doubts or suggestions.\n\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n < | zip_demons | NORMAL | 2022-08-16T08:08:40.922089+00:00 | 2022-08-16T08:08:40.922121+00:00 | 365 | false | **Upvote if the solution if helpful. Comment for any doubts or suggestions.**\n```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n if n < 2:\n return n\n arr = [0]*(n+1)\n arr[1] = 1\n max_num = 0\n for i in range(2, n+1):\n if i%2 == 0:\n ... | 1 | 0 | ['Python', 'Python3'] | 1 |
get-maximum-in-generated-array | 0ms Faster than 100% Solution in C++, Easy to understand(O(N)) | 0ms-faster-than-100-solution-in-c-easy-t-3d38 | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int>dp(n+1, 0);\n if(n == 0 || n == 1) return n;\n dp[0] = 0;\n | NextThread | NORMAL | 2022-07-28T06:53:41.890903+00:00 | 2022-07-28T06:53:41.890943+00:00 | 37 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int>dp(n+1, 0);\n if(n == 0 || n == 1) return n;\n dp[0] = 0;\n dp[1] = 1;\n for (int i = 2; i <= n; i++)\n dp[i] = i % 2 == 0 ? dp[i/2] : dp[i / 2] + dp[i / 2 + 1];\n return *max_element(d... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
get-maximum-in-generated-array | C++ : Simple Solution | c-simple-solution-by-beast_paw-u1q8 | \nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int mx=INT_MIN;\n if(n==0)\n return 0;\n if(n==1)\n | beast_paw | NORMAL | 2022-07-24T10:40:04.357598+00:00 | 2022-07-24T10:40:04.357636+00:00 | 97 | false | ```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n int mx=INT_MIN;\n if(n==0)\n return 0;\n if(n==1)\n return 1;\n vector<int>nums(n+6);\n nums[0]=0;\n nums[1]=1;\n for(int i=2;i<=n;i++)\n {\n if(i%2==0)\n ... | 1 | 0 | ['C'] | 0 |
get-maximum-in-generated-array | C++ || DP Memoization || 100 % Faster | c-dp-memoization-100-faster-by-vijay_cpp-yz5z | \nclass Solution {\npublic:\n int getMax(int ind, vector<int> &nums, vector<int> &dp)\n {\n \n if(dp[ind] != -1)\n return d | vijay_cpp | NORMAL | 2022-07-21T02:48:22.647527+00:00 | 2022-07-21T03:04:02.829529+00:00 | 120 | false | ```\nclass Solution {\npublic:\n int getMax(int ind, vector<int> &nums, vector<int> &dp)\n {\n \n if(dp[ind] != -1)\n return dp[ind];\n \n if(ind < 0)\n return 0;\n \n if(ind % 2 == 0)\n dp[ind] = getMax(ind / 2, nums, dp);\n ... | 1 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
get-maximum-in-generated-array | c++ || 100 % faster || DP SOLUTION | c-100-faster-dp-solution-by-universal_va-gv9l | class Solution {\npublic:\n\n\n int getMaximumGenerated(int n) {\n if(n==0){\n return 0;\n }\n vector dp(n+1,0);\n dp[ | universal_vaibhav | NORMAL | 2022-07-19T20:52:03.567874+00:00 | 2022-07-19T20:52:37.324661+00:00 | 51 | false | **class Solution {\npublic:**\n\n\n int getMaximumGenerated(int n) {\n if(n==0){\n return 0;\n }\n vector<int> dp(n+1,0);\n dp[0]=0;\n dp[1]=1;\n \n for(int i=2;i<=n;++i){\n if(i&1){\n dp[i]=dp[i/2]+dp[(i/2)+1];\n }\n ... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
get-maximum-in-generated-array | Solution ( 96.51% Faster) | solution-9651-faster-by-fiqbal997-hcrr | \nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n l1 = [0,1]\n if n == 2 or n == 1:\n return (1)\n elif n = | fiqbal997 | NORMAL | 2022-07-12T06:05:31.261130+00:00 | 2022-07-12T06:05:31.261176+00:00 | 273 | false | ```\nclass Solution:\n def getMaximumGenerated(self, n: int) -> int:\n l1 = [0,1]\n if n == 2 or n == 1:\n return (1)\n elif n == 0:\n return (0)\n for i in range(1,n):\n l1.append(l1[i])\n if (i * 2) == n:\n break\n l1... | 1 | 0 | ['Python', 'Python3'] | 0 |
get-maximum-in-generated-array | ✅C++ Solution | c-solution-by-ke4e-ctme | \n\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int> nums(n+1);\n if (n<=1) return n;\n nums[0]=0;\n nu | ke4e | NORMAL | 2022-07-06T12:06:03.720508+00:00 | 2022-07-06T12:06:03.720542+00:00 | 70 | false | \n```\nclass Solution {\npublic:\n int getMaximumGenerated(int n) {\n vector<int> nums(n+1);\n if (n<=1) return n;\n nums[0]=0;\n nums[1]=1;\n for (int i=2; i<=n; i++) {\n if (i%2==0) {\n nums[i]=nums[i/2];\n } else {\n nums[i]=nu... | 1 | 0 | ['C'] | 0 |
minimum-cost-to-reach-every-position | Python3 || 1 line, accumulate || T/S: 99% / 97% | python3-1-line-accumulate-by-spaulding-a5xq | The problem is is equivalent to this problem: For each element in cost, determine the minimum value in costs preceding that element.https://leetcode.com/problem | Spaulding_ | NORMAL | 2025-03-30T04:06:22.388883+00:00 | 2025-04-02T16:36:35.887774+00:00 | 740 | false | The problem is is equivalent to this problem: *For each element in cost, determine the minimum value in costs preceding that element.*
```python3 []
class Solution:
def minCosts(self, cost: List[int]) -> List[int]:
return list(accumulate(cost, min))
```
```cpp []
class Solution {
public:
std::v... | 21 | 0 | ['C++', 'Java', 'Python3'] | 2 |
minimum-cost-to-reach-every-position | ⌚【2-liner】🚀💻✅BEATS 100%⌛⚡[C++/Java/Py3/JS]🍨| EASY n CLEAN EXPLANATION⭕💌 | 2-liner-beats-100cjavapy3js-easy-n-clean-eju9 | IntuitionThe problem requires computing the minimum cost up to each index in the given cost array. Essentially, for each index i, we need to find the minimum va | Fawz-Haaroon | NORMAL | 2025-03-31T09:01:27.755248+00:00 | 2025-04-01T07:32:53.645985+00:00 | 516 | false | # **Intuition**
The problem requires computing the minimum cost up to each index in the given `cost` array. Essentially, for each index `i`, we need to find the minimum value among all elements from the start to `i`.
To achieve this efficiently, we maintain a running minimum while iterating over the array.
# **App... | 11 | 0 | ['Math', 'Simulation', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
minimum-cost-to-reach-every-position | C++ partial_sum 2 lines|beats 100% | c-partial_sum-2-linesbeats-100-by-anwend-l2tj | IntuitionUse prefix sum with operation minApproach
Use partial_sum with lambda function [](int x, int y){return x=min(x, y);}
return cost
Complexity
Time compl | anwendeng | NORMAL | 2025-03-31T05:21:44.114295+00:00 | 2025-03-31T05:21:44.114295+00:00 | 289 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Use prefix sum with operation min
# Approach
<!-- Describe your approach to solving the problem. -->
1. Use `partial_sum` with lambda function `[](int x, int y){return x=min(x, y);}`
2. return `cost`
# Complexity
- Time complexity:
<!-- Ad... | 8 | 0 | ['Prefix Sum', 'C++'] | 1 |
minimum-cost-to-reach-every-position | 100% Beats || Simple Code | 100-beats-simple-code-by-kdhakal-tw3d | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | kdhakal | NORMAL | 2025-04-09T13:20:37.968768+00:00 | 2025-04-09T13:20:37.968768+00:00 | 36 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 3 | 0 | ['Java'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.