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
longest-continuous-increasing-subsequence
Easy python method using sliding window approach
easy-python-method-using-sliding-window-9h2s5
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
arun_balakrishnan
NORMAL
2024-04-16T13:48:17.324480+00:00
2024-04-16T13:48:17.324508+00:00
126
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)$$ -->\n\n# Code\n```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n result = 1\n left = 0\n l = len(nums)\n for i in range(1, l):\n if nums[i] <= nums[i - 1]:\n left = i\n else:\n result = max(result, (i - left + 1))\n return result\n \n```
2
0
['Python3']
0
longest-continuous-increasing-subsequence
python easy solution.
python-easy-solution-by-alaaelgndy-wru6
Intuition \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-
alaaelgndy
NORMAL
2024-03-17T09:24:15.301944+00:00
2024-03-17T09:24:15.301967+00:00
381
false
# Intuition \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)$$ -->\n\n# Code\n```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n res = 1\n temp = 1\n prev = nums[0]\n for num in nums:\n if num > prev:\n temp += 1\n else:\n if temp > res:\n res = temp\n temp = 1\n prev = num\n return max(res, temp)\n```
2
0
['Python3']
0
longest-continuous-increasing-subsequence
🟢Beats 100.00% of users with Java, Easy Solution with Explanation
beats-10000-of-users-with-java-easy-solu-c5h4
Keep growing \uD83D\uDE0A\n\n\n\n# Complexity\n\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n\n# Explanation\n\nJavascript []\nStart\n Initializatio
rahultripathi17
NORMAL
2024-01-14T12:51:37.605297+00:00
2024-04-04T09:12:07.922884+00:00
602
false
> ##### Keep growing \uD83D\uDE0A\n![image.png](https://assets.leetcode.com/users/images/886b45fe-9695-406f-a5eb-89b60bb2a074_1705236446.7537713.png)\n\n\n# Complexity\n\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n\n# Explanation\n\n```Javascript []\nStart\n Initialization: maxLength = 1, currentLength = 1\n For loop (i = 1 to nums.length - 1)\n If (nums[i] > nums[i - 1])\n True: currentLength++\n False: currentLength = 1\n Update maxLength: maxLength = Math.max(maxLength, currentLength)\n Repeat for the next iteration of the loop\n End of loop\n Return maxLength\nEnd\n```\n\n# Code\n\n```java []\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n \n int maxLength = 1;\n int currentLength = 1;\n\n for (int i = 1; i < nums.length; i++) {\n if (nums[i] > nums[i - 1]) {\n currentLength++;\n } else {\n currentLength = 1;\n }\n\n maxLength = Math.max(maxLength, currentLength);\n }\n\n return maxLength;\n }\n}\n```\n##### If you have any question, feel free to ask. If you like the solution or the explanation, Please UPVOTE ! \u270C\uFE0F
2
0
['Array', 'Math', 'Java']
0
longest-continuous-increasing-subsequence
Best C++ Solution
best-c-solution-by-ravikumar50-v7l0
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
ravikumar50
NORMAL
2023-11-17T17:53:01.438220+00:00
2023-11-17T17:53:01.438251+00:00
567
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)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& arr) {\n int n = arr.size();\n int i=0;\n int j=0;\n int ans = 1;\n while(i<n){\n int res = 1;\n for(int j=i+1; j<n; j++){\n if(arr[j]>arr[j-1]) res++;\n else break;\n }\n ans = max(ans,res);\n i++;\n }\n return ans;\n }\n};\n```
2
0
['C++']
1
longest-continuous-increasing-subsequence
O(n) Longest Continuous Increasing Subsequence Solution in C++
on-longest-continuous-increasing-subsequ-b6uf
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
The_Kunal_Singh
NORMAL
2023-05-14T03:20:07.270088+00:00
2023-05-14T03:20:07.270122+00:00
443
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)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int i, len=1, maxlen=1;\n for(i=1 ; i<nums.size() ; i++)\n {\n if(nums[i]>nums[i-1])\n {\n len++;\n }\n else if(len>maxlen)\n {\n maxlen = len;\n len=1;\n }\n else\n {\n len=1;\n }\n }\n if(len>maxlen)\n maxlen = len;\n return maxlen;\n }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/db35f119-6d56-413c-aeac-389431744144_1684034399.839135.jpeg)\n
2
0
['C++']
0
longest-continuous-increasing-subsequence
Solution
solution-by-deleted_user-xjme
C++ []\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int maxlength = 1;\n int length = 1;\n int n = nums.size
deleted_user
NORMAL
2023-04-17T13:17:59.099337+00:00
2023-04-17T13:44:03.515514+00:00
1,124
false
```C++ []\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int maxlength = 1;\n int length = 1;\n int n = nums.size();\n for(int i= 1; i<n;i++){\n if (nums[i-1]<nums[i]){\n length++;\n }\n else{\n if(maxlength<length){\n maxlength = length;\n }\n length = 1;\n }\n }\n return max(length, maxlength);\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n l, r, curMax = 0, 1, 1\n while r < len(nums):\n if nums[r] > nums[r-1]:\n curMax = max(curMax, r-l+1)\n else:\n l = r\n r += 1\n return curMax\n```\n\n```Java []\nclass Solution {\n public int findLengthOfLCIS(int[] nums) \n {\n int maxCount = 1;\n int currentCount = 1;\n int i = 0 ;\n int j = 1;\n while(j<nums.length)\n {\n if(nums[j]>nums[i])\n {\n currentCount++;\n i++;\n j++;\n }\n else\n {\n i = j;\n j++;\n currentCount = 1;\n }\n if(maxCount<currentCount)\n {\n maxCount = currentCount;\n }\n } \n return maxCount; \n }\n}\n```\n
2
0
['C++', 'Java', 'Python3']
0
longest-continuous-increasing-subsequence
simple cpp solution
simple-cpp-solution-by-prithviraj26-9fsl
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
prithviraj26
NORMAL
2023-02-08T16:00:00.307033+00:00
2023-02-08T16:00:00.307088+00:00
359
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)$$ -->\no(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(1)\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int ans=0,c=1;\n for(int i=1;i<nums.size();i++)\n {\n if(nums[i]>nums[i-1])\n {\n c++;\n }\n else\n {\n ans=max(ans,c);\n c=1;\n }\n }\n ans=max(ans,c);\n return ans;\n }\n};\n```
2
0
['Array', 'C++']
0
longest-continuous-increasing-subsequence
✅ [Rust] 0 ms, linear scan (with detailed comments)
rust-0-ms-linear-scan-with-detailed-comm-y64f
This solution employs a simple loop to count the number of characters in the longest continuous increasing subsequence. It demonstrated 0 ms runtime (100.00%) a
stanislav-iablokov
NORMAL
2022-09-13T09:32:53.917656+00:00
2022-10-23T12:57:45.006077+00:00
148
false
This [solution](https://leetcode.com/submissions/detail/798332889/) employs a simple loop to count the number of characters in the longest continuous increasing subsequence. It demonstrated **0 ms runtime (100.00%)** and used **2.0 MB memory (100.00%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\nimpl Solution \n{\n pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 \n {\n let mut max_len : i32 = 0;\n let mut cur_len : i32 = 0;\n let mut prev : i32 = -1_000_000_001;\n \n // [1] we keep track of current length \'cur_len\' of subsequence\n\t\t// and update \'max_len\' every time the continuous sequence is broken\n for n in nums\n {\n if n > prev { cur_len += 1; }\n else { max_len = max_len.max(cur_len); cur_len = 1; }\n prev = n;\n }\n \n // [2] update \'max_len\' for the last continuous sequence\n max_len.max(cur_len)\n }\n}\n```
2
0
['Rust']
1
longest-continuous-increasing-subsequence
Clean 0ms Java Solution
clean-0ms-java-solution-by-nomaanansarii-x6bt
\nclass Solution {\n public int findLengthOfLCIS(int[] nums) \n {\n int max =0;\n int count =0;\n \n for(int i=1; i<nums.lengt
nomaanansarii100
NORMAL
2022-09-12T08:03:30.677918+00:00
2022-09-12T08:03:30.677951+00:00
733
false
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) \n {\n int max =0;\n int count =0;\n \n for(int i=1; i<nums.length;i++)\n {\n if(nums[i-1] < nums[i])\n {\n count++;\n max = Math.max(count , max);\n }\n else\n count =0;\n }\n return max+1;\n }\n}\n```
2
0
['Java']
0
longest-continuous-increasing-subsequence
O(n) with go
on-with-go-by-tuanbieber-47h6
\nfunc findLengthOfLCIS(nums []int) int {\n res, current := 1, 1\n \n for i := 1; i < len(nums); i++ {\n if nums[i] > nums[i-1] {\n c
tuanbieber
NORMAL
2022-08-20T16:18:13.014082+00:00
2022-08-20T16:18:13.014128+00:00
387
false
```\nfunc findLengthOfLCIS(nums []int) int {\n res, current := 1, 1\n \n for i := 1; i < len(nums); i++ {\n if nums[i] > nums[i-1] {\n current++ \n } else {\n if current > res {\n res = current\n }\n \n current = 1\n }\n }\n \n if current > res {\n res = current\n }\n \n return res\n}\n```
2
0
['Go']
0
longest-continuous-increasing-subsequence
📌Fastest Java☕ solution 0ms💯
fastest-java-solution-0ms-by-saurabh_173-szcx
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int len=1,max=0;\n for(int i=1;i<nums.length;i++)\n {\n i
saurabh_173
NORMAL
2022-07-04T15:48:26.030704+00:00
2022-07-04T15:48:26.030733+00:00
274
false
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int len=1,max=0;\n for(int i=1;i<nums.length;i++)\n {\n if(nums[i-1]<nums[i])\n len++;\n else\n {\n max=Math.max(len,max);\n len=1;\n }\n }\n return Math.max(max,len);\n }\n}
2
0
['Java']
0
longest-continuous-increasing-subsequence
O(N) solution
on-solution-by-andrewnerdimo-4f6b
\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n maxLen = count = 1\n for i in range(len(nums) - 1):\n if n
andrewnerdimo
NORMAL
2022-05-19T11:48:36.813258+00:00
2022-05-19T11:48:36.813289+00:00
449
false
```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n maxLen = count = 1\n for i in range(len(nums) - 1):\n if nums[i] < nums[i + 1]:\n count += 1\n else:\n count = 1\n \n maxLen = max(count, maxLen)\n \n return maxLen\n```
2
0
['Python', 'Python3']
0
longest-continuous-increasing-subsequence
Simple and Easy || C++ ||
simple-and-easy-c-by-bhaskarv2000-195q
\nclass Solution\n{\npublic:\n int findLengthOfLCIS(vector<int> &nums)\n {\n int mn = INT_MIN, cnt = 0, mx = 0;\n for (auto it : nums)\n
BhaskarV2000
NORMAL
2022-04-17T14:34:04.765757+00:00
2022-04-17T14:34:04.765789+00:00
252
false
```\nclass Solution\n{\npublic:\n int findLengthOfLCIS(vector<int> &nums)\n {\n int mn = INT_MIN, cnt = 0, mx = 0;\n for (auto it : nums)\n {\n if (it > mn)\n {\n mn = it;\n cnt++;\n }\n else\n {\n mx = max(cnt, mx);\n mn = it;\n cnt = 1;\n }\n }\n mx = max(cnt, mx);\n return mx;\n }\n};\n```
2
0
['C']
0
longest-continuous-increasing-subsequence
Longest Continuous Increasing Subsequence Solution Java
longest-continuous-increasing-subsequenc-7i4o
class Solution {\n public int findLengthOfLCIS(int[] nums) {\n int ans = 0;\n\n for (int l = 0, r = 0; r < nums.length; ++r) {\n if (r > 0 && nums[r
bhupendra786
NORMAL
2022-03-25T07:23:33.028008+00:00
2022-03-25T07:23:33.028047+00:00
100
false
class Solution {\n public int findLengthOfLCIS(int[] nums) {\n int ans = 0;\n\n for (int l = 0, r = 0; r < nums.length; ++r) {\n if (r > 0 && nums[r] <= nums[r - 1])\n l = r;\n ans = Math.max(ans, r - l + 1);\n }\n\n return ans;\n }\n}\n
2
0
['Array']
0
longest-continuous-increasing-subsequence
Python | Single pass | Simplest Self Explanatory Code
python-single-pass-simplest-self-explana-7tlu
\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n lcis, cis = 1, 1\n for i in range(1, len(nums)):\n if nums
akash3anup
NORMAL
2021-12-13T06:01:47.225236+00:00
2021-12-13T06:01:47.225282+00:00
123
false
```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n lcis, cis = 1, 1\n for i in range(1, len(nums)):\n if nums[i] > nums[i-1]:\n cis += 1\n else:\n cis = 1\n lcis = max(lcis, cis)\n return lcis\n \n```\n\n***If you liked the above solution then please upvote!***
2
0
['Python']
0
longest-continuous-increasing-subsequence
C++ || 4ms || simple solution
c-4ms-simple-solution-by-rohit_sapkal-09p0
class Solution {\npublic:\n\n int findLengthOfLCIS(vector& nums) {\n int n = nums.size();\n int ct = 1, count=0;\n \n for(int i=0
Rohit_Sapkal
NORMAL
2021-10-17T14:08:43.548808+00:00
2021-10-17T14:08:43.548838+00:00
149
false
class Solution {\npublic:\n\n int findLengthOfLCIS(vector<int>& nums) {\n int n = nums.size();\n int ct = 1, count=0;\n \n for(int i=0 ; i<n-1 ; ++i)\n {\n if(nums[i]>=nums[i+1])\n {\n count = max(count,ct);\n ct=1;\n }\n else ct++;\n }\n count = max(count,ct);\n return count;\n }\n};\n\n**leave a like.**
2
0
['C']
0
longest-continuous-increasing-subsequence
Easy Java Solution
easy-java-solution-by-kritikasinha-6x57
class Solution {\n\n public int findLengthOfLCIS(int[] nums) {\n int max = 1, count = 1;\n \n for(int i = 1; inums[i-1])\n {\
kritikasinha_
NORMAL
2021-08-13T15:32:00.705534+00:00
2021-08-13T15:32:00.705581+00:00
233
false
class Solution {\n\n public int findLengthOfLCIS(int[] nums) {\n int max = 1, count = 1;\n \n for(int i = 1; i<nums.length; i++)\n {\n if(nums[i]>nums[i-1])\n {\n count++;\n max = Math.max(max, count);\n }\n else\n count = 1;\n }\n return max;\n }\n}
2
0
['Java']
0
longest-continuous-increasing-subsequence
JS-Easy to understand for beginners as well(2 solutions)
js-easy-to-understand-for-beginners-as-w-6s9r
\nvar findLengthOfLCIS = function (nums) {\n let count = 1,\n max = 0;\n for (let i = 1; i < nums.length; i++) {\n if (nums[i] > nums[i - 1]) {\n c
lssuseendharlal
NORMAL
2021-03-24T13:08:50.201756+00:00
2021-04-18T13:27:12.962960+00:00
211
false
```\nvar findLengthOfLCIS = function (nums) {\n let count = 1,\n max = 0;\n for (let i = 1; i < nums.length; i++) {\n if (nums[i] > nums[i - 1]) {\n count++;\n max = Math.max(max, count);\n } else {\n count = 1;\n }\n }\n return nums.length >= 1 ? (max > 0 ? max : count) : 0;\n};\n\n```\n\nSecond solution:\n```\nvar findLengthOfLCIS = function(nums) {\n if(nums.length==0) return 0\n let count=1,max=1;\n for(let i=0;i<nums.length-1;i++){\n if(nums[i]<nums[i+1]){\n count++;\n max=Math.max(count,max);\n }else{\n count=1;\n }\n }\n return max;\n};\n```\n\nIgnore the below solution(this is for the guy who asked another ques in the comment)\n```\nconst longestIncreaseWithInBoundary = (arr, indices) => {\n // converting 2D array to 1D\n // [[0, 5],[1, 5],[2, 5],[2, 2]] will be [0, 5, 1, 5, 2, 5, 2, 2]\n const flatIndices = indices.flat();\n\n const findLongest = (sliced) => {\n // this is the old method which is used in this question\n let count = 1,\n max = 0;\n for (let i = 1; i < sliced.length; i++) {\n if (sliced[i] > sliced[i - 1]) {\n count++;\n max = Math.max(count, max);\n } else {\n count = 1;\n }\n }\n return max > 0 ? max : count;\n };\n\n let res = [],\n map = new Map();\n // iterating the 1D(which we converted...we converted because we can avoid inner for loop)\n for (let i = 0; i < flatIndices.length; i += 2) {\n // this takes a part of given nums\n // for example, part of [2,1,3,5,4,7] with boundary [2,5] is [3,5,4,7]\n const slicedArr = arr.slice(flatIndices[i], flatIndices[i + 1] + 1);\n // if that value is already stored we can take from that map(no need to pass to the helper func)\n if (map.has(flatIndices[i] + "" + flatIndices[i + 1])) {\n res.push(map.get(flatIndices[i] + "" + flatIndices[i + 1]));\n } else {\n // passing that sliceArr into the helper function(name whatever u want)\n const length = findLongest(slicedArr);\n // storing that returned value in the map\n map.set(flatIndices[i] + "" + flatIndices[i + 1], length);\n // pushing the returned max subarray value\n res.push(length);\n }\n }\n // returning the array which holds the max subarray correspondingly.\n // [3,3,2,1]\n return res;\n};\nconsole.log(\n longestIncreaseWithInBoundary(\n [2, 1, 3, 5, 4, 7],\n [\n [0, 5],\n [1, 5],\n [2, 5],\n [2, 2],\n ]\n )\n);\n```\nBut still Im not giving you assurance that this will work if large number of data is passed.Try it and let me know.
2
0
['JavaScript']
2
longest-continuous-increasing-subsequence
C++ || Greed is best || Easy to understand
c-greed-is-best-easy-to-understand-by-an-a6vv
Runtime: 24 ms, faster than 54.02% of C++ online submissions for Longest Continuous Increasing Subsequence.\nMemory Usage: 11 MB, less than 94.51% of C++ online
anonymous_kumar
NORMAL
2020-07-31T19:48:50.511504+00:00
2020-07-31T19:48:50.511550+00:00
420
false
***Runtime: 24 ms, faster than 54.02% of C++ online submissions for Longest Continuous Increasing Subsequence.\nMemory Usage: 11 MB, less than 94.51% of C++ online submissions for Longest Continuous Increasing Subsequence.***\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int n = nums.size();\n if(n == 0) \n return 0;\n int result = 1;\n int current = 1;\n for(int i=1;i<n;i++){\n if(nums[i] > nums[i-1]){\n current++;\n }else{\n current = 1;\n }\n result = max(result, current);\n }\n return result;\n }\n};\n```
2
0
['C', 'C++']
0
longest-continuous-increasing-subsequence
Simple Java beats 100%
simple-java-beats-100-by-swapnil510-m53l
```\n public int findLengthOfLCIS(int[] nums) {\n if(nums==null || nums.length ==0)\n return 0;\n int count = 1;\n int max =
swapnil510
NORMAL
2019-12-28T21:23:12.343103+00:00
2019-12-28T21:23:12.343146+00:00
265
false
```\n public int findLengthOfLCIS(int[] nums) {\n if(nums==null || nums.length ==0)\n return 0;\n int count = 1;\n int max = 0;\n for(int i =1;i<nums.length;i++){\n if(nums[i]>nums[i-1]){\n count++;\n }else{\n max = Math.max(max,count);\n count=1;\n }\n }\n \n return Math.max(max,count); // if the complete sequence is monotonically increasing
2
0
[]
0
longest-continuous-increasing-subsequence
Divide and Conquer Recursive Solution [Accepted]
divide-and-conquer-recursive-solution-ac-0qpd
Below is a classic divide-and-conquer approach to solve this problem using recursion in C#. Although a little complex than the linear solution presented in Solu
ccpu
NORMAL
2019-07-06T04:16:42.361531+00:00
2019-07-06T04:16:42.361565+00:00
249
false
Below is a classic divide-and-conquer approach to solve this problem using recursion in C#. Although a little complex than the linear solution presented in Solution tab, its intuitive and a common approach for "longest subsequence" kind of problems.\n\n```\npublic class Solution {\n int FindLCIS_Iter(int[] a, int start, int end) {\n if (start == end) {\n return 1;\n }\n \n int mid = start + (end - start) / 2;\n int leftLcis = FindLCIS_Iter(a, start, mid);\n int rightLcis = FindLCIS_Iter(a, mid + 1, end);\n\t\t\n int currentLcis = FindLCIS(a, start, end, mid);\n List<int> lcisList = new List<int>() { leftLcis, rightLcis, currentLcis };\n lcisList.Sort();\n return lcisList[lcisList.Count - 1];\n }\n \n int FindLCIS(int[] a, int start, int end, int mid) {\n int i = mid, j = mid;\n while (i > start && a[i] > a[i - 1]) i -= 1;\n while (j < end && a[j] < a[j + 1]) j += 1;\n return j - i + 1;\n }\n \n public int FindLengthOfLCIS(int[] nums) {\n if (nums.Length < 2) return nums.Length;\n return FindLCIS_Iter(nums, 0, nums.Length - 1);\n }\n}\n```
2
0
[]
0
longest-continuous-increasing-subsequence
python easy solution
python-easy-solution-by-zlpmichelle-hrut
\n\n max_res = 0\n count = 0\n for i in range(len(nums)):\n if i == 0 or nums[i] > nums[i - 1]:\n count += 1\n
zlpmichelle
NORMAL
2019-06-02T20:28:42.286985+00:00
2019-06-02T20:29:55.412797+00:00
245
false
\n\n max_res = 0\n count = 0\n for i in range(len(nums)):\n if i == 0 or nums[i] > nums[i - 1]:\n count += 1\n max_res = max(max_res, count)\n else:\n count = 1\n return max_res
2
0
[]
0
longest-continuous-increasing-subsequence
Python - super simple and very intuitive - also beats 100% at the moment
python-super-simple-and-very-intuitive-a-0o2l
\nclass Solution(object):\n def findLengthOfLCIS(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n if not n
poojanarayan
NORMAL
2018-08-29T09:27:20.470302+00:00
2018-09-07T16:14:43.545668+00:00
272
false
```\nclass Solution(object):\n def findLengthOfLCIS(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n if not nums:\n return 0\n if len(nums) == 1:\n return 1\n \n count = 1\n maxcount = 1\n \n for i in range(1,len(nums)):\n if nums[i] > nums[i-1]:\n count+=1\n else:\n count = 1\n if count > maxcount:\n maxcount = count\n return maxcount\n```
2
1
[]
0
longest-continuous-increasing-subsequence
Python, 'Anchor' Approach
python-anchor-approach-by-awice-axta
Let's remember the smallest value prev in our current chain, and the length count of the current chain.\n\n\ndef findLengthOfLCIS(self, nums):\n prev = float
awice
NORMAL
2017-09-10T04:24:50.134000+00:00
2017-09-10T04:24:50.134000+00:00
312
false
Let's remember the smallest value `prev` in our current chain, and the length `count` of the current chain.\n\n```\ndef findLengthOfLCIS(self, nums):\n prev = float('-inf')\n ans = count = 0\n for x in nums:\n if x > prev:\n count += 1\n ans = max(ans, count)\n else:\n count = 1\n prev = x\n return ans\n```
2
1
[]
1
longest-continuous-increasing-subsequence
Python
python-by-ipeq1-2n7y
\nclass Solution(object):\n def findLengthOfLCIS(self, nums):\n if not nums:\n return 0\n ans, pre = 1, 1\n for i in range(1,
ipeq1
NORMAL
2017-09-12T04:48:28.022000+00:00
2017-09-12T04:48:28.022000+00:00
445
false
```\nclass Solution(object):\n def findLengthOfLCIS(self, nums):\n if not nums:\n return 0\n ans, pre = 1, 1\n for i in range(1, len(nums)):\n if nums[i] > nums[i - 1]:\n ans = max(ans, i - pre)\n else:\n pre = 1\n ans = max(ans, pre)\n return ans\n```
2
0
[]
2
longest-continuous-increasing-subsequence
beats 100% and easy solution in c++.
beats-100-and-easy-solution-in-c-by-xegl-yx6e
IntuitionApproachComplexity Time complexity:O(n) Space complexity:O(1) Code
xegl87zdzE
NORMAL
2025-04-06T12:10:15.816162+00:00
2025-04-06T12:10:15.816162+00:00
32
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity:O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findLengthOfLCIS(vector<int>& nums) { int res=1,p=1; for(int j=1;j<nums.size();j++) { if(nums[j]>nums[j-1]) { p++; } else { res=max(res,p); p=1; } } res=max(res,p); return res; } }; ```
1
0
['Array', 'C++']
0
longest-continuous-increasing-subsequence
Longest Continuous Increasing Subsequence
longest-continuous-increasing-subsequenc-mp2x
IntuitionThe problem asks for the length of the longest continuous increasing subsequence (LCIS) in an array. To solve this, we traverse the array while keeping
expert07
NORMAL
2025-03-13T09:12:58.556125+00:00
2025-03-13T09:12:58.556125+00:00
135
false
# Intuition The problem asks for the length of the longest continuous increasing subsequence (LCIS) in an array. To solve this, we traverse the array while keeping track of an increasing sequence. If we encounter a number smaller than or equal to the previous one, we reset the counter. Throughout, we update the result if we find a longer subsequence. # Approach - Initialize two variables: counter to keep track of the current increasing subsequence length and result to store the maximum length found. - Iterate through the array using a for loop. - For each element, reset counter to 1, then use a while loop to count the length of the increasing subsequence. - If the current number is smaller than or equal to the previous one, exit the while loop. - Update result if counter exceeds the previous result. - Return result as the final answer. # Complexity - Time complexity: O(n), where n is the length of nums, as each element is visited at most once. - Space complexity: O(1), constant space used. # Code ```cpp [] class Solution { public: int findLengthOfLCIS(vector<int>& nums) { int counter = 1; int result = 1; for(int i = 0; i < nums.size(); i++) { counter = 1; while(i < nums.size() -1 && nums[i+1] > nums[i]) { counter++; i++; } if(result < counter) result = counter; } return result; } }; ```
1
0
['Array', 'Two Pointers', 'C++']
0
longest-continuous-increasing-subsequence
100% Acceptance! ✅
100-acceptance-by-velan_m_velan-wqbm
VELAN.MVelan.MComplexity Time complexity:O(n) Space complexity:O(n) Code
velan_m_velan
NORMAL
2025-03-08T08:14:46.890614+00:00
2025-03-08T08:14:46.890614+00:00
105
false
# VELAN.M $$Velan.M$$ # 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 ```cpp [] class Solution { public: int findLengthOfLCIS(vector<int>& nums) { int n=nums.size(),c=0,maxc=0; for(int i=0;i<n-1;i++){ if(nums[i]<nums[i+1])maxc=max(++c,maxc); else c=0; } return maxc+1; } }; ```
1
0
['C++']
0
longest-continuous-increasing-subsequence
Beats 100 % || Easy solution || Java
beats-100-easy-solution-java-by-nikhil_s-g4o0
IntuitionApproachComplexity Time complexity: Space complexity: Code
Nikhil_Shirsath
NORMAL
2025-02-26T06:57:17.533453+00:00
2025-02-26T06:57:17.533453+00:00
189
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 ```java [] class Solution { public int findLengthOfLCIS(int[] nums) { if(nums.length==1) { return 1; } int count=1; int max=1; for(int i=0;i<nums.length-1;i++) { if(nums[i]<nums[i+1]) { count++; } else { max=Math.max(count,max); count=1; } } max=Math.max(count,max); return max; } } ```
1
0
['Java']
0
longest-continuous-increasing-subsequence
just use the prev element with the next element!
just-use-the-prev-element-with-the-next-5kjcg
IntuitionApproachComplexity Time complexity: Space complexity: Code
HLE0mPWjhW
NORMAL
2025-02-14T11:33:37.322395+00:00
2025-02-14T11:33:37.322395+00:00
102
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 ```java [] class Solution { public int findLengthOfLCIS(int[] nums) { int lng=1; int max = Integer.MIN_VALUE; for(int j =1;j<nums.length;j++){ int current = j-1; if(nums[current]<nums[j]) lng++; else{ max=Math.max(max,lng); lng=1; } } max=Math.max(max,lng); lng=1; return max; } } ```
1
0
['Java']
0
longest-continuous-increasing-subsequence
dp easy solution (memorization concept ) c++ solution
dp-easy-solution-memorization-concept-c-b517w
IntuitionApproachComplexityo(n); Time complexity: Space complexity: o(n) Code
anandgoyal0810
NORMAL
2025-02-09T09:44:51.472666+00:00
2025-02-09T09:44:51.472666+00:00
95
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity o(n); - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: - o(n) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findLengthOfLCIS(vector<int>& nums) { int n = nums.size(); vector<int> dp ( n , 1); if (n==1) return 1; int maxi=0; for (int i=1;i< n;i++){ if (nums[i]>nums[i-1]){ dp[i]=dp[i-1]+1; } maxi=max(maxi,dp[i]); } return maxi; } }; ```
1
0
['C++']
0
longest-continuous-increasing-subsequence
pointer approach easy and quick
pointer-approach-easy-and-quick-by-willw-vzko
Intuitionuse one pointer, traverse the list onceApproachComplexity Time complexity: O(n) Space complexity: O(1)Code
willw_
NORMAL
2025-02-07T03:08:19.544954+00:00
2025-02-07T03:08:19.544954+00:00
191
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> use one pointer, traverse the list once # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. c --> $$O(n)$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> $$O(1)$$ # Code ```python3 [] class Solution: def findLengthOfLCIS(self, nums: List[int]) -> int: # deal with edge case if len(nums) == 1: return 1 # specify variables - we only need one pointer # as we will have to check one by one anyway so we can use # pointer and pointer + 1 to achieve this idx, curr, longest = 0, 1, 1 # since we will use pointer + 1, we only traverse the first n - 1 elements while idx < len(nums) - 1: # if strictly increasing, update the current counter # and immediately compare with the current max and update if nums[idx + 1] > nums[idx]: curr += 1 longest = max(longest, curr) # if not strictly increasing then reset the counter else: curr = 1 # and only now do we update the counter as it applies to both if and else idx += 1 return longest ```
1
0
['Python3']
0
longest-continuous-increasing-subsequence
Easy solution using C++ |100% beats
easy-solution-using-c-100-beats-by-ravin-7mmc
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
RAVINDRAN_S
NORMAL
2024-11-21T04:46:03.267541+00:00
2024-11-21T04:46:03.267576+00:00
13
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:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int c=1;\n int n=nums.size();\n int maxm=1;\n for (int i=0;i<n-1;i++){\n if (nums[i]<nums[i+1]){\n c++;\n } else{\n c=1;\n }\n maxm=max(maxm,c);\n }\n return maxm;\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
Easy Solution. Beats 94%.
easy-solution-beats-94-by-akshat_04-9q7e
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
Akshat_04
NORMAL
2024-07-17T07:55:51.198331+00:00
2024-07-17T07:55:51.198351+00:00
9
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- 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)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int count=0;\n int ans=0;\n for(int i=1;i<nums.size();i++){\n if(nums[i]>nums[i-1]){\n count++;\n }\n else{\n //max between count and ans\n ans=max(count,ans);\n count=0;\n }\n }\n ans=max(count,ans);\n \n //we have traversed from 1 index so we have to add 1 to the ans.\n return ans+1;\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
Beats 95% users, simple
beats-95-users-simple-by-anil_kumar_2002-v2ps
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
anil_kumar_2002
NORMAL
2024-06-09T08:29:57.819158+00:00
2024-06-09T08:29:57.819187+00:00
2
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)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int count=1;\n int index=0;\n int ans=1;\n for(int i=1;i<nums.size();i++){\n if(nums[i]>nums[i-1]){\n count++;\n }else{\n ans=max(ans,count);\n count=1;\n }\n }\n ans=max(ans,count);\n return ans;\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
c++ counting
c-counting-by-2004sherry-zbvt
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
2004sherry
NORMAL
2024-05-30T10:16:13.859500+00:00
2024-05-30T10:16:13.859524+00:00
47
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\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)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int count =1;\n int maxi=INT_MIN;\n int n=nums.size();\n for(int i=0;i<n-1;i++)\n {\n if(nums[i]<nums[i+1] )\n {\n count++;\n maxi=max(maxi,count);\n }\n else\n {\n count=1;\n }\n }\n if(maxi==INT_MIN)\n {\n return 1;\n }\n return maxi;\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
Naive Approach || 68% TC || 61% S.C || CPP
naive-approach-68-tc-61-sc-cpp-by-ganesh-l2so
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
Ganesh_ag10
NORMAL
2024-04-08T23:46:50.018296+00:00
2024-04-08T23:46:50.018338+00:00
533
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:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int n=nums.size();\n int r=1;\n int maxi=1;\n int count=1;\n while(r<n){\n if(nums[r-1]<nums[r]){\n count++;\n }\n else\n {\n maxi=max(count,maxi);\n count=1;\n }\n r++;\n }\n maxi=max(count,maxi);\n return maxi;\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
Java solution (Beats 100%)
java-solution-beats-100-by-vidojevica-lg1v
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
vidojevica
NORMAL
2023-11-28T21:18:18.169510+00:00
2023-11-28T21:18:18.169540+00:00
9
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)$$ -->\n\n# Code\n```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) \n {\n int max = 0;\n\n int cur = 1;\n\n for (int i = 0; i < nums.length - 1; i++)\n {\n if (nums[i] < nums[i + 1]) cur++;\n else\n {\n if (cur > max) max = cur;\n cur = 1;\n }\n } \n\n if (cur > max) max = cur;\n\n return max;\n }\n}\n```
1
0
['Array', 'Java']
0
longest-continuous-increasing-subsequence
Using sliding window + lagging pointer concept
using-sliding-window-lagging-pointer-con-aq09
Intuition\nUsing Sliding window + lagging pointer concept.\n\n# Approach\nWe need to find the cases for which we update the lagging pointer as we move our slidi
rahulthankachan
NORMAL
2023-10-21T18:35:31.208956+00:00
2023-10-21T18:35:31.208980+00:00
168
false
# Intuition\nUsing Sliding window + lagging pointer concept.\n\n# Approach\nWe need to find the cases for which we update the lagging pointer as we move our sliding window.\n- Bad case1: nums[i + 1] > nums[i]\n- Bad case2: when we have reached the end of the array.\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity:O(1)\n# Code\n```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n if (nums == null) return 0;\n int p1 = 0;\n int max = 0;\n for (int i = 0; i < nums.length; i++) {\n // Bad case when we update\n if (i + 1 == nums.length || nums[i + 1] <= nums[i]) {\n // max cal\n max = Math.max(i - p1 + 1, max);\n // update p1 pointer\n p1 = i + 1;\n }\n }\n return max;\n }\n}\n```
1
0
['Sliding Window', 'Java']
2
longest-continuous-increasing-subsequence
✅ [C++] EASY Solution || LIS+Slight Modification
c-easy-solution-lisslight-modification-b-i9g6
Just the Longest Increasing Subsequence Code+ Slight modification.\nWe need continuous LIS which means difference between adjacent index should be 1. That\'s it
The_Nitin
NORMAL
2023-07-31T01:30:02.881334+00:00
2023-07-31T01:31:03.706183+00:00
112
false
Just the ***Longest Increasing Subsequence Code+ Slight modification.***\nWe need ***continuous LIS*** which means difference between adjacent index should be 1. That\'s it \uD83D\uDE42\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int n=nums.size();\n vector<vector<int>>dp(n+1,vector<int>(n+1,0));\n for(int ind=n-1;ind>=0;ind--){\n for(int prev_ind=ind-1;prev_ind>=-1;prev_ind--){\n int len=dp[ind+1][prev_ind+1];\n if(prev_ind==-1 || nums[ind]>nums[prev_ind]) {\n if(ind-prev==1) // Here we add the condition, rest code is same as of LIS\n len= max(len,1+dp[ind+1][ind+1]);\n }\n dp[ind][prev_ind+1]=len;\n }\n }\n \n return dp[0][0];\n }\n};\n```\nThanks \nNitin Manoj
1
0
['Dynamic Programming']
0
longest-continuous-increasing-subsequence
Python short 1-liner. Functional programming.
python-short-1-liner-functional-programm-hso3
Approach\n1. For each adjacent pairwise numbers in nums check if nums_i < nums_{i + 1} to form a boolean array. (Useful to see bools as 1 and 0).\nlt_bools = st
darshan-as
NORMAL
2023-07-21T10:08:00.636627+00:00
2023-07-21T10:08:00.636657+00:00
912
false
# Approach\n1. For each adjacent `pairwise` numbers in `nums` check if $$nums_i < nums_{i + 1}$$ to form a boolean array. (Useful to see bools as 1 and 0).\n`lt_bools = starmap(lt, pairwise(nums))`\n\n2. Calculate `running_sums` on the array of bools and reset every time a `0` is found.\n`run_sums = accumulate(lt_bools, lambda a, x: a * x + 1, initial=1)`\n\n3. Return the `max(run_sums) + 1`\n\nExample:\n```python\nnums = [1, 3, 5, 4, 7, 2, 4, 5, 7, 9]\nlt_bools = [1, 1, 0, 1, 0, 1, 1, 1, 1]\nrun_sums = [1, 2, 3, 1, 2, 1, 2, 3, 4, 5] # Extra 1 added at the beginning\nlcis_len = 5\n```\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\nwhere, `n is length of nums`.\n\n# Code\n```python\nclass Solution:\n def findLengthOfLCIS(self, nums: list[int]) -> int:\n return max(accumulate(starmap(lt, pairwise(nums)), lambda a, x: a * x + 1, initial=1))\n\n\n```
1
0
['Array', 'Dynamic Programming', 'Prefix Sum', 'Python', 'Python3']
0
longest-continuous-increasing-subsequence
C++ solution | 87.72% time, 94.70% space | update max length on the fly
c-solution-8772-time-9470-space-update-m-ow4o
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# Co
photon_einstein
NORMAL
2023-04-14T15:37:14.680737+00:00
2023-04-14T15:37:14.680775+00:00
1,143
false
# 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 findLengthOfLCIS(vector<int>& nums);\n};\n/*********************************************************/\nint Solution::findLengthOfLCIS(vector<int>& nums) {\n int maxLength=1, length=1, i, size = nums.size();\n for (i = 1; i < size; ++i) {\n if (nums[i-1] < nums[i]) {\n ++length;\n if (length > maxLength) {\n maxLength = length;\n }\n } else {\n length = 1;\n }\n }\n return maxLength;\n}\n/*********************************************************/\n```
1
0
['C++']
1
longest-continuous-increasing-subsequence
JavaScript / TypeScript Solution
javascript-typescript-solution-by-plskz-re1f
Code\n\n\nExample\n\n\n// cur=1, ans=1\n\n// [1,3,5,4,7] 3 > 1\n// 0 1 2 3 4 < i=1\n\n// cur=2, ans=2\n\n// [1,3,5,4,7] 5 > 3\n// 0 1 2 3 4 < i=2\n\n// cur=
plskz
NORMAL
2023-03-30T14:28:18.737602+00:00
2023-03-30T14:28:18.737627+00:00
66
false
# Code\n\n<details>\n<summary>Example</summary>\n\n```\n// cur=1, ans=1\n\n// [1,3,5,4,7] 3 > 1\n// 0 1 2 3 4 < i=1\n\n// cur=2, ans=2\n\n// [1,3,5,4,7] 5 > 3\n// 0 1 2 3 4 < i=2\n\n// cur=3, ans=3\n\n// [1,3,5,4,7] 4 > 5 \n// 0 1 2 3 4 < i=3\n\n// cur=1, ans=3\n\n// [1,3,5,4,7] 7 > 4 \n// 0 1 2 3 4 < i=4\n\n// cur=2, ans=3\n```\n</details>\n\n\n```\nfunction findLengthOfLCIS(nums: number[]): number {\n let cur = 1;\n let ans = 1;\n\n for (let i = 1; i < nums.length; i++) {\n // if (nums[i] > nums[i - 1]) {\n // cur += 1\n // ans = Math.max(cur, ans)\n // } else {\n // cur = 1;\n // }\n\n // same above. using ternary operator\n cur = nums[i] > nums[i - 1] ? cur + 1 : 1\n ans = Math.max(cur, ans)\n }\n\n return ans\n};\n\n```\n\nUsing DP\n\n```\nfunction findLengthOfLCIS(nums: number[]): number {\n const dp = new Array(nums.length).fill(1)\n\n for (let i = 1; i < nums.length; i++) {\n if (nums[i] > nums[i - 1]) {\n dp[i] = dp[i - 1] + 1\n }\n }\n\n return Math.max(...dp)\n};\n```
1
0
['Dynamic Programming', 'TypeScript', 'JavaScript']
0
longest-continuous-increasing-subsequence
JavaScript easy single loop
javascript-easy-single-loop-by-pradeepsa-n6wi
Intuition\n Describe your first thoughts on how to solve this problem. \n increasing the counter by comparing elements in an array\n# Approach\n Describe you
PradeepSaravanau
NORMAL
2023-03-28T02:40:06.573225+00:00
2023-03-28T02:40:06.573261+00:00
46
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n increasing the counter by comparing elements in an array\n# Approach\n<!-- Describe your approach to solving the problem. -->\ncompare two elements nums[i] and nums[i-1], if i is greater we include it, so count++, if not we reset counter to 1 and count again for any better LCIS in the array.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findLengthOfLCIS = function (nums) {\n let count = 1;\n let max = 1;\n for (let i = 1; i < nums.length; i++) {\n if (nums[i - 1] < nums[i]) {\n count++;\n } else {\n count = 1;\n }\n max = Math.max(max, count);\n }\n return max;\n};\n```
1
0
['JavaScript']
0
longest-continuous-increasing-subsequence
2 DP APPROACH | C++ | BEATS 95% | O(N)
2-dp-approach-c-beats-95-on-by-kr_vishnu-91fr
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# 1st
kr_vishnu
NORMAL
2023-01-23T08:21:27.605491+00:00
2023-01-23T08:21:27.605521+00:00
464
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# 1st APPROACH: \n# Code\n```\nclass Solution {\npublic:\n int dp[10001];\n int solve(vector<int>& nums, int i, int n){\n if(i==n) return 0;\n if(dp[i] != -1) return dp[i];\n int k=i;\n while(k<n-1 && nums[k]<nums[k+1]){\n k++;\n }\n int cnt1=k-i+1;\n int cnt2=solve(nums, k+1, n);\n \n return dp[i]=max(cnt1, cnt2);\n }\n int findLengthOfLCIS(vector<int>& nums) {\n memset(dp, -1, sizeof(dp));\n return solve(nums, 0, nums.size());\n }\n};\n```\n# 2nd APPROACH: (TLE)\n# Code\n```\nclass Solution {\n int solveTab(vector<int>& nums, int n){ \n vector<vector<int>> dp(n+1, vector<int> (n+1, 0)); \n int ans=0;\n for(int curr=n-1; curr>=0; curr--){\n for(int prev=curr-1; prev>=-1; prev--){\n if(prev==-1 || (nums[curr] > nums[prev]))\n dp[curr][prev+1]=1+dp[curr+1][curr+1];\n \n ans=max(ans, dp[curr][prev+1]);\n }\n }\n return ans;\n }\npublic:\n \n int findLengthOfLCIS(vector<int>& nums) {\n return solveTab(nums,nums.size());\n }\n};\n```
1
0
['C++']
0
longest-continuous-increasing-subsequence
c++ | easy | fast
c-easy-fast-by-venomhighs7-dnfv
\n\n# Code\n\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n if(nums.size()<=1)return nums.size();\n int answer=1,coun
venomhighs7
NORMAL
2022-11-30T16:36:30.518967+00:00
2022-11-30T16:36:30.519018+00:00
1,068
false
\n\n# Code\n```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n if(nums.size()<=1)return nums.size();\n int answer=1,count=1;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]<nums[i+1]){\n count++;\n answer=max(answer,count);\n }\n else{\n count=1;\n }\n }\n return answer;\n }\n};\n```
1
0
['C++']
1
longest-continuous-increasing-subsequence
Two Simple Python Solutions
two-simple-python-solutions-by-deleted_u-arjz
\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n prev, cur, res = 0, 0, 0\n \n for n in nums:\n cur
deleted_user
NORMAL
2022-10-31T13:52:11.253591+00:00
2022-10-31T14:02:04.916584+00:00
787
false
```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n prev, cur, res = 0, 0, 0\n \n for n in nums:\n cur = cur + 1 if prev < n else 1\n res = max(res, cur)\n prev = n\n\n return res\n\nTime complexity: O(n)\nSpace complexity: O(1)\n```\n\n```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n n = len(nums)\n dp = [1] * n\n \n for i in range(1, n):\n if nums[i] > nums[i-1]:\n dp[i] = dp[i-1] + dp[i]\n \n return max(dp)\n\nTime complexity: O(n)\nSpace complexity: O(n)\n```
1
0
[]
0
longest-continuous-increasing-subsequence
Easy to understand
easy-to-understand-by-letmefindanother11-dkpd
\n int findLengthOfLCIS(vector<int>& nums) \n {\n int mx=0;\n int n=nums.size();\n int count=1;\n int i=0,j=1;\n if(n==
LetMeFindAnother111121itr
NORMAL
2022-09-07T16:48:44.773937+00:00
2022-09-07T16:48:44.773982+00:00
288
false
```\n int findLengthOfLCIS(vector<int>& nums) \n {\n int mx=0;\n int n=nums.size();\n int count=1;\n int i=0,j=1;\n if(n==1) return 1;\n \n while(j<n)\n {\n if(nums[i]<nums[j])\n {\n count++;\n i++;\n j++;\n mx=max(mx,count);\n }\n else\n {\n mx=max(mx,count);\n count=1;\n i++;\n j++;\n }\n }\n return mx;\n }\n```
1
0
['Two Pointers', 'C', 'C++']
0
longest-continuous-increasing-subsequence
C++ | 2 Ways | Brute Force vs Optimal
c-2-ways-brute-force-vs-optimal-by-gkara-mhzo
\n/*\n\tBrute Force\n*/\nint findLengthOfLCIS(vector<int>& nums) {\n\tint ans = 1;\n\tint i = 0;\n\twhile(i < nums.size()) {\n\t\tint m = 1;\n\t\tfor (int j = i
gkaran
NORMAL
2022-09-04T00:58:48.602678+00:00
2022-09-04T00:58:48.602788+00:00
351
false
```\n/*\n\tBrute Force\n*/\nint findLengthOfLCIS(vector<int>& nums) {\n\tint ans = 1;\n\tint i = 0;\n\twhile(i < nums.size()) {\n\t\tint m = 1;\n\t\tfor (int j = i + 1; j < nums.size(); ++j) {\n\t\t\tif (nums[j] > nums[j - 1]) {\n\t\t\t\tm++;\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans = max(ans, m);\n\t\ti += m;\n\t}\n\treturn ans;\n}\n\n/*\n\tOptimal\n*/\nint findLengthOfLCIS(vector<int>& nums) {\n\tint ans = 1;\n\tint count = 1;\n\tfor (int i = 1; i < nums.size(); ++i) {\n\t\tif (nums[i] > nums[i - 1]) {\n\t\t\tcount++;\n\t\t\tans = max(ans, count);\n\t\t} else {\n\t\t\tcount = 1;\n\t\t}\n\t}\n\treturn ans;\n}\n```
1
0
['C']
0
longest-continuous-increasing-subsequence
C++ super-easy understanding solution (non-sliding window approach)
c-super-easy-understanding-solution-non-2uapu
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) \n {\n if(nums.size() == 0) return 0;\n vector<int> dp(nums.size(), -1
macbookair
NORMAL
2022-07-05T06:49:44.224242+00:00
2022-07-09T20:26:27.988888+00:00
25
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) \n {\n if(nums.size() == 0) return 0;\n vector<int> dp(nums.size(), -1);\n for(int i=0; i<nums.size(); ++i)\n {\n if(dp[i] == -1)\n {\n dfs(nums, dp, i); \n }\n }\n int ret = 0;\n for(auto& v:dp)\n {\n ret = max(ret, v);\n cout << v <<endl;\n }\n return ret;\n }\n int dfs(const vector<int>& nums, vector<int>& dp, int i)\n {\n if(i==nums.size()-1)\n {\n dp[i] = 1;\n return dp[i];\n }\n \n if(nums[i+1] > nums[i])\n {\n if(dp[i+1] == -1)\n {\n dp[i] = max( 1 + dfs(nums, dp, i+1), dp[i]);\n }\n else\n {\n dp[i] = max(dp[i], 1 + dp[i+1]);\n }\n }\n else\n {\n dp[i] = 1;\n }\n return dp[i];\n }\n};\n```
1
0
['Dynamic Programming', 'Depth-First Search']
0
longest-continuous-increasing-subsequence
Java 1ms Easy Solution
java-1ms-easy-solution-by-varnit_gupta47-p2ey
\t\tint n=nums.length;\n int c=0;\n int maxx=0;\n for(int i=0;inums[i]){\n c++;\n maxx=Math.max(maxx,c);\n
Varnit_gupta47
NORMAL
2022-06-22T09:59:02.938931+00:00
2022-06-22T09:59:02.938982+00:00
72
false
\t\tint n=nums.length;\n int c=0;\n int maxx=0;\n for(int i=0;i<n-1;i++){\n if(nums[i+1]>nums[i]){\n c++;\n maxx=Math.max(maxx,c);\n }else{\n c=0;\n }\n }\n return maxx+1;\n
1
0
['Iterator']
1
longest-continuous-increasing-subsequence
✔️ Easy C++ Solution
easy-c-solution-by-soorajks2002-qody
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int curr=1, ans=1;\n for(int i=1; i<nums.size(); ++i){\n i
soorajks2002
NORMAL
2022-06-19T02:54:04.269047+00:00
2022-06-19T02:54:04.269074+00:00
263
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int curr=1, ans=1;\n for(int i=1; i<nums.size(); ++i){\n if(nums[i]>nums[i-1]) ++curr;\n else curr=1;\n ans = max(ans, curr);\n }\n return ans;\n }\n};\n```
1
0
['C', 'C++']
0
longest-continuous-increasing-subsequence
C++ Simple Solution
c-simple-solution-by-beast_paw-c00u
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int ans=0;\n int temp=1;\n for(int i=0;i<nums.size()-1;i++)\n
beast_paw
NORMAL
2022-05-21T14:01:13.252238+00:00
2022-05-21T14:01:13.252280+00:00
45
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int ans=0;\n int temp=1;\n for(int i=0;i<nums.size()-1;i++)\n {\n if(nums[i+1]>nums[i])\n temp++;\n else\n { \n ans=max(ans,temp);\n temp=1;\n }\n }\n ans=max(temp,ans);\n return ans;\n }\n};\n```
1
0
['C']
0
longest-continuous-increasing-subsequence
Very simple C++ solution.
very-simple-c-solution-by-hariom510-hqxh
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int count =1;\n int maxi =1;\n \n for(int i=0; i<nums.s
Hariom510
NORMAL
2022-03-26T11:09:25.143539+00:00
2022-03-26T11:09:25.143566+00:00
60
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int count =1;\n int maxi =1;\n \n for(int i=0; i<nums.size()-1; i++){\n if(nums[i+1] > nums[i]){\n count++;\n maxi = max(maxi, count); \n }\n else{\n count =1;\n }\n }\n return maxi;\n }\n};\n// Upvote please if you like it.\n```
1
0
['C']
0
longest-continuous-increasing-subsequence
6 lines solution | Python | DP | Self explanantory
6-lines-solution-python-dp-self-explanan-wrmw
\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n n = len( nums)\n d = [1 for i in range (n)]\n for i in range (
krunalk013
NORMAL
2022-02-26T09:35:51.314163+00:00
2022-02-26T09:35:51.314194+00:00
155
false
```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n n = len( nums)\n d = [1 for i in range (n)]\n for i in range (1,n):\n if nums[i] > nums[i-1]:\n d[i] += d[i-1]\n return max(d) \n```
1
0
['Dynamic Programming', 'Python']
0
longest-continuous-increasing-subsequence
C++ || EASY TO UNDERSTAND
c-easy-to-understand-by-easy_coder-2tuo
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector& nums) {\n int ans = 1;\n int n = nums.size();\n if(n == 1) return 1;\n
Easy_coder
NORMAL
2022-02-23T08:59:31.747943+00:00
2022-02-23T08:59:31.747981+00:00
78
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int ans = 1;\n int n = nums.size();\n if(n == 1) return 1;\n \n int i=0, j = 1;\n while( j < n ){\n if(nums[j] > nums[j-1]){\n ans = max(ans, (j - i + 1));\n j++;\n }\n else{\n i = j;\n j++;\n }\n }\n return ans;\n }\n};
1
0
['C']
0
longest-continuous-increasing-subsequence
O(n) time and O(1) space C++ Solution
on-time-and-o1-space-c-solution-by-lites-ulrn
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int result=0;\n int curr = nums[0];\n int count=1;\n if
liteshghute
NORMAL
2022-02-04T16:37:43.856284+00:00
2022-02-04T16:37:43.856313+00:00
57
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int result=0;\n int curr = nums[0];\n int count=1;\n if(nums.size()==1)\n return 1;\n if(nums.size()==0)\n return 0;\n for(int i=1; i<nums.size(); i++){\n if(nums[i]>curr)\n count+=1;\n else\n count=1;\n result = max(count,result);\n curr = nums[i];\n }\n return result;\n }\n};\n```
1
0
[]
0
longest-continuous-increasing-subsequence
rust windows
rust-windows-by-zakharovvi-aobo
\npub struct Solution {}\n\nimpl Solution {\n pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {\n let mut max = 0;\n let accum = nums\n
zakharovvi
NORMAL
2021-12-25T09:11:41.930426+00:00
2021-12-25T09:11:41.930493+00:00
115
false
```\npub struct Solution {}\n\nimpl Solution {\n pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {\n let mut max = 0;\n let accum = nums\n .windows(2)\n .fold(1, |accum, w| {\n if w[0] < w[1] {\n accum + 1\n } else {\n if accum > max {\n max = accum;\n }\n 1\n }\n });\n\n max.max(accum)\n }\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test() {\n assert_eq!(3, Solution::find_length_of_lcis(vec![1,3,5,4,7]));\n assert_eq!(1, Solution::find_length_of_lcis(vec![1]));\n assert_eq!(4, Solution::find_length_of_lcis(vec![4,3,1,2,3,4]));\n }\n}\n```
1
0
['Rust']
0
longest-continuous-increasing-subsequence
BEST SOLUTION C++
best-solution-c-by-harryson03-lpsy
class Solution {\npublic:\n int findLengthOfLCIS(vector& nums) {\n int n=nums.size();\n vectorcnt(n,1);\n int ans=1;\n for(int i=
harryson03
NORMAL
2021-11-26T15:58:03.431284+00:00
2021-11-26T15:58:03.431315+00:00
52
false
class Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int n=nums.size();\n vector<int>cnt(n,1);\n int ans=1;\n for(int i=1;i<n;i++)\n {\n if(nums[i]>nums[i-1])\n {\n cnt[i]=cnt[i-1]+1;\n }\n ans=max(ans,cnt[i]);\n }\n return ans;\n }\n};\n//PLEASE UPVOTE
1
0
[]
0
longest-continuous-increasing-subsequence
C++ | 98.89% | easy
c-9889-easy-by-omanandpandey-l8gh
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n \n int count = 0, i= 0, maxa=INT_MIN;\n \n for(
OmAnandPandey
NORMAL
2021-11-03T19:25:42.578772+00:00
2021-11-03T19:25:42.578812+00:00
150
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n \n int count = 0, i= 0, maxa=INT_MIN;\n \n for(int j = 0; j < nums.size(); j++)\n {\n if(j == nums.size()-1)\n {\n count = j-i+1;\n }\n else if(nums[j] >= nums[j+1])\n {\n count = j - i + 1;\n i = j+1;\n }\n maxa =max(maxa, count);\n }\n return maxa;\n }\n};\n```
1
0
['C']
0
longest-continuous-increasing-subsequence
Java, O(N) time, O(1) space, beat 99.8%
java-on-time-o1-space-beat-998-by-phung_-fqjj
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int index = 0;\n int ans = 1;\n while(index < nums.length) {\n
phung_manh_cuong
NORMAL
2021-11-03T05:40:59.216923+00:00
2021-11-03T05:40:59.216965+00:00
39
false
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int index = 0;\n int ans = 1;\n while(index < nums.length) {\n int base = index;\n while(index < nums.length-1 && nums[index] < nums[index+1]) index++;\n if(index == base) {\n index++;\n continue;\n }\n \n ans = Math.max(ans, index - base + 1);\n }\n \n return ans;\n }\n}
1
1
[]
0
longest-continuous-increasing-subsequence
Using sliding window of dynamic size easy c++ better than 99% in time
using-sliding-window-of-dynamic-size-eas-11j3
\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int i = 0;\n int ml = 1;\n int j = 1;\n for(j;j<nums.si
jainav_agarwal
NORMAL
2021-10-25T15:11:06.463492+00:00
2021-10-25T15:11:06.463536+00:00
169
false
```\nclass Solution {\npublic:\n int findLengthOfLCIS(vector<int>& nums) {\n int i = 0;\n int ml = 1;\n int j = 1;\n for(j;j<nums.size();j++){\n if(nums[j]<=nums[j-1]){\n ml = max(ml,j-i);\n i= j;\n }\n }\n if(nums[j-1]>nums[i])\n ml = max(ml,j-i);\n return ml;\n }\n};\n```
1
0
['C', 'Sliding Window', 'C++']
0
longest-continuous-increasing-subsequence
Easy JAVA Solution One Pass (On - time, O1 - space)
easy-java-solution-one-pass-on-time-o1-s-is42
\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int res = 0, temp = 1;\n\n for (int i = 1; i < nums.length; i++) {\n int curr = num
movsar
NORMAL
2021-09-21T21:02:10.329932+00:00
2021-09-21T21:02:10.329983+00:00
139
false
```\nclass Solution {\n public int findLengthOfLCIS(int[] nums) {\n int res = 0, temp = 1;\n\n for (int i = 1; i < nums.length; i++) {\n int curr = nums[i];\n int prev = nums[i-1];\n\n if (prev < curr) {\n temp++;\n } else {\n res = Math.max(res, temp);\n temp = 1;\n }\n }\n return Math.max(res, temp);\n }\n}\n```
1
0
['Java']
0
longest-continuous-increasing-subsequence
Python3 solution
python3-solution-by-florinnc1-d6ok
\'\'\'\n\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n msf = 0 # maxim so far\n meh = 1 # maxim ending here\n
FlorinnC1
NORMAL
2021-09-18T12:48:18.116814+00:00
2021-09-18T12:48:18.116845+00:00
251
false
\'\'\'\n```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n msf = 0 # maxim so far\n meh = 1 # maxim ending here\n n = len(nums)\n if n == 1: return 1\n last = nums[0]\n for i in range(1, n):\n if nums[i] > last:\n last = nums[i]\n meh += 1\n else:\n meh = 1\n last = nums[i] \n if msf < meh:\n msf = meh\n return msf\n \n```\n\'\'\'
1
0
['Python', 'Python3']
0
longest-continuous-increasing-subsequence
python3 stack fast easy solution
python3-stack-fast-easy-solution-by-bich-hekc
\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n stack = [nums[0]]\n ret = 1\n for i in range(1, len(nums)):\n
bichengwang
NORMAL
2021-09-18T01:42:23.981506+00:00
2021-09-21T05:51:00.316561+00:00
163
false
```\nclass Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:\n stack = [nums[0]]\n ret = 1\n for i in range(1, len(nums)):\n if stack and stack[-1] >= nums[i]: stack.clear()\n stack.append(nums[i])\n ret = max(ret, len(stack))\n return ret\n```
1
0
['Stack', 'Python', 'Python3']
0
department-highest-salary
Three accpeted solutions
three-accpeted-solutions-by-kent-huang-nmao
SELECT D.Name AS Department ,E.Name AS Employee ,E.Salary \n FROM\n \tEmployee E,\n \t(SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY De
kent-huang
NORMAL
2015-01-22T01:01:44+00:00
2018-10-16T16:15:03.493819+00:00
58,694
false
SELECT D.Name AS Department ,E.Name AS Employee ,E.Salary \n FROM\n \tEmployee E,\n \t(SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY DepartmentId) T,\n \tDepartment D\n WHERE E.DepartmentId = T.DepartmentId \n AND E.Salary = T.max\n AND E.DepartmentId = D.id\n\n SELECT D.Name,A.Name,A.Salary \n FROM \n \tEmployee A,\n \tDepartment D \n WHERE A.DepartmentId = D.Id \n AND NOT EXISTS \n (SELECT 1 FROM Employee B WHERE B.Salary > A.Salary AND A.DepartmentId = B.DepartmentId) \n\n SELECT D.Name AS Department ,E.Name AS Employee ,E.Salary \n from \n \tEmployee E,\n \tDepartment D \n WHERE E.DepartmentId = D.id \n AND (DepartmentId,Salary) in \n (SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY DepartmentId)
187
3
[]
34
department-highest-salary
🔥💯 [Pandas] Very simple Step by step Process (detailed)🔥💯
pandas-very-simple-step-by-step-process-a0gh7
\n# Approach\n Describe your approach to solving the problem. \nThe approach involves merging the DataFrames, grouping by department, and then finding the emplo
sriganesh777
NORMAL
2023-08-04T06:40:27.845868+00:00
2023-08-04T06:40:27.845906+00:00
15,377
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach involves merging the DataFrames, grouping by department, and then finding the employees with the highest salary within each group using the max function and boolean indexing. The function handles empty table scenarios and correctly renames the columns as specified.\n\n# Detailed procedure\n- Check if either the employee or department DataFrame is empty. If either of them is empty, return an empty DataFrame with the column names [\'Department\', \'Employee\', \'Salary\'].\n```\n if employee.empty or department.empty:\n return pd.DataFrame(columns=[\'Department\',\'Employee\', \'Salary\'])\n```\n- Merge the employee and department DataFrames on \'departmentId\' and \'id\' columns, respectively, using the merge function.\n```\n merged_df = employee.merge(department, left_on=\'departmentId\', right_on=\'id\', suffixes=(\'_employee\', \'_department\'))\n```\n- Use the groupby function to group data in merged_df by \'departmentId\' and apply a lambda function to find employees with the highest salary in each group.\n```\n highest_salary_df = merged_df.groupby(\'departmentId\').apply(lambda x: x[x[\'salary\'] == x[\'salary\'].max()])\n```\n- Reset the index of highest_salary_df to remove the group labels and obtain a flat DataFrame.\n```\n highest_salary_df = highest_salary_df.reset_index(drop=True)\n```\n- Select the required columns \'name_department\', \'name_employee\', and \'salary\' from highest_salary_df to get the department name, employee name, and salary of employees with the highest salary in each department.\n```\n result_df = highest_salary_df[[\'name_department\', \'name_employee\', \'salary\']]\n```\n- Rename the columns of the resulting DataFrame to [\'Department\', \'Employee\', \'Salary\'] as specified.\n```\n result_df.columns = [\'Department\',\'Employee\', \'Salary\']\n```\n- Return the resulting DataFrame result_df containing employees with the highest salary in each department.\n\n\n\n# Code\n```\nimport pandas as pd\n\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:\n if employee.empty or department.empty:\n return pd.DataFrame(columns=[\'Department\',\'Employee\', \'Salary\'])\n \n # Merge the employee and department DataFrames on \'departmentId\' and \'id\' columns\n merged_df = employee.merge(department, left_on=\'departmentId\', right_on=\'id\', suffixes=(\'_employee\', \'_department\'))\n \n # Use groupby to group data by \'departmentId\' and apply a lambda function to get employees with highest salary in each group\n highest_salary_df = merged_df.groupby(\'departmentId\').apply(lambda x: x[x[\'salary\'] == x[\'salary\'].max()])\n \n # Drop the duplicate \'departmentId\' column and reset the index\n highest_salary_df = highest_salary_df.reset_index(drop=True)\n \n # Select the required columns and return the result\n result_df = highest_salary_df[[\'name_department\', \'name_employee\', \'salary\']]\n \n # Rename the columns as specified\n result_df.columns = [\'Department\',\'Employee\', \'Salary\']\n \n return result_df\n```\n\n# Please upvote the solution which motivates me to share high quality solutions like this \uD83E\uDD7A Thank You \u2764\uFE0F.
153
0
['Pandas']
9
department-highest-salary
✅ 100% EASY || FAST 🔥|| CLEAN SOLUTION 🌟
100-easy-fast-clean-solution-by-kartik_k-fj1u
Code\n\n/* Write your PL/SQL query statement below */\nSELECT DEPT.name AS Department, EMP.name AS Employee, EMP.salary AS \n\nSalary FROM Department DEPT, Empl
kartik_ksk7
NORMAL
2023-07-28T06:37:07.250031+00:00
2023-08-05T05:56:21.328317+00:00
21,928
false
# Code\n```\n/* Write your PL/SQL query statement below */\nSELECT DEPT.name AS Department, EMP.name AS Employee, EMP.salary AS \n\nSalary FROM Department DEPT, Employee EMP WHERE\n\nEMP.departmentId = DEPT.id AND (EMP.departmentId, salary) IN \n\n(SELECT departmentId, MAX (salary) FROM Employee GROUP BY \n\ndepartmentId)\n```\nIF THIS WILL BE HELPFUL TO YOU,PLEASE UPVOTE !\n\n![5kej8w.jpg](https://assets.leetcode.com/users/images/c29d80c7-fd85-4816-8171-ebf71ef130fa_1690526222.9120727.jpeg)\n\n\n
139
0
['Database', 'MySQL', 'Oracle', 'MS SQL Server']
11
department-highest-salary
Solution with Detail Explanation (Easy to Understand)
solution-with-detail-explanation-easy-to-80wr
Please upvote Me ^ Thanks.\nIT IS SIMPLE \n\nfirst identify highest salary by \nSELECT departmentId,MAX(salary) FROM Employee GROUP BY departmentId\n\nThen JOIN
Prabal_Nair
NORMAL
2022-08-21T06:14:44.757748+00:00
2022-08-21T06:14:44.757782+00:00
22,880
false
**Please upvote Me ^ Thanks.**\nIT IS SIMPLE \n\nfirst identify highest salary by \n`SELECT departmentId,MAX(salary) FROM Employee GROUP BY departmentId`\n\nThen JOIN both table by\n`SELECT Department.name AS Department ,Employee.name AS Employee, Employee.salary\nFROM Department JOIN Employee ON Employee.departmentId=Department.id `\n\nThen put Condition by\n`WHERE(departmentId, salary) IN\n(SELECT departmentId,MAX(salary) FROM Employee GROUP BY departmentId) ;`\n\n**Code**\n\n```\nSELECT Department.name AS Department ,Employee.name AS Employee, Employee.salary\nFROM Department JOIN Employee ON Employee.departmentId=Department.id \nWHERE(departmentId, salary) IN\n(SELECT departmentId,MAX(salary) FROM Employee GROUP BY departmentId) ;\n```
120
0
['MySQL']
7
department-highest-salary
Simple solution, easy to understand
simple-solution-easy-to-understand-by-le-rw6h
SELECT dep.Name as Department, emp.Name as Employee, emp.Salary \n from Department dep, Employee emp \n where emp.DepartmentId=dep.Id \n and emp.Salary
lemonxixi
NORMAL
2015-08-27T01:00:56+00:00
2018-10-06T06:59:03.531712+00:00
26,104
false
SELECT dep.Name as Department, emp.Name as Employee, emp.Salary \n from Department dep, Employee emp \n where emp.DepartmentId=dep.Id \n and emp.Salary=(Select max(Salary) from Employee e2 where e2.DepartmentId=dep.Id)
83
6
[]
12
department-highest-salary
Sharing my simple solution
sharing-my-simple-solution-by-mahdy-n321
Select Department.Name, emp1.Name, emp1.Salary from \n Employee emp1 join Department on emp1.DepartmentId = Department.Id\n where emp1.Salary = (Select Ma
mahdy
NORMAL
2015-02-09T02:59:59+00:00
2018-10-06T06:46:47.818894+00:00
10,052
false
Select Department.Name, emp1.Name, emp1.Salary from \n Employee emp1 join Department on emp1.DepartmentId = Department.Id\n where emp1.Salary = (Select Max(Salary) from Employee emp2 where emp2.DepartmentId = emp1.DepartmentId);
33
3
[]
5
department-highest-salary
Pandas vs SQL | Elegant & Short | All 30 Days of Pandas solutions ✅
pandas-vs-sql-elegant-short-all-30-days-eysb8
Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\nPython []\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFra
Kyrylo-Ktl
NORMAL
2023-08-05T13:00:46.825759+00:00
2023-08-06T16:57:05.900946+00:00
4,647
false
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```Python []\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:\n return employee.merge(\n department, left_on=\'departmentId\', right_on=\'id\', suffixes=(\'_employee\', \'_department\')\n ).groupby(\n \'departmentId\'\n ).apply(\n lambda x: x[x[\'salary\'] == x[\'salary\'].max()]\n ).reset_index(drop=True)[\n [\'name_department\', \'name_employee\', \'salary\']\n ].rename(columns={\n \'name_department\': \'Department\',\n \'name_employee\': \'Employee\',\n \'salary\': \'Salary\',\n })\n```\n```SQL []\nWITH cte AS (\n SELECT d.name AS department,\n e.name AS employee,\n e.salary,\n max(e.salary) OVER (PARTITION BY d.id) AS max_salary\n FROM Employee e\n JOIN Department d\n ON e.departmentId = d.id\n)\nSELECT department,\n employee,\n salary\n FROM cte\n WHERE salary = max_salary;\n```\n\n# Important!\n###### If you like the solution or find it useful, feel free to **upvote** for it, it will support me in creating high quality solutions)\n\n# 30 Days of Pandas solutions\n\n### Data Filtering \u2705\n- [Big Countries](https://leetcode.com/problems/big-countries/solutions/3848474/pandas-elegant-short-1-line/)\n- [Recyclable and Low Fat Products](https://leetcode.com/problems/recyclable-and-low-fat-products/solutions/3848500/pandas-elegant-short-1-line/)\n- [Customers Who Never Order](https://leetcode.com/problems/customers-who-never-order/solutions/3848527/pandas-elegant-short-1-line/)\n- [Article Views I](https://leetcode.com/problems/article-views-i/solutions/3867192/pandas-elegant-short-1-line/)\n\n\n### String Methods \u2705\n- [Invalid Tweets](https://leetcode.com/problems/invalid-tweets/solutions/3849121/pandas-elegant-short-1-line/)\n- [Calculate Special Bonus](https://leetcode.com/problems/calculate-special-bonus/solutions/3867209/pandas-elegant-short-1-line/)\n- [Fix Names in a Table](https://leetcode.com/problems/fix-names-in-a-table/solutions/3849167/pandas-elegant-short-1-line/)\n- [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails/solutions/3849177/pandas-elegant-short-1-line/)\n- [Patients With a Condition](https://leetcode.com/problems/patients-with-a-condition/solutions/3849196/pandas-elegant-short-1-line-regex/)\n\n\n### Data Manipulation \u2705\n- [Nth Highest Salary](https://leetcode.com/problems/nth-highest-salary/solutions/3867257/pandas-elegant-short-1-line/)\n- [Second Highest Salary](https://leetcode.com/problems/second-highest-salary/solutions/3867278/pandas-elegant-short/)\n- [Department Highest Salary](https://leetcode.com/problems/department-highest-salary/solutions/3867312/pandas-elegant-short-1-line/)\n- [Rank Scores](https://leetcode.com/problems/rank-scores/solutions/3872817/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n- [Delete Duplicate Emails](https://leetcode.com/problems/delete-duplicate-emails/solutions/3849211/pandas-elegant-short/)\n- [Rearrange Products Table](https://leetcode.com/problems/rearrange-products-table/solutions/3849226/pandas-elegant-short-1-line/)\n\n\n### Statistics \u2705\n- [The Number of Rich Customers](https://leetcode.com/problems/the-number-of-rich-customers/solutions/3849251/pandas-elegant-short-1-line/)\n- [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i/solutions/3872719/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n- [Count Salary Categories](https://leetcode.com/problems/count-salary-categories/solutions/3872801/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n\n\n### Data Aggregation \u2705\n- [Find Total Time Spent by Each Employee](https://leetcode.com/problems/find-total-time-spent-by-each-employee/solutions/3872715/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n- [Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i/solutions/3863223/pandas-elegant-short-1-line/)\n- [Number of Unique Subjects Taught by Each Teacher](https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher/solutions/3863239/pandas-elegant-short-1-line/)\n- [Classes More Than 5 Students](https://leetcode.com/problems/classes-more-than-5-students/solutions/3863249/pandas-elegant-short/)\n- [Customer Placing the Largest Number of Orders](https://leetcode.com/problems/customer-placing-the-largest-number-of-orders/solutions/3863257/pandas-elegant-short-1-line/)\n- [Group Sold Products By The Date](https://leetcode.com/problems/group-sold-products-by-the-date/solutions/3863267/pandas-elegant-short-1-line/)\n- [Daily Leads and Partners](https://leetcode.com/problems/daily-leads-and-partners/solutions/3863279/pandas-elegant-short-1-line/)\n\n\n### Data Aggregation \u2705\n- [Actors and Directors Who Cooperated At Least Three Times](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/solutions/3863309/pandas-elegant-short/)\n- [Replace Employee ID With The Unique Identifier](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/solutions/3872822/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n- [Students and Examinations](https://leetcode.com/problems/students-and-examinations/solutions/3872699/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n- [Managers with at Least 5 Direct Reports](https://leetcode.com/problems/managers-with-at-least-5-direct-reports/solutions/3872861/pandas-elegant-short/)\n- [Sales Person](https://leetcode.com/problems/sales-person/solutions/3872712/pandas-elegant-short-1-line-all-30-days-of-pandas-solutions/)\n
32
0
['Python', 'Python3', 'MySQL', 'Pandas']
2
department-highest-salary
GROUP BY HAVING not working for multiple highest salary, why?
group-by-having-not-working-for-multiple-nap2
SELECT b.Name as Department, a.Name as Employee, a.Salary\nFROM Employee a\nJOIN Department b\nON a.DepartmentId = b.Id\nGROUP BY Department\nHAVING a.Salary =
gogopink
NORMAL
2015-01-23T23:44:30+00:00
2015-01-23T23:44:30+00:00
7,388
false
`SELECT b.Name as Department, a.Name as Employee, a.Salary\nFROM Employee a\nJOIN Department b\nON a.DepartmentId = b.Id\nGROUP BY Department\nHAVING a.Salary = max(a.Salary)`\n\nThis way it was not able to return multiple rows with same highest salary. I can't figure why, please help!
27
0
[]
7
department-highest-salary
MySQL partition by with join solution with explaination
mysql-partition-by-with-join-solution-wi-khlg
\nSELECT b.Name AS Department, a.Name AS Employee, Salary FROM\n(SELECT *, MAX(Salary) OVER(PARTITION BY DepartmentId) AS max_val\nFROM Employee) a\nJOIN Depart
lianj
NORMAL
2020-05-14T14:13:37.703535+00:00
2020-05-14T14:13:37.703572+00:00
3,139
false
```\nSELECT b.Name AS Department, a.Name AS Employee, Salary FROM\n(SELECT *, MAX(Salary) OVER(PARTITION BY DepartmentId) AS max_val\nFROM Employee) a\nJOIN Department b\nON a.DepartmentId = b.Id\nWHERE Salary = max_val;\n```\nLogic here: add a column to the original Employee table of max salary within that department (that is what over partition by do)\nThen we select the ones that match max with its value to filter out the people with max salary of his / her department\nThen we join on the Department table to get the require information
26
0
['MySQL']
1
department-highest-salary
184: Solution with step by step explanation
184-solution-with-step-by-step-explanati-u02y
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nLet\'s go through the steps:\n\nJoin the Employee and Department tables o
Marlen09
NORMAL
2023-02-21T14:00:25.035894+00:00
2023-02-21T14:00:25.035942+00:00
12,662
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nLet\'s go through the steps:\n\nJoin the Employee and Department tables on the departmentId column to get the name of the department for each employee.\nUse a subquery to get the maximum salary for each department. The subquery first groups the employees by departmentId, and then gets the maximum salary for each group using the MAX function.\nJoin the result of the subquery with the Employee table on the departmentId and salary columns to get the employees who have the maximum salary for their department.\nSelect the Department, Employee, and Salary columns from the result.\nThis query will return the department name, employee name, and their salary for each department where at least one employee has the highest salary. The result will be ordered by department name, but the order of the rows within each department is not specified.\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\nTo find the employees who have the highest salary in each of the departments, we can use a subquery to get the maximum salary for each department, and then join it with the employee table to get the employees who have the maximum salary for their department.\n\nHere\'s the SQL query:\n\n```\nSELECT d.name AS Department, e.name AS Employee, e.salary AS Salary\nFROM Employee e\nJOIN Department d ON e.departmentId = d.id\nWHERE (e.departmentId, e.salary) IN\n (SELECT departmentId, MAX(salary)\n FROM Employee\n GROUP BY departmentId)\n\n```
23
0
['Database', 'MySQL']
7
department-highest-salary
Why cannot we just use max() with group by?
why-cannot-we-just-use-max-with-group-by-rzj0
select D.name as Department, E.name as Employee, max(salary) as Salary \n from Employee E , Department D \n where E.DepartmentId = D.Id \n
markwithk
NORMAL
2015-05-07T15:49:05+00:00
2015-05-07T15:49:05+00:00
6,895
false
select D.name as Department, E.name as Employee, max(salary) as Salary \n from Employee E , Department D \n where E.DepartmentId = D.Id \n group by D.id\n\nI tried to use something like this, but it did not pass. When two departments has the same max salary, it only outputs one row.\n\nHowever, this is not how it works in my local mysql.\n\nWhy is this wrong?
23
0
[]
14
department-highest-salary
simple and easy solution || MySQL
simple-and-easy-solution-mysql-by-shishi-egxo
\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook
shishirRsiam
NORMAL
2024-09-20T19:38:01.379613+00:00
2024-09-20T19:38:01.379637+00:00
6,216
false
\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n# Code\n```mysql []\nselect dp.name as Department, em.name as Employee, em.salary\nfrom Employee as em join Department as dp \non em.departmentId = dp.id \nwhere em.salary = ( select max(salary) from Employee where departmentId = dp.id )\n```
21
0
['Database', 'MySQL']
6
department-highest-salary
95% beats || MySQL solution
95-beats-mysql-solution-by-im_obid-ede4
\n# Code\n\nselect Department,e.name as Employee,e.salary as Salary \nfrom employee e,\n(\n select d.id department_id,d.name as Department,max(e.salary) as m
im_obid
NORMAL
2023-01-08T12:17:30.989840+00:00
2023-01-08T12:17:30.989880+00:00
7,705
false
\n# Code\n```\nselect Department,e.name as Employee,e.salary as Salary \nfrom employee e,\n(\n select d.id department_id,d.name as Department,max(e.salary) as max \n from department d left join employee e \n on d.id=e.departmentId \n group by d.id\n) as MaxSalaries \nwhere e.departmentId=department_id and e.salary = max;\n```\n\n```\nplease upvote, if you find it useful\n```
21
0
['MySQL']
0
department-highest-salary
[Pandas] 3-line solution, beats 90%
pandas-3-line-solution-beats-90-by-dzhan-x1el
Approach\n Describe your approach to solving the problem. \nWe could do this using a series of group-by, apply and merge operations, but we can do it quickly ut
dzhang2324
NORMAL
2023-08-08T05:24:48.053677+00:00
2023-08-08T05:25:18.534499+00:00
1,913
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe could do this using a series of group-by, apply and merge operations, but we can do it quickly utilizing group-by and transform. Documentation is here: https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.transform.html\n\nIf you can\'t really understand the documentation (I couldn\'t), using transform in conjunction with a group-by operation in this situation is (informally)\n1) Performing the group-by operation specified (in this case, grouping by department).\n2) Calling [\'Salary\'] is extracting the salary series while maintaing the group-by information.\n3) .transform(max) is taking the maximum of salaries by group, and converting it back into a series of the same length that preserves indexes from merged_df. In this context, it returns a series of salaries where each entry is the maximum salary in a particular department, and entries are duplicated and arranged such that the order matches up with each observation in the original dataframe (merged_df). Intuitively, if you added this series to the dataframe, it\'s like adding an attribute to each individual which tells us the highest salary in their department.\n\nIn the end, we use this series to filter for the rows in the orignal dataframe which have the maximum salary. Amazingly, it accounts for ties in the maximum salary due to how we are able to filter using this series. \n\n# Code\n```\nimport pandas as pd\n\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:\n #First, we merge the employee and department dataframes \n #using an inner join (default for merge)\n merged_df = employee.merge(department, left_on = \'departmentId\', right_on = \'id\')\n\n #Second, we rename the columns \n #and take only the department, employee, and salary columns\n merged_df = merged_df.rename(columns = {\'name_x\': \'Employee\', \'name_y\': \'Department\', \'salary\': \'Salary\'})[[\'Department\', \'Employee\', \'Salary\']]\n \n return merged_df[merged_df[\'Salary\'] == merged_df.groupby(\'Department\')[\'Salary\'].transform(max)]\n```
20
0
['Pandas']
3
department-highest-salary
MySQL solution using join
mysql-solution-using-join-by-yashkumarjh-rvj5
\nSELECT D.NAME AS DEPARTMENT,\nE.NAME AS EMPLOYEE,\nE.SALARY\nFROM EMPLOYEE E\nJOIN DEPARTMENT D ON \nE.DEPARTMENTID = D.ID\nWHERE SALARY = (SELECT MAX(SALARY)
yashkumarjha
NORMAL
2022-06-17T17:42:24.349786+00:00
2022-06-17T17:42:48.756149+00:00
3,120
false
```\nSELECT D.NAME AS DEPARTMENT,\nE.NAME AS EMPLOYEE,\nE.SALARY\nFROM EMPLOYEE E\nJOIN DEPARTMENT D ON \nE.DEPARTMENTID = D.ID\nWHERE SALARY = (SELECT MAX(SALARY) FROM EMPLOYEE WHERE D.ID = EMPLOYEE.DEPARTMENTID);\n```\n\nPlease upvote if you find it useful.
19
1
['MySQL']
2
department-highest-salary
A simple solution use one join
a-simple-solution-use-one-join-by-zzhang-ucgi
select d.Name Department, e.Name Employee, Salary\nfrom Department d join Employee e on d.Id=e.DepartmentId\nwhere (Salary,d.id) in (select max(Salary),Departme
zzhang2222
NORMAL
2016-05-16T05:13:11+00:00
2016-05-16T05:13:11+00:00
2,463
false
select d.Name Department, e.Name Employee, Salary\nfrom Department d join Employee e on d.Id=e.DepartmentId\nwhere (Salary,d.id) in (select max(Salary),DepartmentId from Employee group by DepartmentId);
16
1
[]
0
department-highest-salary
Highest Salaries in Every Department!
highest-salaries-in-every-department-by-sqsui
Intuition:We have two tables: one with employee details and one with department details. Our task is to find the highest-paid employee in each department. This
NoobML
NORMAL
2025-03-04T12:04:25.799813+00:00
2025-03-04T12:04:25.799813+00:00
1,942
false
### Intuition: We have two tables: one with employee details and one with department details. Our task is to find the highest-paid employee in each department. This seems like a straightforward problem of **grouping employees by department** and then finding the **maximum salary** within each group. ### Approach: 1. **Merging the DataFrames**: We start by merging the `employee` and `department` DataFrames on the department ID. This way, we can link each employee to their respective department and get both the employee and department information together. - The `merge()` function is used here because it allows us to combine two tables based on a common key (in this case, `departmentId` and `id`). 2. **Finding the highest salary**: Once the two DataFrames are merged, we need to find the highest salary for each department. - To do this, we use the `groupby('departmentId')['salary'].transform('max')`. - `groupby('departmentId')` groups the data by department. - `transform('max')` finds the maximum salary in each group (department) and **repeats** that maximum salary for every employee in the department. This makes it easy to compare each employee's salary with the highest salary in their department. 3. **Filtering the Data**: Now that we know the highest salary for each department, we can filter the employees whose salary matches the highest salary using: ```python merged.loc[merged.groupby('departmentId')['salary'].transform('max') == merged['salary']] ``` - This filters out all employees except the ones with the highest salary in their department. 4. **Renaming the Columns**: After filtering the data, we select the columns we need (`Employee`, `Salary`, and `Department`) and rename them to match the desired output. - `name_x` is the employee's name from the `employee` table, and `name_y` is the department's name from the `department` table. We rename these columns to `Employee` and `Department`, respectively. 5. **Returning the Result**: Finally, we return the filtered DataFrame with the selected and renamed columns. ### Why use `groupby()` and `transform('max')`: - **`groupby()`**: This is a fundamental operation when dealing with group-specific operations like "maximum salary per department." By grouping the data based on `departmentId`, we can perform operations like finding the maximum salary for each department. - **`transform('max')`**: This is key because it doesn't just calculate the maximum salary for each department once and return a single value, it **repeats** the maximum salary for every employee in the group. This is super useful because it allows us to compare every employee's salary to the maximum salary of their department without losing the structure of the DataFrame. If we used `agg('max')`, we would get a single row per department showing the maximum salary, but that wouldn't allow us to easily filter out the employees who have that maximum salary. With `transform('max')`, we can keep the same number of rows as the original DataFrame, making the comparison much easier. ### Example: Let's use this approach with an example: #### Data: **Employee Table:** | id | name | salary | departmentId | |-----|-------|--------|--------------| | 1 | Joe | 70000 | 1 | | 2 | Jim | 90000 | 1 | | 3 | Henry | 80000 | 2 | | 4 | Sam | 60000 | 2 | | 5 | Max | 90000 | 1 | **Department Table:** | id | name | |-----|-------| | 1 | IT | | 2 | Sales | #### Merged DataFrame: | id | name_x | salary | departmentId | id_y | name_y | |-----|--------|--------|--------------|------|--------| | 1 | Joe | 70000 | 1 | 1 | IT | | 2 | Jim | 90000 | 1 | 1 | IT | | 3 | Henry | 80000 | 2 | 2 | Sales | | 4 | Sam | 60000 | 2 | 2 | Sales | | 5 | Max | 90000 | 1 | 1 | IT | #### After Filtering for Highest Salary: | Department | Employee | Salary | |------------|----------|--------| | IT | Jim | 90000 | | IT | Max | 90000 | | Sales | Henry | 80000 | ### Complexity: - **Time Complexity**: - Merging two DataFrames with `merge()` takes **O(n)**, where `n` is the total number of rows in the resulting DataFrame. - `groupby()` and `transform('max')` also take **O(n)** because it processes each row individually. - So, the overall **time complexity is O(n)**. - **Space Complexity**: - We are storing the merged DataFrame and the filtered result. The space complexity is mainly dependent on the size of the DataFrame, so it’s **O(n)**. ### Code: ```pythondata [] import pandas as pd def department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame: # Merging the employee and department DataFrames based on departmentId merged = employee.merge(department, left_on='departmentId', right_on='id', how='left') # Filtering employees whose salary equals the highest salary in their department highest_salary = merged.loc[merged.groupby('departmentId')['salary'].transform('max') == merged['salary']] # Renaming the columns to match the output format result = highest_salary[['name_x', 'salary', 'name_y']].rename(columns={ 'name_y': 'Department', # department name column 'name_x': 'Employee', # employee name column 'salary': 'Salary' # salary column }) # Returning the final result in the desired order return result[['Department', 'Employee', 'Salary']] ``` ![upvote.jpeg](https://assets.leetcode.com/users/images/0eecd514-45b3-478b-ada6-25184cc54507_1741089657.4374201.jpeg)
15
0
['Pandas']
0
department-highest-salary
pandas || 3 lines, merge and groupby
pandas-3-lines-merge-and-groupby-by-spau-d3gb
\nimport pandas as pd\n\ndef department_highest_salary(employee : pd.DataFrame, \n department: pd.DataFrame) -> pd.DataFrame:\n\n
Spaulding_
NORMAL
2024-05-14T05:59:24.343439+00:00
2024-05-14T05:59:24.343469+00:00
1,532
false
```\nimport pandas as pd\n\ndef department_highest_salary(employee : pd.DataFrame, \n department: pd.DataFrame) -> pd.DataFrame:\n\n df = employee.merge(department, how=\'left\', \n left_on=\'departmentId\', right_on=\'id\')\n\n grp = df.groupby(\'name_y\')[\'salary\'] \n\n return df[df.salary == grp.transform(max)].iloc[:,[5,1,2]\n ].rename(columns = {\'name_x\': \'Employee\',\n \'salary\': \'Salary\',\n \'name_y\': \'Department\'}) \n```
15
0
['Pandas']
0
department-highest-salary
My best solution, super clean, no subquery, no Max
my-best-solution-super-clean-no-subquery-klis
Oftentimes those interviewers won't allow you to write subquery~\n\nReturn the highest salary for each department\n\n SELECT D.Name as Department, E.Name a
joy4fun
NORMAL
2017-10-27T23:11:04.180000+00:00
2017-10-27T23:11:04.180000+00:00
4,715
false
Oftentimes those interviewers won't allow you to write subquery~\n\n**Return the highest salary for each department**\n\n SELECT D.Name as Department, E.Name as Employee, E.Salary \n FROM Department D, Employee E, Employee E2 \n WHERE D.ID = E.DepartmentId and E.DepartmentId = E2.DepartmentId and \n E.Salary <= E2.Salary\n group by D.ID,E.Name having count(distinct E2.Salary) = 1\n order by D.Name desc\n\n**Follow up, return the secondary salary for each department**\n\n SELECT D.Name as Department, E.Name as Employee, E.Salary \n FROM Department D, Employee E, Employee E2 \n WHERE D.ID = E.DepartmentId and E.DepartmentId = E2.DepartmentId and \n E.Salary < E2.Salary\n group by D.ID,E.Name having count(distinct E2.Salary) = 1\n order by D.Name desc
14
0
[]
5
department-highest-salary
✅MySQL-2 Different Approach ||Easy understanding|| Beginner level|| Simple, Short ,Solution✅
mysql-2-different-approach-easy-understa-f9ev
Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n____\n\u27
Anos
NORMAL
2022-08-13T18:44:35.529967+00:00
2022-08-13T18:44:35.529993+00:00
2,044
false
***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome**.*\n______________________\n\u2705 **MySQL Code :**\n***Approach 1:***\n```\nSELECT t1.Department, t1.Employee, t1.Salary\nFROM(SELECT d.name AS Department, e.name AS Employee, e.salary AS Salary\n,RANK()OVER(PARTITION BY d.id ORDER BY salary DESC) AS rk\nFROM Department AS d\nJOIN Employee AS e ON E.departmentId = d.id) AS t1\nWHERE rk = 1\n```\n__________________________________\n***Approach 2***:\n\n```\nSELECT D.Name AS Department ,E.Name AS Employee ,E.Salary \nFROM\n\tEmployee E,\n\t(SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY DepartmentId) T,\n\tDepartment D\nWHERE E.DepartmentId = T.DepartmentId \n AND E.Salary = T.max\n AND E.DepartmentId = D.id\n```\n______________________\nIf you like the solution, please upvote \uD83D\uDD3C\nFor any questions, or discussions, comment below. \uD83D\uDC47\uFE0F
13
0
['MySQL']
1
department-highest-salary
Easy Solution. No joins. GROUP BY is enough. 916ms
easy-solution-no-joins-group-by-is-enoug-8kfd
select\n d.Name, e.Name, e.Salary\n from\n Department d,\n Employee e,\n (select MAX(Salary) as Salary, DepartmentId as DepartmentId from Employ
ruoyu_lei
NORMAL
2015-07-30T23:25:55+00:00
2015-07-30T23:25:55+00:00
4,001
false
select\n d.Name, e.Name, e.Salary\n from\n Department d,\n Employee e,\n (select MAX(Salary) as Salary, DepartmentId as DepartmentId from Employee GROUP BY DepartmentId) h\n where\n e.Salary = h.Salary and\n e.DepartmentId = h.DepartmentId and\n e.DepartmentId = d.Id;
12
6
[]
3
department-highest-salary
Find Highest Salary Employees by Department (Subquery & Join) in MySQL
find-highest-salary-employees-by-departm-655a
Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within e
d_sushkov
NORMAL
2024-08-06T01:41:07.230445+00:00
2024-08-06T01:41:07.230479+00:00
2,133
false
# Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within each department.\n- Filter employees to match this maximum salary.\n- Combine this information with department names to present the result.\n\n# Approach\n1. `Subquery for Maximum Salary`: Use a subquery to compute the maximum salary (MAX(Salary)) for each department by grouping the Employee table by departmentId.\n\n2. `Main Query Join`: Join the Employee and Department tables, filtering the results based on the subquery to ensure only employees with the maximum salary are selected.\n\n3. `Select Columns`: Ensure the final output includes the department name, employee name, and salary.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ \n`Subquery`: The subquery involves a GROUP BY operation which can be \n$$O(nlogn)$$ due to sorting.\n`Join and Filter`: The join and filtering operations are generally $$O(n)$$, assuming indexes are in place.\n\n- Space complexity: $$O(n)$$ space required for intermediate result storage and the final join operation grows linearly with the number of rows in the tables.\n\n# Code\n```\n# Write your MySQL query statement below\nSELECT \n Department.name AS Department, \n Employee.name AS Employee, \n Salary\nFROM \n Employee\nJOIN \n Department \n ON Department.id = Employee.departmentId\nWHERE \n (Employee.departmentId, Salary) IN (\n SELECT \n departmentId, \n MAX(Salary) \n FROM \n Employee \n GROUP BY \n departmentId\n );\n```
11
0
['Database', 'MySQL']
0
department-highest-salary
✅Easiest Basic SQL Solution wiith table explanation( No advance)✅.
easiest-basic-sql-solution-wiith-table-e-xsmx
Explanation :\nStep 1: INNER JOIN\nThe INNER JOIN combines the relevant rows from both tables based on the common departmentId and id columns.\n\nResult after t
dev_yash_
NORMAL
2024-01-29T14:31:56.623022+00:00
2024-01-29T14:34:29.927440+00:00
1,817
false
**Explanation :**\n*Step 1: INNER JOIN*\nThe INNER JOIN combines the relevant rows from both tables based on the common departmentId and id columns.\n\nResult after the INNER JOIN:\n![image](https://assets.leetcode.com/users/images/655e682b-7a61-46b7-b03d-1348cf2f0a0e_1706538575.3033745.png)\n\n*Step 2: WHERE Clause with Correlated Subquery*\nThe WHERE clause with the correlated subquery filters the rows to include only those where the (departmentId, salary) pair matches the maximum salary for each department.\n\nResult after applying the WHERE clause:\n![image](https://assets.leetcode.com/users/images/d6e17cdf-3abf-4939-8d6b-726a67896c21_1706538655.1041048.png)\n\n*Step 3: SELECT Clause*\nFinally, the SELECT clause specifies the columns to include in the output, with aliases for better readability.\n\nFinal Result:\n![image](https://assets.leetcode.com/users/images/114a0c83-62dc-4102-96e6-b14d216f9610_1706538704.3250432.png)\n\n\n\n\n**Query :**\n```\nSELECT \n Department.name AS Department,\n Employee.name AS Employee,\n Employee.salary AS Salary\nFROM \n Employee\nINNER JOIN \n Department ON Employee.departmentId = Department.id\nWHERE \n (Employee.departmentId, Employee.salary) IN \n (SELECT \n departmentId, MAX(salary) \n FROM \n Employee \n WHERE \n Employee.departmentId = Department.id\n GROUP BY \n departmentId)\n\n
11
0
['MySQL', 'MS SQL Server']
1
department-highest-salary
184. Department Highest Salary
184-department-highest-salary-by-spauldi-t0sd
```\nSELECT dept.Name AS Department, Employee.Name AS Employee, Salary\nFROM Employee\n\nINNER JOIN Department AS dept ON Employee.DepartmentId=dept.Id\n\nwhere
Spaulding_
NORMAL
2022-09-10T00:58:37.523160+00:00
2022-09-10T00:58:37.523195+00:00
1,433
false
```\nSELECT dept.Name AS Department, Employee.Name AS Employee, Salary\nFROM Employee\n\nINNER JOIN Department AS dept ON Employee.DepartmentId=dept.Id\n\nwhere (dept.Id, Salary) IN (SELECT DepartmentId, max(Salary)\n FROM Employee GROUP BY DepartmentId);
11
0
['MySQL']
0
department-highest-salary
[MySQL] Find the highest salary with `rank` function
mysql-find-the-highest-salary-with-rank-8bhfb
We can either group table by DepartmentId and get the highest salary with max(salary), or use window function rank. sql SELECT department, employee, salary FRO
rudy__
NORMAL
2020-10-29T01:21:00.610140+00:00
2020-10-29T01:21:00.610185+00:00
1,430
false
We can either group table by `DepartmentId` and get the highest salary with `max(salary)`, or use window function `rank`. ```sql SELECT department, employee, salary FROM ( SELECT a.name AS employee , b.name AS department , salary , RANK() OVER (PARTITION BY b.name ORDER BY a.salary DESC) AS dr FROM employee a JOIN department b ON a.departmentid = b.id ) tmp WHERE dr = 1 ```
11
0
[]
1
department-highest-salary
Share my simple query using >= ALL
share-my-simple-query-using-all-by-dottk-67ar
\nselect Department.Name as Department, e1.Name as Employee, Salary\nfrom Employee e1, Department\nwhere e1.DepartmentId = Department.Id \nand\nSalary >= ALL (s
dottkdomain
NORMAL
2015-04-22T14:06:00+00:00
2015-04-22T14:06:00+00:00
2,409
false
<PRE><CODE>\nselect Department.Name as Department, e1.Name as Employee, Salary\nfrom Employee e1, Department\nwhere e1.DepartmentId = Department.Id \nand\nSalary >= ALL (select Salary from Employee e2 where e2.DepartmentId = e1.DepartmentId);\n</CODE></PRE>
11
0
[]
0
department-highest-salary
MySQL Solution. Window
mysql-solution-window-by-kristina_m-r7kh
Code\nmysql []\n# Write your MySQL query statement below\nselect Department, Employee, Salary from (\n select \n dense_rank() over w as top,\n
Kristina_m
NORMAL
2024-08-25T12:45:24.077399+00:00
2024-08-25T12:45:24.077439+00:00
1,456
false
# Code\n```mysql []\n# Write your MySQL query statement below\nselect Department, Employee, Salary from (\n select \n dense_rank() over w as top,\n d.name as Department, \n e.name as Employee,\n salary as Salary\n from Employee e\n join Department d on e.departmentId = d.id\n window w as(\n partition by e.departmentId\n order by Salary desc\n )\n) x\nwhere top = 1;\n```\n\n![\u0421\u043D\u0438\u043C\u043E\u043A \u044D\u043A\u0440\u0430\u043D\u0430 2024-08-11 \u0432 15.09.52.png](https://assets.leetcode.com/users/images/e95f5b74-235c-4804-bd69-c083e6aec820_1724589908.1147046.png)\n
10
0
['MySQL']
0
department-highest-salary
Find Highest Salary Employees by Department (Merge & Filter) in Pandas
find-highest-salary-employees-by-departm-w3fw
Intuition\nTo solve the problem of finding the employee with the highest salary in each department using Pandas, start by combining the Employee and Department
d_sushkov
NORMAL
2024-08-06T01:41:58.698223+00:00
2024-08-06T01:41:58.698253+00:00
1,773
false
# Intuition\nTo solve the problem of finding the employee with the highest salary in each department using Pandas, start by combining the Employee and Department DataFrames. This will allow you to associate each employee with their respective department. Next, determine the highest salary within each department and filter the DataFrame to retain only those employees who have this maximum salary.\n\n# Approach\n1. `Merge DataFrames`: Use pd.merge() to combine the Employee and Department DataFrames based on the departmentId and id columns. This merge will add department names to the employee records.\n\n2. `Rename Columns`: Rename columns to make them more descriptive and select only the columns of interest: Department, Employee, and Salary.\n\n3. `Find Maximum Salary`: Use groupby() along with transform(max) to identify the maximum salary within each department. This will add a new column with the maximum salary for each employee\u2019s department.\n\n4. `Filter Results`: Filter the DataFrame to include only those rows where the employee\u2019s salary matches the maximum salary for their department.\n\n# Complexity\n- Time complexity:$$O(n)$$ for merging and filtering operations assuming efficient internal implementations.\n\n- Space complexity: $$O(n)$$ the space complexity is dominated by the size of the DataFrame, which grows linearly with the number of rows. The merged DataFrame and intermediate results are stored in memory.\n\n# Code\n```\nimport pandas as pd\n\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:\n # Merge the Employee and Department DataFrames based on the departmentId\n merged_df = pd.merge(employee, department, left_on=\'departmentId\', right_on=\'id\', how=\'left\')\n \n # Rename columns for clarity and select relevant columns\n merged_df = merged_df.rename(columns={\'name_x\': \'Employee\', \'name_y\': \'Department\', \'salary\': \'Salary\'})[[\'Department\', \'Employee\', \'Salary\']]\n \n # Filter rows where Salary matches the maximum salary within each Department\n result_df = merged_df[merged_df[\'Salary\'] == merged_df.groupby(\'Department\')[\'Salary\'].transform(max)]\n \n return result_df\n```
10
0
['Database', 'Pandas']
0
department-highest-salary
Find Highest Salary Employees by Department (Subquery & Join) in PostgreSQL
find-highest-salary-employees-by-departm-x0f2
Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within e
d_sushkov
NORMAL
2024-08-06T01:41:51.823868+00:00
2024-08-06T01:41:51.823901+00:00
1,714
false
# Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within each department.\n- Filter employees to match this maximum salary.\n- Combine this information with department names to present the result.\n\n# Approach\n1. `Subquery for Maximum Salary`: Use a subquery to compute the maximum salary (MAX(Salary)) for each department by grouping the Employee table by departmentId.\n\n2. `Main Query Join`: Join the Employee and Department tables, filtering the results based on the subquery to ensure only employees with the maximum salary are selected.\n\n3. `Select Columns`: Ensure the final output includes the department name, employee name, and salary.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ \n`Subquery`: The subquery involves a GROUP BY operation which can be \n$$O(nlogn)$$ due to sorting.\n`Join and Filter`: The join and filtering operations are generally $$O(n)$$, assuming indexes are in place.\n\n- Space complexity: $$O(n)$$ space required for intermediate result storage and the final join operation grows linearly with the number of rows in the tables.\n\n# Code\n```\n-- Write your PostgreSQL query statement below\nSELECT \n Department.name AS Department, \n Employee.name AS Employee, \n Salary\nFROM \n Employee\nJOIN \n Department \n ON Department.id = Employee.departmentId\nWHERE \n (Employee.departmentId, Salary) IN (\n SELECT \n departmentId, \n MAX(Salary) \n FROM \n Employee \n GROUP BY \n departmentId\n );\n```
10
0
['Database', 'PostgreSQL']
1
department-highest-salary
Find Highest Salary Employees by Department (Subquery & Join) in MS SQL Server
find-highest-salary-employees-by-departm-mg33
Intuition\nTo find the employee with the highest salary in each department using T-SQL, you need to:\n\n- Determine the maximum salary for each department.\n- F
d_sushkov
NORMAL
2024-08-06T01:41:33.815507+00:00
2024-08-06T01:41:33.815533+00:00
831
false
# Intuition\nTo find the employee with the highest salary in each department using T-SQL, you need to:\n\n- Determine the maximum salary for each department.\n- Filter employees to include only those with the maximum salary within their respective departments.\n- Join this filtered data with the department names to get the desired result.\n\n# Approach\n1. `Subquery for Maximum Salary`: Create a subquery that groups the employees by departmentId and computes the maximum salary (MaxSalary) for each department.\n\n2. `Join Results`: Perform a join operation between the Employee table and the Department table, and then join this with the results of the subquery. This will give you the employees who have the maximum salary in their respective departments.\n\n3. `Select Relevant Columns`: Choose the columns that are needed for the final output: department name, employee name, and salary.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ \n`Subquery`: The subquery involves a GROUP BY operation, which is typically $$O(nlogn)$$ due to sorting.\n`Joins`: The join operations are generally $$O(n)$$ for each join step, assuming efficient indexing.\n\n- Space complexity: $$O(n)$$ space is required for intermediate results and the final join operation. The size of the intermediate results and final result set grows linearly with the number of rows in the tables.\n\n# Code\n```\n/* Write your T-SQL query statement below */\nSELECT \n d.name AS Department, \n e.name AS Employee, \n e.salary AS Salary\nFROM \n Employee e\nJOIN \n Department d \n ON d.id = e.departmentId\nJOIN \n (\n SELECT \n departmentId, \n MAX(salary) AS MaxSalary\n FROM \n Employee\n GROUP BY \n departmentId\n ) max_salaries\n ON e.departmentId = max_salaries.departmentId \n AND e.salary = max_salaries.MaxSalary;\n```
9
0
['Database', 'MS SQL Server']
0
department-highest-salary
RANK() window function
rank-window-function-by-foyhu-vh8e
Intuition\nuse rank() to rank salary partition by departments, then select rank = 1 rows\n\n# Code\n\n/* Write your T-SQL query statement below */\nWITH joined
foyhu
NORMAL
2023-01-21T19:21:24.381175+00:00
2023-01-21T19:21:24.381206+00:00
3,626
false
# Intuition\nuse rank() to rank salary partition by departments, then select rank = 1 rows\n\n# Code\n```\n/* Write your T-SQL query statement below */\nWITH joined as(\nSELECT d.name Department,\ne.name as Employee, \ne.salary as Salary,\nRANK() over (PARTITION BY d.name ORDER BY e.salary DESC) rank \nFROM Department d \nJOIN Employee e on d.id = e.departmentId\n) \n\nselect \nDepartment,Employee, Salary\nfrom joined \nWHERE rank = 1\n\n\n```
9
0
['MS SQL Server']
2
department-highest-salary
Faster than 99.29% using MySQL Windowing functions (with detailed explanation)
faster-than-9929-using-mysql-windowing-f-r6sd
Runtime: 457 ms, faster than 99.29% of MySQL online submissions for Department Highest Salary.\nMemory Usage: 0B, less than 100.00% of MySQL online submissions
DataCookie
NORMAL
2021-11-04T11:53:22.229886+00:00
2021-11-04T12:10:22.897154+00:00
1,387
false
Runtime: 457 ms, faster than 99.29% of MySQL online submissions for Department Highest Salary.\nMemory Usage: 0B, less than 100.00% of MySQL online submissions for Department Highest Salary.\n\nExplanation: I\'m using concept of Windowing, which is [well supported by MySQL](https://dev.mysql.com/doc/refman/8.0/en/window-functions-usage.html). Together with Windowing I\'m using [`RANK()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_rank) function, which ranks all the salaries grouped by `e.departmentId` (`PARTITION BY e.departmentId`) and the rank is calculated descending based on the salary value (`ORDER BY e.salary DESC`). We could, of course, use [`DENSE_RANK()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_dense-rank).\n\nChacteristing of `RANK()` is that if two or more values have the same rank (1st in our case), they will have the same value, therefore we can select them safely in the final `SELECT` using `WHERE sr.srank = 1`.\n\nNotes:\n\n1. I like to name columns explicitly, so there is no "figuring out" how the column is named and from where does it come from, hence the additional code.\n2. I prefer to use `WITH` (so called [`Common Table Expressions`](https://dev.mysql.com/doc/refman/8.0/en/with.html)) instead of nested queries. Why? Code is more readable, easier to understand, easier to maintain and develop. It\'s also reflecting more how we think from a perspective of preparing data for a final `SELECT`, breaking subqueries into logical steps. It especially works with longer queries.\n\n```sql\n# Write your MySQL query statement below\nWITH salaries_ranked AS (\n SELECT\n e.departmentId id,\n e.name name,\n e.salary salary,\n RANK() OVER(\n PARTITION BY e.departmentId\n ORDER BY e.salary DESC\n ) srank\n FROM Employee e\n)\nSELECT\n d.name Department,\n sr.name Employee,\n sr.salary\nFROM salaries_ranked sr\nJOIN Department d ON d.id = sr.id\nWHERE sr.srank = 1;\n```
9
0
['Sliding Window', 'MySQL']
1
department-highest-salary
Six ways to solve this
six-ways-to-solve-this-by-chamal-3kzy
Start with defining a common table expression for the join which I\'ll reuse for all solutions\n\nwith DepartmentSalary\nas\n(\nselect d.Name as Department, e.N
chamal
NORMAL
2021-01-09T04:23:09.873215+00:00
2021-01-09T04:25:22.311276+00:00
720
false
Start with defining a common table expression for the join which I\'ll reuse for all solutions\n```\nwith DepartmentSalary\nas\n(\nselect d.Name as Department, e.Name as Employee, e.Salary as Salary\nfrom Employee e join Department d on\n e.DepartmentId = d.Id\n)\n```\n\nSolution 1: \n```\nselect * from DepartmentSalary ds\nwhere not Salary < ANY (select Salary from DepartmentSalary where Department = ds.Department)\n```\n\nSolution 2:\n```\nselect * from DepartmentSalary ds\nwhere Salary >= All (select Salary from DepartmentSalary where Department = ds.Department)\n```\n\nSolution 3:\n```\nselect * from DepartmentSalary ds\nwhere Salary = (select max(Salary) from DepartmentSalary where Department = ds.Department)\n```\n\nSolution 4: \nThis is probably the most optimal, since this will only do 1 scan of the table (Others will need to rely on the query optimizer, which if it\'s smart will hopefully figure out how to rewrite the query to a similar form). \n```\nselect Department, Employee, Salary from (\nselect *, max(Salary) over (partition by Department) maxSalary from DepartmentSalary\n)tmp where Salary = maxSalary\n```\n\nSolution 5:\n```\nselect * from DepartmentSalary ds\nwhere Salary = (select max(Salary) from DepartmentSalary where Department = ds.Department)\n```\n\nSolution 6:\n```\nselect ds.* from DepartmentSalary ds\njoin\n(\n select Department, max(Salary) maxSalary from DepartmentSalary\n group by Department \n) maxSalary\non\nds.Department = maxSalary.Department\nand\nds.Salary = maxSalary.maxSalary\n```
9
0
[]
0
department-highest-salary
Find Highest Salary Employees by Department (Subquery & Join) in Oracle
find-highest-salary-employees-by-departm-fzdn
Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within e
d_sushkov
NORMAL
2024-08-06T01:41:44.695737+00:00
2024-08-06T01:41:44.695759+00:00
706
false
# Intuition\nTo solve the problem of retrieving the employee with the highest salary within each department, we need to:\n\n- Identify the maximum salary within each department.\n- Filter employees to match this maximum salary.\n- Combine this information with department names to present the result.\n\n# Approach\n1. `Subquery for Maximum Salary`: Use a subquery to compute the maximum salary (MAX(Salary)) for each department by grouping the Employee table by departmentId.\n\n2. `Main Query Join`: Join the Employee and Department tables, filtering the results based on the subquery to ensure only employees with the maximum salary are selected.\n\n3. `Select Columns`: Ensure the final output includes the department name, employee name, and salary.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ \n`Subquery`: The subquery involves a GROUP BY operation which can be \n$$O(nlogn)$$ due to sorting.\n`Join and Filter`: The join and filtering operations are generally $$O(n)$$, assuming indexes are in place.\n\n- Space complexity: $$O(n)$$ space required for intermediate result storage and the final join operation grows linearly with the number of rows in the tables.\n\n# Code\n```\n/* Write your PL/SQL query statement below */\nSELECT \n Department.name AS Department, \n Employee.name AS Employee, \n Salary\nFROM \n Employee\nJOIN \n Department \n ON Department.id = Employee.departmentId\nWHERE \n (Employee.departmentId, Salary) IN (\n SELECT \n departmentId, \n MAX(Salary) \n FROM \n Employee \n GROUP BY \n departmentId\n );\n```
8
0
['Database', 'Oracle']
0
department-highest-salary
SQL Solution
sql-solution-by-pranto1209-jq3u
Code\n\nselect Department.name as department, Employee.name as employee, salary\nfrom Employee join Department on Employee.DepartmentId = Department.Id\nwhere (
pranto1209
NORMAL
2023-01-04T07:14:33.237845+00:00
2024-05-26T18:29:53.397250+00:00
3,324
false
# Code\n```\nselect Department.name as department, Employee.name as employee, salary\nfrom Employee join Department on Employee.DepartmentId = Department.Id\nwhere (Employee.DepartmentId, Salary) in (\n select DepartmentId, max(Salary) from Employee \n group by DepartmentId\n);\n```
7
0
['MySQL', 'PostgreSQL']
2