Split Array Largest Sum | Leetcode 410 Solution | Searching and Sorting

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

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
1. Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.
2. Write an algorithm to minimize the largest sum among these m subarrays.

Topic: #BinarySearch #leetcode410 #SearchingAndSorting

Used #DataStructure: #Array

#TimeComplexity: O(N*log(S)) , where N is total number of elements and S is array sum.

#SpaceComplexity: O(1)

----------------------------------------------------------------

Linked Questions:

----------------------------------------------------------------

----------------------------------------------------------------

#Array #BinarySearch #leetcode #SearchingAndSorting



.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
Рекомендации по теме
Комментарии
Автор

May be it is the language that gets in our mind better, I couldn't find any english video with such a good explanation. The phrases used are very catchy and even non programmers can understand a hard problem like this by watching this video. Thanks a ton for the effort you did for making this tutorial. It'll help everyone (who understands hindi).

RishinderRana
Автор

Absolutely top notch! After quite a bit of searching, and head scratching to develop the intuition for the binary search solution...the development of intuition by the presenter is incredible!

devangshah
Автор

This was the best possible explanation for this question. Keep up the good work!

nikunjgupta
Автор

I just coded this leetcode hard in 5 minutes because of just Manisha ma'am, thank you so much pepcoding !!



code ->


class Solution {
public int splitArray(int[] nums, int m) {

int max = Integer.MIN_VALUE;
int sum = 0;

for(int a : nums){
sum+=a;
max = Math.max(a, max);

}

int low = max;
int high = sum;
int ans = 0;

while(low <= high){

int mid = low + (high - low) / 2;
if(isPossible(nums, mid, m)){

ans = mid;
high = mid - 1;
}
else{
low = mid + 1;
}
}

return ans;

}

public static boolean isPossible(int[] arr, int mid, int m){

int sum = 0 ; int count = 1;

for(int a : arr){

sum+=a;

if(sum > mid){

count++; sum = a;
}

}

return count <= m;
}
}

jaspreetsingh
Автор

This is the best explanation so far i have seen

Code_Solver
Автор

At 10:36, the sum is still 14 (less than 15) and not 17.

hemant_pandey
Автор

God level explanation, samjh aa gya, thankyou

rajaryan
Автор

Absolutely loved the explanation and approach.

syamsreemanojreddy
Автор

Crisp and clear .. thanks for sharing.

madanmohanpachouly
Автор

Very nice explanation. Thanks to Pepcoding team !! You are indeed doing a great job.

nitaraj
Автор

Mam how can i access your question video search on channel but your videos is not showing

shakibsiddiqui
Автор

it was good, how you relate this problem, with pages allocation problem. appreciated

sanjeevanrawat
Автор

mam iss series me total kitne video aenge? Abhi tk sare sawal bohot ache hai.

thekumarpriyansh
Автор

painter''s partition prblm bhi dal dijye portal pr

dietpepsi
Автор

More questions kon same types
de please

rockykumar
Автор

8
250 74 159 181 23 45 129 174
6
on this test case, your code gives 250 as ans, but keeping 250 as barrier, only 5 subarrays will formed ?
Even having this loophole, why all coding platform accepts this code?

mohitgupta
Автор

I will be appreciate it if you could launch English Version

understand___