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
maximum-number-of-consecutive-values-you-can-make
Thought Process behind the Solution|| C++ || Easy & Clean Code.
thought-process-behind-the-solution-c-ea-6vqc
Approach\nWhy res Starts at 1\nInitial Smallest Missing Number:\n The smallest positive integer is 1. Starting res at 1 means we are initially considering 1
nikk_05
NORMAL
2024-06-16T08:11:40.546512+00:00
2024-06-16T08:11:40.546542+00:00
10
false
# Approach\n***Why res Starts at 1***\nInitial Smallest Missing Number:\n The smallest positive integer is 1. Starting res at 1 means we are initially considering 1 as the smallest integer that we can\'t form with the given coins.\n If we can form 1, we will increment res to 2, meaning we are now considering 2 as...
0
0
['Array', 'Greedy', 'Sorting', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
[C++] Sort then Greedy
c-sort-then-greedy-by-amanmehara-3b5l
Complexity\n- Time complexity: O(nlogn)\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n
amanmehara
NORMAL
2024-06-16T08:11:07.724991+00:00
2024-06-16T08:11:07.725015+00:00
2
false
# Complexity\n- Time complexity: $$O(nlogn)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n sort(coins.begin(), coins.end());\n int curr = 0;\n for (const auto& coin : coins) {\n if (coin > curr + 1) {\n ...
0
0
['Array', 'Greedy', 'Sorting', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
✅99.55% Better than Other C++ Users|| Easy ||Concept Explained...!
9955-better-than-other-c-users-easy-conc-4fj4
Intuition\nWhen you first see this problem, you might think about how you can create a range of consecutive numbers starting from 1 using the given coins. The k
kaditya67
NORMAL
2024-06-16T07:29:24.438811+00:00
2024-06-16T07:29:24.438841+00:00
6
false
### Intuition\nWhen you first see this problem, you might think about how you can create a range of consecutive numbers starting from 1 using the given coins. The key insight here is to use a greedy approach to always use the smallest available coin to extend the range of consecutive numbers you can make. By sorting th...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Simple Greedy
simple-greedy-by-abhimanyu_185724-jdn7
Intuition\nIf we can form all integers from 0 to x using the current elements of the array, and we have a new value v, then we can form all integers from 0 to x
Abhimanyu_185724
NORMAL
2024-06-16T07:19:11.668145+00:00
2024-06-16T07:24:34.603395+00:00
3
false
# Intuition\nIf we can form all integers from 0 to x using the current elements of the array, and we have a new value v, then we can form all integers from 0 to x+v if and only if v\u2264x+1.\nExplanation with an Example\n\nGiven an array [1,1,4], we start with the initial set S={0}:\n\n Step 1: Adding the first ele...
0
0
['Greedy', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
Summing
summing-by-azizkaz-zcod
Intuition\n Describe your first thoughts on how to solve this problem. \nAt first we need to sort the $coins$ array.\nIf we can construct all sums in the range
azizkaz
NORMAL
2024-06-16T06:57:25.494061+00:00
2024-06-16T06:58:00.989191+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAt first we need to sort the $coins$ array.\nIf we can construct all sums in the range $[1, k]$ inclusive, and we have the next number from $coins[i]$, then using this number we can construct all sums in the range $[1, k + coins[i]]$\n\n#...
0
0
['Prefix Sum', 'Rust']
0
maximum-number-of-consecutive-values-you-can-make
C++||Greedy & Sorting
cgreedy-sorting-by-prathmeshr-hlj7
Intuition\nSorting the array which will make easy to check consecutive numbers.\n\nwe will start with tmp = 0 and will check that coins[i] is less or eqaul to t
PrathmeshR
NORMAL
2024-06-16T06:31:48.362560+00:00
2024-06-16T06:31:48.362583+00:00
2
false
# Intuition\nSorting the array which will make easy to check consecutive numbers.\n\nwe will start with tmp = 0 and will check that coins[i] is less or eqaul to tmp + 1.\n\ntmp represent upto which number we are able to make series of consecutive numbers.\n\nif coins[i] is greater than tmp + 1 means some number is miss...
0
0
['Greedy', 'Sorting', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
easy cpp soln
easy-cpp-soln-by-pratima-bakshi-60xb
Complexity\n- Time complexity:\n O(NLogN)\n\n- Space complexity:\n O(1)\n\n# Code\n\nclass Solution {\npublic:\n \n int getMaximumConsecutive(vector
Pratima-Bakshi
NORMAL
2024-06-16T05:59:19.305882+00:00
2024-06-16T05:59:19.305907+00:00
1
false
# Complexity\n- Time complexity:\n O(NLogN)\n\n- Space complexity:\n O(1)\n\n# Code\n```\nclass Solution {\npublic:\n \n int getMaximumConsecutive(vector<int>& coins) \n {\n long long sum = 0;\n int i =0;\n sort(coins.begin(),coins.end());\n while(sum<=1e10)\n {\n ...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Easy to understand C++ solution, beats 96% in time and 79% in space.
easy-to-understand-c-solution-beats-96-i-rfmc
\nPlease upvote if u find this useful <3\n\n# Intuition\n- If we can make first x values and we have a value y, we can make all the values that <= x+y and >=y\n
notisora
NORMAL
2024-06-16T05:08:01.522662+00:00
2024-06-16T05:08:01.522684+00:00
5
false
![image.png](https://assets.leetcode.com/users/images/c9c9c886-21a0-4681-8f98-5ec4767cf832_1718514185.398779.png)\n**Please upvote if u find this useful <3**\n\n# Intuition\n- If we can make first x values and we have a value y, we can make all the values that <= x+y and >=y\n- => X would start at 0 and if x <=coins[i]...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Fastest and Easiest solution in python🔥
fastest-and-easiest-solution-in-python-b-umld
\n\n\n\n# Approach\nAnswer lies in the hint:\nIf you can make the first x values and you have a value v, then you can make all the values \u2264 v + x\n\nThe co
avoynath2005
NORMAL
2024-06-16T01:57:18.088538+00:00
2024-06-16T01:57:18.088565+00:00
35
false
\n![Screenshot 2024-06-16 072521.png](https://assets.leetcode.com/users/images/bb81f3c1-3c3a-46d1-bef6-4204c84ec3ed_1718502962.7985275.png)\n\n\n# Approach\nAnswer lies in the hint:\nIf you can make the first x values and you have a value v, then you can make all the values \u2264 v + x\n\nThe code is self explainatory...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
Set - TLE
set-tle-by-wangcai20-01if
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
wangcai20
NORMAL
2024-05-18T16:15:22.764051+00:00
2024-05-18T16:15:22.764082+00:00
14
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)$$ --...
0
0
['Java']
0
maximum-number-of-consecutive-values-you-can-make
simple maths || easy to understand || o(N) time && o(1) space ||
simple-maths-easy-to-understand-on-time-14yxm
Code\n\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n \n //if i dont take anything that will sum to 0\n
akshat0610
NORMAL
2024-05-14T09:39:53.686019+00:00
2024-05-14T09:39:53.686048+00:00
11
false
# Code\n```\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n \n //if i dont take anything that will sum to 0\n int maxVal = 0;\n sort(coins.begin(),coins.end());\n for(int i = 0 ; i < coins.size() ; i++){\n //we cannot add the coin...
0
0
['Array', 'Greedy', 'Sorting', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
Easy JS with O(nlogn) time complexity
easy-js-with-onlogn-time-complexity-by-m-3j3z
Complexity\n- Time complexity: O(nlogn)\n- Space complexity: O(n)\n\n# Idea\nJust check: if any coins[i] > sum(coins, i - 1) + 1 THEN cannot find elements with
Maduro29
NORMAL
2024-04-20T07:37:01.518378+00:00
2024-04-20T07:37:01.518408+00:00
4
false
# Complexity\n- Time complexity: O(nlogn)\n- Space complexity: O(n)\n\n# Idea\nJust check: if any coins[i] > sum(coins, i - 1) + 1 THEN cannot find elements with sum coins[i] - 1\n\n# Code\n```\n/**\n * @param {number[]} coins\n * @return {number}\n */\nvar getMaximumConsecutive = function(coins) {\n coins.sort((a, b)...
0
0
['JavaScript']
0
maximum-number-of-consecutive-values-you-can-make
Straightforward Python
straightforward-python-by-jabezng2-dwje
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
Jabezng2
NORMAL
2024-04-12T14:12:52.498476+00:00
2024-04-12T14:12:52.498508+00:00
30
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)$$ --...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
Shortest, Easiest, Clean & Clear | To the Point & Beginners Friendly Approach (❤️ ω ❤️)
shortest-easiest-clean-clear-to-the-poin-gc90
Code\n\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n int x=1;\n sort(coins.begin(),coins.end());\n for(
Nitansh_Koshta
NORMAL
2024-04-10T13:06:52.370480+00:00
2024-04-10T13:06:52.370516+00:00
3
false
# Code\n```\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n int x=1;\n sort(coins.begin(),coins.end());\n for(auto i:coins){\n if(i<=x)x+=i;\n else break;\n }\n return x;\n\n// if you like my approach then please UpVOTE o((>\u03...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Python (Simple Greedy)
python-simple-greedy-by-rnotappl-19tc
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
rnotappl
NORMAL
2024-03-17T16:27:50.299381+00:00
2024-03-17T16:27:50.299414+00:00
26
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)$$ --...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
JS || Solution by Bharadwaj
js-solution-by-bharadwaj-by-manu-bharadw-eqxw
Code\n\nvar getMaximumConsecutive = function (coins) {\n coins.sort((a, b) => a - b);\n let count = 0;\n for (let coin of coins) {\n if (coin <=
Manu-Bharadwaj-BN
NORMAL
2024-03-02T04:58:14.268094+00:00
2024-03-02T04:58:14.268160+00:00
32
false
# Code\n```\nvar getMaximumConsecutive = function (coins) {\n coins.sort((a, b) => a - b);\n let count = 0;\n for (let coin of coins) {\n if (coin <= count + 1) {\n count += coin;\n }\n }\n return count + 1;\n};\n```
0
0
['JavaScript']
1
maximum-number-of-consecutive-values-you-can-make
1798. Maximum Number of Consecutive Values You Can Make
1798-maximum-number-of-consecutive-value-scp9
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nPure math\n\n\ncoin value is <= sum+1\n\n\n\n# Complexity\n- Time complex
pgmreddy
NORMAL
2024-02-26T14:56:30.296918+00:00
2024-02-26T14:56:30.296953+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nPure math\n\n`\ncoin value is <= sum+1\n`\n\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)$$ -->\n\n# Code\...
0
0
['JavaScript']
0
maximum-number-of-consecutive-values-you-can-make
submission beats 100% of other submissions' runtime.
submission-beats-100-of-other-submission-6471
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
PriyanshuNiranjan
NORMAL
2024-02-16T14:07:43.151357+00:00
2024-02-16T14:07:43.151386+00:00
31
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)$$ --...
0
0
['Java']
0
maximum-number-of-consecutive-values-you-can-make
consecutive
consecutive-by-aman_17000s-6wg2
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
aman_17000s
NORMAL
2024-02-06T07:45:22.317299+00:00
2024-02-06T07:45:22.317320+00:00
3
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)$$ --...
0
0
['Greedy', 'Sorting', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
greedy
greedy-by-ns7653900-n79u
\n\n# Code\n\nclass Solution:\n def getMaximumConsecutive(self, coins: List[int]) -> int:\n coins.sort()\n ans=0\n tot=0\n for i
ns7653900
NORMAL
2024-01-24T05:16:29.714569+00:00
2024-01-24T05:16:29.714602+00:00
23
false
\n\n# Code\n```\nclass Solution:\n def getMaximumConsecutive(self, coins: List[int]) -> int:\n coins.sort()\n ans=0\n tot=0\n for i in range(len(coins)):\n if tot-coins[i]>=-1:\n tot+=coins[i]\n ans=tot\n else:\n break\n ...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
same as patching array||c++||ditto same as patching array
same-as-patching-arraycditto-same-as-pat-tcll
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
kartik_pandey07
NORMAL
2024-01-19T16:39:40.481528+00:00
2024-01-19T16:39:40.481567+00:00
5
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)$$ --...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
🔥🔥🔥easy to understand [JAVA]
easy-to-understand-java-by-chakribontha9-3ta0
maximum number we can make == minimum number we can\'t make from array\nhow we can find minimum number ???\nAns:-SORT ARRAY\nwhy sort?? \nAns:-[[2] 1 5]]\nminel
chakribontha9
NORMAL
2024-01-04T10:35:29.744623+00:00
2024-01-04T10:35:29.744653+00:00
20
false
**maximum number we can make == minimum number we can\'t make from array**\nhow we can find minimum number ???\nAns:-SORT ARRAY\nwhy sort?? \nAns:-[[2] 1 5]]\nminele=1\nminele is 1 first ele is greater than minele --itsfailed\nexample [ 1 3 ]\n [1 **[2]** 3] \n\n```\nclass Solution {\n public int getMaximumConse...
0
0
['Greedy', 'Java']
0
maximum-number-of-consecutive-values-you-can-make
merge sort
merge-sort-by-a36466136-t873
Intuition\n Describe your first thoughts on how to solve this problem. \nmerge sort\n# Approach\n Describe your approach to solving the problem. \n\n# Complexit
a36466136
NORMAL
2023-12-14T02:24:33.545701+00:00
2023-12-14T02:24:33.545754+00:00
21
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nmerge sort\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)$$ -->\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity he...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
Simple C++ Solution
simple-c-solution-by-ikharabhishek-4lus
Intuition\n# There is 1 observation here. so if we find the consecutive sequence till "x" then if we have new interger let say "val" then we can obtained a cons
ikharabhishek
NORMAL
2023-12-05T07:16:25.862230+00:00
2023-12-05T07:16:25.862259+00:00
8
false
# Intuition\n# **There is 1 observation here. so if we find the consecutive sequence till "x" then if we have new interger let say "val" then we can obtained a consecutive sequence from 0 ... val+x . But only case when it is not possible is when x+1 < val.**\n\n# Approach\n1. Sort the coins array.\n2. Initialize the a...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Python greedy with sorting with explanation (330 and 2952 variant)
python-greedy-with-sorting-with-explanat-h6mm
Intuition\n Describe your first thoughts on how to solve this problem. \n1. Initialize res = 1 since we count from 0;\n2. Sort coins;\n3. For each coin in coins
nanzhuangdalao
NORMAL
2023-12-03T22:00:58.698420+00:00
2023-12-03T22:06:02.800181+00:00
20
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Initialize res = 1 since we count from 0;\n2. Sort coins;\n3. For each coin in coins:\n - if coin > res, then the consecutive values cannot expand to the right;\n - if coin == res, then the consecutive values can be just perfectly ex...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
[Rust] Sort + Greedy value coverage extension
rust-sort-greedy-value-coverage-extensio-pdq9
Intuition\nThe intuition behind solving this problem is based on the realization that if we can create every sum up to a certain value with the given coins, the
phi9t
NORMAL
2023-12-03T19:48:20.977176+00:00
2023-12-03T19:48:20.977204+00:00
2
false
# Intuition\nThe intuition behind solving this problem is based on the realization that if we can create every sum up to a certain value with the given coins, then any additional coin can only increase or maintain this range. The key lies in identifying the smallest value that we cannot attain. Since the coins don\'t n...
0
0
['Rust']
0
maximum-number-of-consecutive-values-you-can-make
Easy JavaScript Solution
easy-javascript-solution-by-surajkales11-kp4u
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
surajkales111
NORMAL
2023-12-03T05:21:26.610960+00:00
2023-12-03T05:21:26.610988+00:00
5
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)$$ --...
0
0
['JavaScript']
0
maximum-number-of-consecutive-values-you-can-make
Easy to understand JavaScript solution (Greedy)
easy-to-understand-javascript-solution-g-ak46
Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n\nvar getMaximumConsecutive = function(coins) {\n let result = 1;\n\n coi
tzuyi0817
NORMAL
2023-11-09T02:55:16.152681+00:00
2023-11-09T02:55:16.152717+00:00
5
false
# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nvar getMaximumConsecutive = function(coins) {\n let result = 1;\n\n coins.sort((a, b) => a - b);\n\n for (const coin of coins) {\n if (coin > result) return result;\n result += coin;\n }\n return...
0
0
['JavaScript']
0
maximum-number-of-consecutive-values-you-can-make
C# Solution Using Concatenation
c-solution-using-concatenation-by-jack00-5pur
Intuition\n\n\n# Approach\nassume we have found [0..biggest], in order for the consecutive, the next coin value have to be <=biggest+1, if that satisfies, we ca
jack0001
NORMAL
2023-10-07T17:32:36.351034+00:00
2023-10-07T17:32:36.351072+00:00
6
false
# Intuition\n\n\n# Approach\nassume we have found [0..biggest], in order for the consecutive, the next coin value have to be <=biggest+1, if that satisfies, we can concatenate the smallest we found and the biggest would be this coin value plus "biggest" we found before.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n...
0
0
['C#']
0
maximum-number-of-consecutive-values-you-can-make
Easiest C++ Solution...
easiest-c-solution-by-parthbansal2047-6u7b
\n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \
parthbansal2047
NORMAL
2023-09-17T20:44:58.784884+00:00
2023-09-17T20:44:58.784911+00:00
13
false
\n\n# Complexity\n- Time complexity: *O(n)*\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: *O(1)*\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int getMaximumConsecutive(vector<int>& coins) {\n int ans=0;\n sort(coins...
0
0
['Array', 'Greedy', 'C++']
0
maximum-number-of-consecutive-values-you-can-make
C++/Python, greedy solution with explanation
cpython-greedy-solution-with-explanation-brrw
sort coins first.\n[0, m] are coin we can construct.\n\nand current coin is c,\nso if we use current coin c, we can construct m + c at most.\n\nand if current c
shun6096tw
NORMAL
2023-08-30T08:50:36.639222+00:00
2023-08-30T08:50:36.639240+00:00
27
false
sort coins first.\n[0, m] are coin we can construct.\n\nand current coin is c,\nso if we use current coin c, we can construct m + c at most.\n\nand if current coin c > m + 1,\nthere is no way to construct m + 1 because other coins after conic c >= c.\n\ntc is O(nlogn), sc is O(1).\n### python\n```python\nclass Solution...
0
0
['Greedy', 'C', 'Sorting', 'Python']
0
maximum-number-of-consecutive-values-you-can-make
Fast solution O(N*logN) time and O(1) space
fast-solution-onlogn-time-and-o1-space-b-2pdy
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
devvikram34
NORMAL
2023-08-20T16:27:43.336513+00:00
2023-08-20T16:28:28.228057+00:00
16
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*log N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e....
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Maximum Number of Consecutive Values You Can Make solve with python
maximum-number-of-consecutive-values-you-l4qc
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
suryasoto45
NORMAL
2023-06-10T15:51:18.541197+00:00
2023-06-10T15:51:18.541232+00:00
74
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)$$ --...
0
0
['Python3']
0
maximum-number-of-consecutive-values-you-can-make
C++ | O(nlogn) + O(n)
c-onlogn-on-by-seekerm-0xen
Intuition\nFirst sort the elements. Why ??\nFor e.g. coins = [1,1,1,4]. Here the numbers less than 4 can only be generated by elements in the coins array with v
SeekerM
NORMAL
2023-05-12T10:51:08.281129+00:00
2023-05-12T10:51:08.281177+00:00
51
false
# Intuition\nFirst sort the elements. Why ??\nFor e.g. coins = [1,1,1,4]. Here the numbers less than 4 can only be generated by elements in the coins array with value less than 4. There to generate the numbers starting from 1 to ... we need coins to be sorted order.\n\nExplanation for: \n if(x <= rv+1)rv += x;\n ...
0
0
['C++']
0
maximum-number-of-consecutive-values-you-can-make
Rust solution!
rust-solution-by-zhoutianyi0805-hl7i
Newbie in rust, any suggestion welcome\n# Code\n\n\nimpl Solution {\n pub fn get_maximum_consecutive(coins: Vec<i32>) -> i32 {\n let mut c = coins.clone
zhoutianyi0805
NORMAL
2023-05-05T22:38:59.927987+00:00
2023-05-05T22:38:59.928019+00:00
24
false
Newbie in rust, any suggestion welcome\n# Code\n```\n\nimpl Solution {\n pub fn get_maximum_consecutive(coins: Vec<i32>) -> i32 {\n let mut c = coins.clone();\n c.sort();\n let mut res = 0;\n let mut ans = c.iter()\n .try_fold(0, |accum, &val| {\n if accum < val - 1 {\n re...
0
0
['Rust']
0
minimum-swaps-to-make-sequences-increasing
Java O(n) DP Solution
java-on-dp-solution-by-wangzi6147-7dws
swapRecord means for the ith element in A and B, the minimum swaps if we swap A[i] and B[i]\nfixRecord means for the ith element in A and B, the minimum swaps i
wangzi6147
NORMAL
2018-03-19T04:20:01.859505+00:00
2018-10-21T05:49:21.762728+00:00
35,253
false
```swapRecord``` means for the ith element in A and B, the minimum swaps if we swap ```A[i]``` and ```B[i]```\n```fixRecord``` means for the ith element in A and B, the minimum swaps if we DONOT swap ```A[i]``` and ```B[i]```\n```\nclass Solution {\n public int minSwap(int[] A, int[] B) {\n int swapRecord = 1...
408
7
[]
42
minimum-swaps-to-make-sequences-increasing
[Java/C++/Python] DP O(N) Solution
javacpython-dp-on-solution-by-lee215-xrdk
Explanation\nswap[n] means the minimum swaps to make the A[i] and B[i] sequences increasing for 0 <= i <= n,\nin condition that we swap A[n] and B[n]\nnot_swap[
lee215
NORMAL
2018-03-19T08:27:53.829176+00:00
2020-11-29T10:23:48.824046+00:00
32,570
false
# **Explanation**\n```swap[n]``` means the minimum swaps to make the ```A[i]``` and ```B[i]``` sequences increasing for ```0 <= i <= n```,\nin condition that we swap ```A[n]``` and ```B[n]```\n```not_swap[n]``` is the same with ```A[n]``` and ```B[n]``` not swapped.\n\n@Acker help explain:\n1. `A[i - 1] < A[i] && B[i -...
317
3
[]
36
minimum-swaps-to-make-sequences-increasing
Bottom-up DP with Optimization (Java / Python)
bottom-up-dp-with-optimization-java-pyth-82kn
state\t\nwhether we swap the element at index i to make A[0..i] and B[0..i] both increasing can uniquely identify a\xA0state, i.e. a node in the state graph.\n
gracemeng
NORMAL
2018-08-21T01:59:58.096686+00:00
2018-10-17T19:14:32.933059+00:00
8,992
false
**state**\t\nwhether we swap the element at index i to make A[0..i] and B[0..i] both increasing can uniquely identify a\xA0state, i.e. a node in the state graph.\n**state function**\t\n`state(i, 0)`\xA0is the minimum swaps to make A[0..i] and B[0..i] both increasing if we donot swap A[i] with B[i]\n`state(i, 1)`\xA0is...
275
0
[]
21
minimum-swaps-to-make-sequences-increasing
Recursive with memoization (beats 100.00 %):
recursive-with-memoization-beats-10000-b-eob0
\nclass Solution { \n\n int[][] dp;\n \n public int minSwap(int[] A, int[] B) {\n dp = new int[A.length][2];\n for (int[] row: dp)\n
yogi_bear
NORMAL
2019-03-26T06:16:30.430676+00:00
2020-04-12T20:26:10.015676+00:00
7,320
false
```\nclass Solution { \n\n int[][] dp;\n \n public int minSwap(int[] A, int[] B) {\n dp = new int[A.length][2];\n for (int[] row: dp)\n Arrays.fill(row, -1);\n return minSwapHelper(A, B, 0, -1, -1, 0);\n }\n \n private int minSwapHelper(int[] A, int[] B, int i, int p...
106
0
[]
17
minimum-swaps-to-make-sequences-increasing
Python 14-line O(1) space O(n) time DP solution
python-14-line-o1-space-on-time-dp-solut-mo7d
This problem can be solved using dynamic programming, at each position, we can choose to swap or not. Since we want two sorted arrays, at each position, whether
luckypants
NORMAL
2018-03-19T03:45:50.604272+00:00
2018-10-21T05:21:55.360369+00:00
7,910
false
This problem can be solved using dynamic programming, at each position, we can choose to swap or not. Since we want two sorted arrays, at each position, whether to swap or not depends on the choice at previous position, so we can form a recursive formula.\n\n```\nN = len(A)\ndp = [[maxint]*2 for _ in range(N)]\n```\n\n...
70
1
[]
17
minimum-swaps-to-make-sequences-increasing
C++ solution with explanation
c-solution-with-explanation-by-snorlaxny-sbvq
Here let me rephrase the solution by @lee215.\n\nhttps://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/119879/Easy-Understood-DP-Solu
snorlaxnyc
NORMAL
2018-03-24T03:17:45.497684+00:00
2018-09-19T07:19:21.100653+00:00
5,663
false
Here let me rephrase the solution by @lee215.\n\nhttps://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/119879/Easy-Understood-DP-Solution-C++JavaPython\n\nThis problem can be solved using dynamic programming, at each position, we can choose to swap or not. Since we want two sorted arrays, at ...
54
3
[]
5
minimum-swaps-to-make-sequences-increasing
FULLY EXPLAINED SOLUTION FOR BEGINNER . ( Recursion+Memoization)
fully-explained-solution-for-beginner-re-bqwb
The basic idea behind this problem is same what we uses in 0 1 knapsack.\nSo what is the idea in 0 1 knapsack. The idea is that we provide some condition during
rahul_81
NORMAL
2022-03-14T18:17:21.203731+00:00
2023-03-13T06:08:09.881085+00:00
2,952
false
The basic idea behind this problem is same what we uses in 0 1 knapsack.\nSo what is the idea in **0 1 knapsack**. The idea is that we provide some condition during function call, and if condition is satisfied then we have two options (i,e) either include the current element or do not include the current element.But if...
45
0
['Java']
4
minimum-swaps-to-make-sequences-increasing
Super Intuitive solution(recursive + memoization)
super-intuitive-solutionrecursive-memoiz-7qw0
\nclass Solution {\n public int minSwap(int[] A, int[] B) {\n Integer[][] dp = new Integer[A.length][2];//0 no swap, 1:swap\n\n return dfs(
job
NORMAL
2018-11-11T17:57:15.734051+00:00
2018-11-11T17:57:15.734091+00:00
3,265
false
```\nclass Solution {\n public int minSwap(int[] A, int[] B) {\n Integer[][] dp = new Integer[A.length][2];//0 no swap, 1:swap\n\n return dfs(A,B,0,dp,0);\n }\n public int dfs(int[] A,int[] B, int i,Integer[][] dp,int swap){\n\n if(i==A.length){\n return 0;\n ...
40
2
[]
3
minimum-swaps-to-make-sequences-increasing
Java DP 2ms solution with comments
java-dp-2ms-solution-with-comments-by-ar-64kq
\npublic int minSwap(int[] A, int[] B) {\n int n = A.length;\n int not_swap[] = new int[n]; \n //not_swap[i] -> min swaps to make {A[0]~A[i
arjun_sharma
NORMAL
2019-04-07T21:41:19.287307+00:00
2019-04-07T21:41:19.287374+00:00
2,385
false
```\npublic int minSwap(int[] A, int[] B) {\n int n = A.length;\n int not_swap[] = new int[n]; \n //not_swap[i] -> min swaps to make {A[0]~A[i]} and {B[0]~B[i]} without swapping A[i] and B[i]\n int swap[] = new int[n];\n //swap[i] -> min swaps to make {A[0]~A[i]} and {B[0]~B[i]} with ...
32
1
[]
7
minimum-swaps-to-make-sequences-increasing
From Recursion to DP (4 Solutions) [Java]
from-recursion-to-dp-4-solutions-java-by-jywc
Approach\nThere are two states possible,\n1. Don\'t swap elements at the current index\n2. Swap elements at the current index\n\nWe just have to find out which
redocsuomynona
NORMAL
2021-06-16T19:41:37.592879+00:00
2021-06-16T19:41:37.592915+00:00
2,495
false
**Approach**\nThere are two states possible,\n1. Don\'t swap elements at the current index\n2. Swap elements at the current index\n\nWe just have to find out which one gives the minimum number of swaps for the rest of the array. That is, we will compute answer for both the states. The answer for the current state is de...
31
0
['Dynamic Programming', 'Recursion', 'Java']
1
minimum-swaps-to-make-sequences-increasing
Java neat and easy to understand DP O(n) solution!
java-neat-and-easy-to-understand-dp-on-s-9np2
We create a dp[n][2] array. dp[i][0] means the minimun swaps when we do not swap in position i, while dp[i][1] means otherwise.\n\nBasically, there are three ca
kylewzk
NORMAL
2018-03-20T07:11:09.824075+00:00
2018-09-27T02:07:46.355571+00:00
3,079
false
We create a dp[n][2] array. dp[i][0] means the minimun swaps when we do not swap in position i, while dp[i][1] means otherwise.\n\nBasically, there are three cases:\na) We either swap or not in position i for condition: A[i]>A[i-1] && A[i]>B[i-1] && B[i] > A[i-1] && B[i] > B[i-1].\nb) If i-1 swaps, i swaps. If i-1 does...
31
0
[]
6
minimum-swaps-to-make-sequences-increasing
[Python] DP solution with explanations
python-dp-solution-with-explanations-by-k33wf
Explanations: For each i, we can either swap or keep the two respective value. Since the best options can come from either swap or keep as well, we need to have
codingasiangirll
NORMAL
2020-05-19T16:05:22.748574+00:00
2020-05-19T18:14:38.356542+00:00
951
false
**Explanations**: For each `i`, we can either swap or keep the two respective value. Since the best options can come from either swap or keep as well, we need to have 2 array to record two actions at each `i`. Here, `dp[0][:]` will record keep and `dp[1][:]` will record swap. \nFor `dp[0][i]`, number of swaps needed, i...
19
0
['Dynamic Programming']
1
minimum-swaps-to-make-sequences-increasing
[C++/Java/Python] Simple DP O(n) Time O(1) Space with Explanation
cjavapython-simple-dp-on-time-o1-space-w-q3ex
Explanation\n\nThis problem relies on the fact that it is possible for both nums1 and nums2 to be strictly increasing in the end. Since we can only perform swap
zayne-siew
NORMAL
2021-11-07T11:53:11.114942+00:00
2021-11-07T11:54:35.252004+00:00
1,631
false
### Explanation\n\nThis problem relies on the fact that it is possible for both `nums1` and `nums2` to be strictly increasing in the end. Since we can only perform swaps between elements with the same index, i.e. we can only swap `nums1[i]` with `nums2[i]` for `0 <= i < n` (where `n` is the length of the arrays), we ca...
15
0
['Dynamic Programming', 'Python', 'C++', 'Java']
2
minimum-swaps-to-make-sequences-increasing
Clear Python o(n) Time, o(n) Space solution with comments
clear-python-on-time-on-space-solution-w-2xtx
bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n\nclass Solution:\n def minSwap(self, A: List[int], B: List[int]) -> int:\n
ay6xp123
NORMAL
2020-02-02T17:38:54.607061+00:00
2020-02-02T17:38:54.607111+00:00
936
false
bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n```\nclass Solution:\n def minSwap(self, A: List[int], B: List[int]) -> int:\n \n n = len(A)\n \n # In this problem, we have two states that we need to keep track at element i; \n # what happens if we swap o...
15
1
['Dynamic Programming', 'Python3']
3
minimum-swaps-to-make-sequences-increasing
C++, Time O(n), Space O(1), 4ms, beats 100%
c-time-on-space-o1-4ms-beats-100-by-pjin-nmtq
If A[i] > B[i], we say, we have a upward node, elsewise we have a downward note.\n\nIf a node max(A[i],B[i]) < min(A[i+1],B[i+1]), we name it a free node.\nBeca
pjincz
NORMAL
2018-11-17T01:04:03.217804+00:00
2018-11-17T01:04:03.217862+00:00
1,139
false
If A[i] > B[i], we say, we have a upward node, elsewise we have a downward note.\n\nIf a node max(A[i],B[i]) < min(A[i+1],B[i+1]), we name it a free node.\nBecause it can changed freely.\nOtherwise, a non-free node should have same direction with next node.\n\nSo, we find a chain, left of first node is a free node, end...
15
0
[]
2
minimum-swaps-to-make-sequences-increasing
DP Simple O(n) time O(1) Space with detailed explanation
dp-simple-on-time-o1-space-with-detailed-tw3d
Think of the problem as finding the best path from n-1th index to nth index\nSuppose Array \n A=[0,7,8,10,10,11,12,13,19,18] and\n\t B=[4,4,5, 7,11,1
prajwalroxman
NORMAL
2019-06-29T08:10:08.637306+00:00
2019-06-29T08:40:49.042877+00:00
1,218
false
Think of the problem as finding the best path from n-1th index to nth index\nSuppose Array \n A=[0,7,8,10,10,11,12,13,19,18] and\n\t B=[4,4,5, 7,11,14,15,16,17,20]\n\t\t\t\t\t\t\t\t\t\t\t ^\nInitially,\t\t\t\t\t\t\t\t\t\t\t \nswap =[0,0,0,0,0,0,0,0,0,1]\nunswap=[0,0,0,0,0,0,0,0,0,0]\n\t\t\t\t\t\t\...
14
0
[]
2
minimum-swaps-to-make-sequences-increasing
✅✅Faster || Easy To Understand || C++ Code
faster-easy-to-understand-c-code-by-__kr-wrql
Approach 1 :- Using Recursion && Memoization\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n \n int dp[100005][2
__KR_SHANU_IITG
NORMAL
2022-07-04T07:40:21.185771+00:00
2022-07-04T07:40:21.185843+00:00
1,085
false
* ***Approach 1 :- Using Recursion && Memoization***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n \n int dp[100005][2];\n \n int dfs(vector<int>& nums1, vector<int>& nums2, int i, int n, int prev1, int prev2, bool swap)\n {\n if(i == n)...
12
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C']
1
minimum-swaps-to-make-sequences-increasing
C++: Solution with explanation
c-solution-with-explanation-by-bingabid-y8ah
To make both array strictly increasing till \'i\' index, there is two possibility\n\n1. we do not swap the \'i\' elements.\n2. we swap the \'i\' elements.\n\nMi
bingabid
NORMAL
2020-06-10T11:11:28.283212+00:00
2020-06-10T11:13:01.296999+00:00
884
false
To make both array strictly increasing till \'i\' index, there is two possibility\n```\n1. we do not swap the \'i\' elements.\n2. we swap the \'i\' elements.\n\nMinimum of the above two possibility is the minimum number of swap needed \nto make both the array strictly increasing till \'i\' index.\n```\n\nlet \'n\' is t...
11
0
[]
1
minimum-swaps-to-make-sequences-increasing
💥 Runtime beats 100.00%, Memory beats 66.67% [EXPLAINED]
runtime-beats-10000-memory-beats-6667-ex-apig
Intuition\nImagine you\'re trying to make two sequences of numbers strictly increasing. You have two arrays, nums1 and nums2, and you can swap elements at the s
r9n
NORMAL
2024-09-06T16:55:59.090570+00:00
2024-09-06T16:55:59.090595+00:00
220
false
# Intuition\nImagine you\'re trying to make two sequences of numbers strictly increasing. You have two arrays, nums1 and nums2, and you can swap elements at the same index between these arrays. Your goal is to find the minimum number of swaps required to make both arrays strictly increasing.\n\nThink of it like organiz...
9
0
['TypeScript']
1
minimum-swaps-to-make-sequences-increasing
C++ Easy and simple solution Recrusive->TopDown->BottomUp
c-easy-and-simple-solution-recrusive-top-bcpn
Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\n\nTh
ayushluthra62
NORMAL
2022-10-12T13:48:31.251289+00:00
2022-10-12T13:48:31.251335+00:00
1,064
false
**Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F**\n\n**There are Different method to solve This question**. \n* **Recursive (TLE)**\n* **Recursive** + **Dp** (Accepted) \n* **Bottom Up (DP)** (Accepted) \n\n**A...
9
1
['Recursion', 'C', 'C++']
2
minimum-swaps-to-make-sequences-increasing
[Python3] two counters
python3-two-counters-by-ye15-s24v
Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of A[i] and B[i] to A and smaller of A[i
ye15
NORMAL
2020-11-11T22:30:06.699064+00:00
2020-11-11T22:30:06.699107+00:00
710
false
Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of `A[i]` and `B[i]` to `A` and smaller of `A[i]` and `B[i]` to `B`. The resulting sequence satisfies the requirement of increasing `A` and increasing `B`. In the spirit of this idea, we can count the...
9
0
['Python3']
1
minimum-swaps-to-make-sequences-increasing
4 Approaches || Recursion || Memoization || Tabulation || Space Optimization ( O(1) ) || Beats 100%
4-approaches-recursion-memoization-tabul-cxvh
Approach 1: Recursive Approach\n Describe your approach to solving the problem. \n- The function solve uses recursion to explore all possibilities at each index
prayashbhuria931
NORMAL
2024-08-29T19:59:51.024040+00:00
2024-08-29T19:59:51.024072+00:00
419
false
# Approach 1: Recursive Approach\n<!-- Describe your approach to solving the problem. -->\n- The function solve uses recursion to explore all possibilities at each index in the sequences.\n- Parameters:\n - nums1 and nums2: The input sequences.\n - index: The current index being processed.\n - swapped: A boolean fla...
8
0
['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++']
1
minimum-swaps-to-make-sequences-increasing
99.51 % Faster Runtime ✅✅ || Recursive + Memoization || Easy to Understand
9951-faster-runtime-recursive-memoizatio-pz9b
Recursively go to every index and check possibility for swapping\n Describe your first thoughts on how to solve this problem. \n\n# Approach : \n> 1.) If we are
unknown_ajay
NORMAL
2023-07-07T05:10:41.470478+00:00
2023-07-07T05:11:40.701639+00:00
1,370
false
# Recursively go to every index and check possibility for swapping\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach : \n> 1.) If we are at index Zero we can either swap it or not because zero does not have any previous index \n2.) Calculate previous index\'s value for both the vectors ...
8
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']
0
minimum-swaps-to-make-sequences-increasing
Python recursion with cache
python-recursion-with-cache-by-cubicon-m7ns
\n def _minSwap(self, A, B, i, cache, swapped):\n if (swapped, i) in cache:\n return cache[(swapped, i)]\n if i == len(A):\n
Cubicon
NORMAL
2018-03-19T05:01:07.621798+00:00
2018-09-05T02:33:32.197113+00:00
1,413
false
```\n def _minSwap(self, A, B, i, cache, swapped):\n if (swapped, i) in cache:\n return cache[(swapped, i)]\n if i == len(A):\n return 0\n l_min = math.inf if i > 0 and (A[i] <= A[i - 1] or B[i] <= B[i - 1]) else self._minSwap(A, B, i + 1, cache, 0)\n A[i], B[i] = B[i...
8
1
[]
0
minimum-swaps-to-make-sequences-increasing
recursion -> memoization
recursion-memoization-by-abhishekaaru-aatj
Recursion (TLE)\n\nclass Solution {\npublic:\n int solve(vector<int> num1,vector<int> num2,int i,int prev1,int prev2){\n int n = num1.size();\n
abhishekaaru
NORMAL
2022-06-04T01:24:01.508813+00:00
2022-06-04T01:24:01.508848+00:00
595
false
**Recursion (TLE)**\n```\nclass Solution {\npublic:\n int solve(vector<int> num1,vector<int> num2,int i,int prev1,int prev2){\n int n = num1.size();\n if(i == n){\n return 0;\n }\n \n int noSwap=1e9;\n if(num1[i]>prev1 && num2[i]>prev2){\n noSwap = solv...
7
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C']
3
minimum-swaps-to-make-sequences-increasing
C++ Solution with Very Detailed Explanation
c-solution-with-very-detailed-explanatio-n36d
For each ith index, we have two options - either swap or do not swap them. We have to calculate the moves for both of them until the last index.\n1. We have ini
rootkonda
NORMAL
2020-05-23T08:14:27.113666+00:00
2020-05-23T08:15:20.950988+00:00
396
false
For each ith index, we have two options - either swap or do not swap them. We have to calculate the moves for both of them until the last index.\n1. We have initialized two arrays with MAX value, which is N as we are going to calculate minimum.\n2. For index 0, if we swap then swap[0] = 1 and if we do not swap then nos...
7
0
[]
1
minimum-swaps-to-make-sequences-increasing
Python | DP | Memoization | Simplest Solution With Explanation
python-dp-memoization-simplest-solution-4ex8j
Logic\n1. Instead of checking everytime the entire array to be strictly increasing, we could check at each index whether the element is greater than its previou
akash3anup
NORMAL
2022-05-09T06:16:04.857833+00:00
2022-05-09T06:16:27.933077+00:00
616
false
### Logic\n1. Instead of checking everytime the entire array to be strictly increasing, we could check at each index whether the element is greater than its previous index or not. If it is then the array is strictly increasing till this index.\n2. So if the index reaches the end of array it means the array is strictly ...
6
0
['Dynamic Programming', 'Memoization', 'Python']
2
minimum-swaps-to-make-sequences-increasing
C++ || Easy & Simple Code || DP
c-easy-simple-code-dp-by-agrasthnaman-ws3m
\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) {\n int swaps = 0,up = 0, down = 0;\n for (int i = 0; i < A.size(); +
agrasthnaman
NORMAL
2022-03-18T21:41:58.292242+00:00
2022-03-18T21:41:58.292271+00:00
519
false
```\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) {\n int swaps = 0,up = 0, down = 0;\n for (int i = 0; i < A.size(); ++i) {\n if (A[i] > B[i]){up += 1;}\n else{down += 1;}\n\n if (i == A.size() - 1 || max(A[i], B[i]) < min(A[i + 1], B[i + 1])...
6
0
['Dynamic Programming', 'C']
1
minimum-swaps-to-make-sequences-increasing
C++ Recursive (TLE) --> Memoization
c-recursive-tle-memoization-by-thechildw-pgn9
If you have any doubts : Please Contact : https://www.linkedin.com/in/shubham-dangwal-307347197/\nC++ Recursive CODE=>TLE \n\nclass Solution {\npublic:\n \n
thechildwholovesyou
NORMAL
2022-01-24T06:31:53.246741+00:00
2022-01-24T18:26:11.841068+00:00
851
false
If you have any doubts : Please Contact : https://www.linkedin.com/in/shubham-dangwal-307347197/\nC++ Recursive CODE=>TLE \n```\nclass Solution {\npublic:\n \n int helper(vector<int>& a, vector<int>& b, int i,int prevA, int prevB, bool swap)\n {\n if(i==a.size()) return 0;\n int res=INT_MAX;\n ...
6
1
['Recursion', 'Memoization']
1
minimum-swaps-to-make-sequences-increasing
C++, O(n), With detailed explanation
c-on-with-detailed-explanation-by-user78-5zr5
\n\n\tint minSwap(vector& nums1, vector& nums2) {\n /\n At any index i, min number of swaps to maintain 0 to i in order = \n min(minimu
user7862p
NORMAL
2021-06-06T02:54:33.952607+00:00
2021-06-06T02:54:33.952643+00:00
414
false
\n\n\tint minSwap(vector<int>& nums1, vector<int>& nums2) {\n /*\n At any index i, min number of swaps to maintain 0 to i in order = \n min(minimum number of swaps required to maintain 0 to i in order by swapping ith numbers, \n minimum number of swaps required to maintain 0 to i...
6
0
[]
0
minimum-swaps-to-make-sequences-increasing
c++ 98% dp. easy to explain and impl in 10mins. cheers!
c-98-dp-easy-to-explain-and-impl-in-10mi-ulyy
\n#include <vector>\n#include <limits>\n\nusing namespace std;\n\nconst int INF = 1e5;\n\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>
solaaoi
NORMAL
2018-10-12T06:01:57.075979+00:00
2018-10-17T20:56:11.273140+00:00
828
false
```\n#include <vector>\n#include <limits>\n\nusing namespace std;\n\nconst int INF = 1e5;\n\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) {\n if (A.empty()) {\n return 0;\n }\n \n int n = A.size();\n \n vector<vector<int>> dp(n, vector<i...
6
2
[]
1
minimum-swaps-to-make-sequences-increasing
Most Efficient Way🔥| Time And Space Optimized| 4 Different Ways| Complexity Analysis
most-efficient-way-time-and-space-optimi-e7l2
Complexity\n\n\n\n\n# Pure Recursion\n\nclass Solution {\npublic:\n int solve(vector<int>& nums1, vector<int>& nums2, int index, int isSwapped) {\n //
vaib8557
NORMAL
2024-06-26T15:29:23.626325+00:00
2024-06-26T15:29:23.626343+00:00
402
false
# Complexity\n![image.png](https://assets.leetcode.com/users/images/95ce3b73-93f9-42cb-becc-c60e0c207adc_1719415538.917883.png)\n\n\n\n# Pure Recursion\n```\nclass Solution {\npublic:\n int solve(vector<int>& nums1, vector<int>& nums2, int index, int isSwapped) {\n // Base case: if index is out of bounds, no ...
5
0
['Dynamic Programming', 'Backtracking', 'Recursion', 'Memoization', 'C++']
0
minimum-swaps-to-make-sequences-increasing
✅ [Python3] DP Solution O(n) Time
python3-dp-solution-on-time-by-samirpaul-6ykm
\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n dp = [[-1]*2 for i in range(len(nums1))]\n \n def so
SamirPaulb
NORMAL
2022-10-08T06:23:52.368651+00:00
2022-10-08T07:27:38.273851+00:00
1,051
false
```\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n dp = [[-1]*2 for i in range(len(nums1))]\n \n def solve(prev1, prev2, i, swaped):\n if i >= len(nums1): return 0\n if dp[i][swaped] != -1: return dp[i][swaped]\n \n...
5
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3']
1
minimum-swaps-to-make-sequences-increasing
Python easy peasy // clear and simple 7 lines solution
python-easy-peasy-clear-and-simple-7-lin-6adw
\nclass Solution:\n def minSwap(self, A, B):\n non_swapped, swapped = [0] * len(A), [1] + [0] * (len(A) - 1)\n for i in range(1, len(A)):\n
cenkay
NORMAL
2018-05-04T14:09:12.652981+00:00
2018-05-04T14:09:12.652981+00:00
988
false
```\nclass Solution:\n def minSwap(self, A, B):\n non_swapped, swapped = [0] * len(A), [1] + [0] * (len(A) - 1)\n for i in range(1, len(A)):\n swps, no_swps = set(), set()\n if A[i - 1] < A[i] and B[i - 1] < B[i]: swps.add(swapped[i - 1] + 1 ); no_swps.add(non_swapped[i - 1])\n ...
5
1
[]
0
minimum-swaps-to-make-sequences-increasing
0(N) Solution
0n-solution-by-2005115-8dai
\n# PLS UPVOTE IF YOU LIKE MY SOLUTION\n# Approach\nModify the solve function to take nums1, nums2, and the current index index as parameters. Also, pass a bool
2005115
NORMAL
2023-07-18T12:10:44.451526+00:00
2023-07-18T12:10:44.451554+00:00
436
false
\n# PLS UPVOTE IF YOU LIKE MY SOLUTION\n# Approach\nModify the solve function to take nums1, nums2, and the current index index as parameters. Also, pass a boolean variable swapped to keep track of whether the elements are swapped at the current index.\n\nAdd a base case to the solve function. When the current index re...
4
0
['Array', 'Dynamic Programming', 'C++']
0
minimum-swaps-to-make-sequences-increasing
Java | 1D DP | easy-understanding
java-1d-dp-easy-understanding-by-6862win-ifbg
There are only 2 cases for each pair of numbers; otherwise, the input is invalid.\n (a) nums1[i] > nums1[i - 1] && nums2[i] > nums2[i - 1]\n\t(b) nums1[i] >
6862wins
NORMAL
2021-11-25T22:23:26.883767+00:00
2021-11-25T22:23:26.883794+00:00
610
false
1. There are only 2 cases for each pair of numbers; otherwise, the input is invalid.\n (a) nums1[i] > nums1[i - 1] && nums2[i] > nums2[i - 1]\n\t(b) nums1[i] > nums2[i - 1] && nums2[i] > nums1[i - 1]\n2. For each pair of numbers in the arrays, there are 2 states: swap or no swap\n3. State transition for Case (a)\n ...
4
0
['Dynamic Programming', 'Java']
0
minimum-swaps-to-make-sequences-increasing
Detailed Explanation of The Solution
detailed-explanation-of-the-solution-by-topgx
You have looked at the solution and you are wondering about the logic behind the if conditions, aren\'t you? Well, you are at the right place. I am writing this
19mihir98
NORMAL
2021-03-12T22:53:58.817374+00:00
2021-04-24T07:19:26.510818+00:00
313
false
You have looked at the solution and you are wondering about the logic behind the if conditions, aren\'t you? Well, you are at the right place. I am writing this post as there are many posts explaining the code but no one seem to clearly explain the logic and the thought process behind it. \n\n```\nint minSwap(vector<in...
4
0
[]
1
minimum-swaps-to-make-sequences-increasing
Recursive wit memo in C++
recursive-wit-memo-in-c-by-anmolgera-hpvp
\nclass Solution {\npublic:\n \n int knap(vector<int>&A, vector<int>&B, int prevA, int prevB, int swap, int idx, vector<vector<int>> &dp) {\n \n
anmolgera
NORMAL
2021-01-16T20:26:05.351535+00:00
2021-01-16T20:26:05.351569+00:00
330
false
```\nclass Solution {\npublic:\n \n int knap(vector<int>&A, vector<int>&B, int prevA, int prevB, int swap, int idx, vector<vector<int>> &dp) {\n \n if(idx==A.size()){\n return 0;\n }\n \n if(dp[idx][swap]!=-1){\n return dp[idx][swap];\n }\n in...
4
0
[]
2
minimum-swaps-to-make-sequences-increasing
C++ program without DP int time complexity of O(n) and space complexity O(1)
c-program-without-dp-int-time-complexity-m03c
\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) {\n int c=0,k=1,temp;\n for(int i=1;i<A.size();i++){\n if
arpit0891
NORMAL
2020-11-09T18:40:03.060256+00:00
2020-11-09T18:40:03.060310+00:00
591
false
```\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) {\n int c=0,k=1,temp;\n for(int i=1;i<A.size();i++){\n if (min(A[i],B[i])>max(A[i-1],B[i-1]))\n { c=min(c,k);\n k=min(c,k)+1; \n }\n else if (A[i] > A[i-1] and B[i] > B[...
4
1
['C']
0
minimum-swaps-to-make-sequences-increasing
Python easy peasy bottom up DP
python-easy-peasy-bottom-up-dp-by-prabhj-xvle
Here dp[i] means, minimum no. of swaps to make A[:i+1] and B[:i+1] increasing.\ndp[i][0] means, when ith index is not swapped.\ndp[i][1] means, when ith index i
prabhjyot28
NORMAL
2020-03-30T16:30:09.603921+00:00
2020-03-30T16:30:09.603958+00:00
510
false
Here dp[i] means, minimum no. of swaps to make A[:i+1] and B[:i+1] increasing.\ndp[i][0] means, when ith index is not swapped.\ndp[i][1] means, when ith index is swapped.\n\n```\ndef usingDP(self, A, B):\n dp = [[float(\'inf\'), float(\'inf\')] for i in range(len(A))] #[NotSwapped, Swapped]\n \n ...
4
1
['Dynamic Programming', 'Python3']
0
minimum-swaps-to-make-sequences-increasing
Hope It helps dp O(n)
hope-it-helps-dp-on-by-savecancel-txs0
inspired from @SolaAoi \n\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) \n {\n int n=A.size();\n \n int d
savecancel
NORMAL
2019-12-18T17:50:17.453376+00:00
2019-12-27T09:05:10.431588+00:00
263
false
inspired from @SolaAoi \n```\nclass Solution {\npublic:\n int minSwap(vector<int>& A, vector<int>& B) \n {\n int n=A.size();\n \n int dp[n][2];\n \n \n for(int i=0;i<n;i++)\n {\n dp[i][0]=INT_MAX;\n dp[i][1]=INT_MAX;\n }\n \n ...
4
0
[]
1
minimum-swaps-to-make-sequences-increasing
Approach + Memoization solution
approach-memoization-solution-by-pranayh-w8fi
\n## (1) why dp? why not simple linar search - greedy?\nnums1 = [0, 4, 4, 5, 9]\nnums2 = [0, 1, 6, 8, 10]\n\nsometimes we can do only 1 coll, either of them\nbu
pranayharishchandra
NORMAL
2024-08-07T09:20:46.056883+00:00
2024-08-07T09:51:12.916935+00:00
199
false
\n## (1) why dp? why not simple linar search - greedy?\nnums1 = [0, 4, 4, 5, 9]\nnums2 = [0, 1, 6, 8, 10]\n\nsometimes we can do only 1 coll, either of them\nbut if the: idx = 1\nprev1 = 0 prev2 = 0\ncurr1 = 4 curr2 = 1\n\nin this case both the calls, swap or not swap will be done\nand greedy will not work \nas we meed...
3
0
['C++']
0
minimum-swaps-to-make-sequences-increasing
Easy Recursive approach, Memoisation, Tabulation, and space Optimised
easy-recursive-approach-memoisation-tabu-5i4p
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
ironblade
NORMAL
2023-02-11T05:38:40.265083+00:00
2023-02-11T05:38:40.265123+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)$$ --...
3
0
['C++']
1
minimum-swaps-to-make-sequences-increasing
✅✅C++ || Recursive (MEMORIZED SOLUTION) || TOP DOWN
c-recursive-memorized-solution-top-down-zlgva
\nclass Solution {\npublic: \n int dp[100001][2];\n // in this i am checking for the last to front so i am \n // finding the decreaing sequence from th
MAXXER_17
NORMAL
2022-08-05T05:57:00.613538+00:00
2022-08-05T05:57:00.613596+00:00
865
false
```\nclass Solution {\npublic: \n int dp[100001][2];\n // in this i am checking for the last to front so i am \n // finding the decreaing sequence from the last to front\n int findans(vector<int>&a,vector<int>&b,int i,int val)\n {\n if(i==0)\n return 0;\n if(dp[i][val]!=-1)\n ...
3
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']
0
minimum-swaps-to-make-sequences-increasing
[C++] code like poetry | Top-down
c-code-like-poetry-top-down-by-onesucces-x4hh
\nclass Solution {\n public:\n \n vector<vector<int>> memo;\n \n int f(vector<int> &A, vector<int> &B, int i, bool shouldSwap) {\n int n = A
onesuccess
NORMAL
2020-11-06T23:12:23.075314+00:00
2020-11-06T23:12:23.075340+00:00
449
false
```\nclass Solution {\n public:\n \n vector<vector<int>> memo;\n \n int f(vector<int> &A, vector<int> &B, int i, bool shouldSwap) {\n int n = A.size();\n if (i == n) return 0;\n if (memo[shouldSwap][i] != -1) return memo[shouldSwap][i];\n int a = A[i - 1], b = B[i - 1];\n ...
3
2
['C']
0
minimum-swaps-to-make-sequences-increasing
[Python] Top Down and Bottom Up DP Solutions
python-top-down-and-bottom-up-dp-solutio-3tld
Top Down Expanded for Readability: 112 ms\npython\ndef minSwap(self, A: List[int], B: List[int]) -> int:\n\n\tif len(A) == 1: return 0\n\n\t@functools.lru_cache
rowe1227
NORMAL
2020-11-02T08:20:16.650896+00:00
2020-11-02T08:20:16.650938+00:00
209
false
**Top Down Expanded for Readability: 112 ms**\n```python\ndef minSwap(self, A: List[int], B: List[int]) -> int:\n\n\tif len(A) == 1: return 0\n\n\t@functools.lru_cache(None)\n\tdef helper(i, prev_swap):\n\n\t\tif i == len(A):\n\t\t\treturn 0\n\n\t\t# if the previous values (A[i-1] and B[i-1]) were swapped then a = B[i-...
3
0
[]
0
minimum-swaps-to-make-sequences-increasing
[Python] O(N) Time O(1) Space DP solution with explainations
python-on-time-o1-space-dp-solution-with-067i
For each pair of elements of A and B, (A[i], B[i]), there are only two status \'not swap\' or \'swap\'. Set two variables, n_swap, swap, to store the min number
licpotis
NORMAL
2020-10-27T12:18:55.211167+00:00
2020-10-27T12:27:16.677135+00:00
640
false
For each pair of elements of A and B, (A[i], B[i]), there are only two status \'not swap\' or \'swap\'. Set two variables, n_swap, swap, to store the min number of swaps to make subarray A[:i+1] and B[:i+1] strict increasing. \n\nFor i-th pair of (A[i], B[i]), there are only three possible cases since it is guaranteed ...
3
0
['Dynamic Programming', 'Python', 'Python3']
0
minimum-swaps-to-make-sequences-increasing
C++ | O( N ) | Detailed Explanation and comments
c-o-n-detailed-explanation-and-comments-p78li
Credits to : lee215\nI will be explaining the approach here.\n swap[i] = total no. of swaps required to keep array from 0 to i in increasing order when we swap
Might_Guy
NORMAL
2020-04-25T15:07:42.154336+00:00
2020-04-25T15:10:26.084652+00:00
303
false
Credits to : [lee215](https://leetcode.com/lee215)\nI will be explaining the approach here.\n* swap[i] = total no. of swaps required to keep array from 0 to i in increasing order when we swap the ith positions\n* notswap[i] = total no. of swaps required to keep array from 0 to i in increasing order when we do not sw...
3
0
[]
1
minimum-swaps-to-make-sequences-increasing
DP and not greedy explaination
dp-and-not-greedy-explaination-by-sthakk-o0gm
Thoughts\n\n- Greedy is not the solution, why?\n\t- First thought came of greedy, i.e. iterate over all the indices (A and B same), then wherever condition brea
sthakkar411
NORMAL
2020-03-21T15:12:39.591944+00:00
2020-03-21T15:12:39.591980+00:00
157
false
***Thoughts***\n\n- ***Greedy is not the solution, why?***\n\t- First thought came of greedy, i.e. iterate over all the indices (A and B same), then wherever condition breaks, swap it, do moves++ and move further\n\t- But in the above approach, whenever condition fails, we are swapping current index elements, we could ...
3
0
[]
0
minimum-swaps-to-make-sequences-increasing
C++ 8ms 97% DP solution, O(n) time O(1) space w/ explanation
c-8ms-97-dp-solution-on-time-o1-space-w-svzsz
Took me a while to figure out the specific DP logic and mentally prove its correctness. The basic idea is this:\n\nAssume you arrive at index i of both arrays.
guccigang
NORMAL
2020-01-03T05:27:25.740424+00:00
2020-01-03T06:12:14.915908+00:00
225
false
Took me a while to figure out the specific DP logic and mentally prove its correctness. The basic idea is this:\n\nAssume you arrive at index `i` of both arrays. There are two things you can do. You can either keep `A[i]` and `B[i`] the way they are (do not flip them), or swap `A[i]` and `B[i]` (flip them). Of course t...
3
0
[]
0
minimum-swaps-to-make-sequences-increasing
Python dp With Clear Explanation
python-dp-with-clear-explanation-by-sash-sjuz
Minimum swaps To make Sequences Increasing\n\n### Given 2 arrays, find minimum same indexed swaps that need to occur to make both arrays strictly increasing\n\n
sashank007
NORMAL
2019-10-01T23:10:12.367784+00:00
2019-10-02T07:12:08.510804+00:00
351
false
## Minimum swaps To make Sequences Increasing\n\n### Given 2 arrays, find minimum same indexed swaps that need to occur to make both arrays strictly increasing\n\n1. Firstly, at each stage , we need to store the value of count if we swap A[i] and B[i] and if we don\'t swap A[i] and B[i].\n2. If they are increasing with...
3
0
[]
0
minimum-swaps-to-make-sequences-increasing
Beats 99.29% Python
beats-9929-python-by-gracemeng-msut
\n def minSwap(self, A, B):\n n = len(A)\n prevNotSwap = 0\n prevSwap = 1\n for i in range(1, n):\n areBothSelfIncreas
gracemeng
NORMAL
2018-12-20T01:29:43.367625+00:00
2018-12-20T01:29:43.367687+00:00
449
false
```\n def minSwap(self, A, B):\n n = len(A)\n prevNotSwap = 0\n prevSwap = 1\n for i in range(1, n):\n areBothSelfIncreasing = A[i - 1] < A[i] and B[i - 1] < B[i] \n areInterchangeIncreasing = A[i - 1] < B[i] and B[i - 1] < A[i]\n if areBothSelfIncreasing ...
3
0
[]
0
minimum-swaps-to-make-sequences-increasing
C++ O(n) time, O(1) space
c-on-time-o1-space-by-babos-is8e
cpp []\nclass Solution {\npublic:\n int minSwap(vector<int>& nums1, vector<int>& nums2) {\n int swap = 1;\n int noSwap = 0;\n \n
babos
NORMAL
2024-11-19T06:48:32.619547+00:00
2024-11-19T06:48:32.619580+00:00
55
false
```cpp []\nclass Solution {\npublic:\n int minSwap(vector<int>& nums1, vector<int>& nums2) {\n int swap = 1;\n int noSwap = 0;\n \n for (int i = 1; i < nums1.size(); i++) {\n int curSwap = 0;\n int curNoSwap = 0;\n\n if (nums1[i] <= nums1[i-1] || nums2[i] ...
2
0
['C++']
0
minimum-swaps-to-make-sequences-increasing
🔥🎯Clean O(n) DP approach🎯🔥
clean-on-dp-approach-by-msrathore1612-m4rb
Intuition\nFor every index i we can either swap it if the strictly increasing rule is being broken or keep it as it is.\n\u2234 We have two Choices.\n\n# Approa
msrathore1612
NORMAL
2024-07-25T16:38:20.512692+00:00
2024-07-25T16:38:20.512725+00:00
491
false
# Intuition\nFor every index i we can either swap it if the strictly increasing rule is being broken or keep it as it is.\n\u2234 We have two $$Choices$$.\n\n# Approach\nIf at any index $$i$$ we have the swaps needed for sub array [ $$i+1$$ to $$n$$ ]\nthen we can calculate result for $$i$$ $$th$$ index.\n\n### Case1 :...
2
0
['Dynamic Programming', 'C++']
0
minimum-swaps-to-make-sequences-increasing
EASY UNDERSTANDING DP (FOUR APPROACHES)
easy-understanding-dp-four-approaches-by-d1c3
RECURSION \n\n \nint solve(vector<int>& nums1, vector<int>& nums2, int index, bool swapped)\n {\n if(index >= nums1.size())\n {\n re
20122
NORMAL
2024-02-24T18:58:50.535310+00:00
2024-02-24T18:58:50.535335+00:00
197
false
**RECURSION **\n\n ```\nint solve(vector<int>& nums1, vector<int>& nums2, int index, bool swapped)\n {\n if(index >= nums1.size())\n {\n return 0;\n }\n \n int ans = INT_MAX;\n \n int prev1 = nums1[index-1];\n int prev2 = nums2[index-1];\n \n ...
2
0
['Recursion', 'Memoization', 'C']
1
minimum-swaps-to-make-sequences-increasing
Detailed Explanation : O(n) Solution using 2 cases for Multisequences DP | Javascript | C++
detailed-explanation-on-solution-using-2-ys3d
Intuition\nDynamic Programming Approach:\nThe idea is to keep track of two states at each index i: swap[i] and not_swap[i].\n\nswap[i] represents the minimum nu
rbssmtkr
NORMAL
2023-08-11T04:28:35.796430+00:00
2023-08-11T04:29:01.805283+00:00
75
false
# Intuition\n**Dynamic Programming Approach:**\nThe idea is to keep track of two states at each index i: swap[i] and not_swap[i].\n\n`swap[i]` represents the minimum number of swaps required to make `A[0...i]` and `B[0...i]` strictly increasing, considering that you swap elements at index i.\n\n`not_swap[i]` represents...
2
0
['Array', 'Dynamic Programming', 'C++', 'JavaScript']
0
minimum-swaps-to-make-sequences-increasing
[Python 3] O(n) Time, O(1) Space, Detailed Explanation
python-3-on-time-o1-space-detailed-expla-a1j8
Intuition\n Describe your first thoughts on how to solve this problem. \nThere are 3 different cases to consider when looking at the border between two pairs of
KellerWheat
NORMAL
2023-07-29T23:41:27.528382+00:00
2023-07-29T23:43:38.441912+00:00
172
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are 3 different cases to consider when looking at the border between two pairs of numbers (a pair being numbers in nums1 and nums2 with the same index):\n1. The numbers are increasing, and if either pair was flipped they would still...
2
0
['Python3']
0
minimum-swaps-to-make-sequences-increasing
solution using recursion and memoization
solution-using-recursion-and-memoization-d74c
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
uwais67
NORMAL
2023-03-02T18:38:37.256941+00:00
2023-03-02T18:38:37.257002+00:00
257
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
minimum-swaps-to-make-sequences-increasing
C++ dp solution with simple explanation
c-dp-solution-with-simple-explanation-by-7kpg
Intuition\n Describe your first thoughts on how to solve this problem. \nTo find min number of swaps at a particular position, following information at previous
pranabpandey
NORMAL
2022-10-03T19:33:00.844314+00:00
2022-10-03T19:33:00.844347+00:00
1,524
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo find min number of swaps at a particular position, following information at previous position is required \n-min swaps if swap at previous position\n-min swaps if no swap at previous position\n\n# Approach\n<!-- Describe your approach ...
2
0
['C++']
0
minimum-swaps-to-make-sequences-increasing
[C++] Memoization -> Space Optimization, O(1) Space, clean code
c-memoization-space-optimization-o1-spac-tgks
1. Memoization\n\n\nclass Solution {\nprivate:\n int solve(vector<int> &nums1, vector<int> &nums2, int index, int swapped, vector<vector<int> > &dp){\n
hardikjain40153
NORMAL
2022-07-22T11:25:35.753387+00:00
2022-07-22T11:25:35.753427+00:00
427
false
***1. Memoization***\n\n```\nclass Solution {\nprivate:\n int solve(vector<int> &nums1, vector<int> &nums2, int index, int swapped, vector<vector<int> > &dp){\n if(index >= nums1.size()) return 0;\n \n if(dp[index][swapped]!=-1) return dp[index][swapped];\n \n int prev1 = nums1[ind...
2
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']
0
minimum-swaps-to-make-sequences-increasing
DP O(n) Solution | Recursion & Memoization | Explained with comments
dp-on-solution-recursion-memoization-exp-oagh
\nclass Solution {\npublic:\n \n int solve(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& dp, int index, int max1, int max2, bool swap){\n
_vedang_
NORMAL
2022-07-09T04:52:30.343009+00:00
2022-07-09T04:52:30.343051+00:00
397
false
```\nclass Solution {\npublic:\n \n int solve(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& dp, int index, int max1, int max2, bool swap){\n if(index == nums1.size()) return 0;\n if(dp[index][swap] != -1) return dp[index][swap];\n \n if(nums1[index] <= max1 || nums2[inde...
2
0
['Dynamic Programming', 'C', 'C++']
0
minimum-swaps-to-make-sequences-increasing
Recursion || C++
recursion-c-by-leetcode_hard-t889
\n// We have two choices either swap ith or don\'t swap ith since we want increasing order so if ith is in increasing order then we can choose not to swap and i
LeetCode_Hard
NORMAL
2022-04-10T15:27:53.697454+00:00
2022-04-10T15:27:53.697491+00:00
256
false
```\n// We have two choices either swap ith or don\'t swap ith since we want increasing order so if ith is in increasing order then we can choose not to swap and if swapping them also result in increasing then we can choose to swap.\n\nclass Solution {\npublic:\n vector<vector<int>>dp;\n int minSwap(vector<int>& ...
2
0
['Recursion', 'C']
0
minimum-swaps-to-make-sequences-increasing
Simple Python Top-Down DFS + @cache (12 lines)
simple-python-top-down-dfs-cache-12-line-76ta
dfs(i, a, b) returns the minimum swaps to ensure that a < nums1[i] and b < nums2[i]. If nums1[i] and nums2[i] are already greater than the things that come befo
jaredlwong
NORMAL
2022-02-18T04:11:10.406530+00:00
2022-02-18T04:11:27.773090+00:00
265
false
`dfs(i, a, b)` returns the minimum swaps to ensure that `a < nums1[i]` and `b < nums2[i]`. If `nums1[i]` and `nums2[i]` are already greater than the things that come before we don\'t need to swap, otherwise we have to swap.\n\nIt\'s still O(n)\n\n```\nfrom functools import cache\nclass Solution:\n def minSwap(self, ...
2
0
['Depth-First Search', 'Python', 'Python3']
0
minimum-swaps-to-make-sequences-increasing
[Python] Top down DP - Clean & Concise
python-top-down-dp-clean-concise-by-hiep-0g6l
Solution 1: Top down DP\n\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n @lru_cache(None)\n def dp(i, isSwa
hiepit
NORMAL
2021-07-27T12:15:26.033734+00:00
2021-07-27T13:03:54.049746+00:00
411
false
**Solution 1: Top down DP**\n```\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n @lru_cache(None)\n def dp(i, isSwap):\n if i == len(nums1):\n return 0\n \n cand = []\n if i == 0:\n last1 = last...
2
4
[]
1
minimum-swaps-to-make-sequences-increasing
C++ & Rust: One Pass Scan Counting Greedy O(N)
c-rust-one-pass-scan-counting-greedy-on-jcumv
The reasining is pretty much the same essentially as most other post. \n1) Let n be the lenth of the arrays and count be the number of swaps of a way to make bo
xiaoping3418
NORMAL
2021-06-28T08:42:08.129161+00:00
2022-07-16T13:19:47.442604+00:00
443
false
The reasining is pretty much the same essentially as most other post. \n1) Let n be the lenth of the arrays and count be the number of swaps of a way to make both arrays strictly incresing. Alternately, we can make n - count swaps to arcgive the same goal. Therefore, the answer is min(count, n - count).\n2) As matter o...
2
0
['C', 'Rust']
0