Number of Ways to Split Array - Leetcode 2270 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
5:04 - Coding Explanation

leetcode 2270

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

solved it myself, so NO NEETCODE FOR TODAY BABY!🥳🥳🥳 See u all tomorrow

myyfstz
Автор

Bruh you getting faster and faster everyday. So proud of your progress, I still remember early days before the website and the early videos.
Keep going, you the best!

business_central
Автор

Acceptance rate is less here because we need to use long instead of int. So most of them will submit atleast twice and the succes rate is 50%.

sanjayrajvv
Автор

Was able to reach the solution by looking back at a solution you posted two days ago (1422. Maximum Score After Splitting a String) which worked!
Just wanted to comment how your videos are so useful for learning how to not only solve the problem, but also arrive to the solution. So thank you!

intaechung
Автор

Man, this guy is the goat. Rapid upload speed.
And yeah, this problem was kinda easy, felt weird for a "medium"

araneuskyuro
Автор

This was a problem where I found the exact same solution as you on my own, although it was on the easier end of problems. Thank you NeetCode.

jayjw
Автор

Oh wow I did it using a prefix sum and a suffix sum array and comparing them to find the answer

lazar
Автор

Solved it myself. I can almost solve medium problems now

skanderbegvictor
Автор

Already solved it but here to see my bro neetcode solve it.

noob_coder
Автор

I used both Prefix sum Array and Suffix sum iteratvely from backwards to 1 index and checked for condition where my sufffixsum<=pref[i-1] i.e the previous one and incremented the count TC O(n) and SC O(n) and i saw this video and optimized the "SC" 😁

Code_Leveler
Автор

The devil works hard but bro works harder 🤣
Thank you for being such a motivational figure 💗

domin
Автор

class Solution:
def waysToSplitArray(self, nums: List[int]) -> int:
right = sum(nums)
left = 0
res = 0

for i in range(len(nums) - 1):
left += nums[i]
right -= nums[i]

res += 1 if left >= right else 0

return res

maggo
Автор

From my observation, acceptance rate is more relevant to the completeness of default test cases rather than actual difficulty.

vierliu
Автор

count = 0
left, right = nums[0], sum(nums[1:])
for i in range(1, len(nums)):
if left >= right:
count += 1
right -= nums[i]
left += nums[i]

return count

albin_joby
Автор

I also thought the exactly same, but isn't in the worst case of we have all positive integers in the array, and all the integers are of 10^5 size. Then how, one can hold this much bigger number even in long datatype in Java.

rahulsyt_
Автор

The acceptance rate is low because in strongly typed languages, you can easily fail on the last test case if you use for example an int in Java to store your sums instead of a long.

beardedcoding
Автор

One question, this seems to be the most optimal solution however it is only in the top 77%, how are people achieving faster times? Is it because they are using a faster language i.e. C?

mitane
Автор

yaa i am a mad person, i did it with dp

sashrikgupta