Maximum Sum Subarray of size K | Sliding Window

Поділитися
Вставка
  • Опубліковано 1 жов 2024
  • Patreon Link: / adityaverma
    Video Pdf Notes And Code: / 41937811
    Playlist Link: • Sliding Window Algorit...
    Problem Description: practice.geeks...
    Given an array of integers Arr of size N and a number K. Return the maximum sum of a subarray of size K.
    Example:
    Input:
    N = 4, K = 2
    Arr = [100, 200, 300, 400]
    Output:
    700
    Explanation:
    Arr3 + Arr4 =700,
    which is maximum. .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

КОМЕНТАРІ • 443

  • @vasachisenjubean5944
    @vasachisenjubean5944 4 роки тому +195

    BHAI TREES AND GRAPHS! PLEASE START KARO!😔

  • @ranjeetsinghbhati5540
    @ranjeetsinghbhati5540 Рік тому +38

    // Maximum Sum SubArray of size k
    #include
    using namespace std;
    int maxsubarray(int *arr,int size,int k){
    int i=0,j=0, sum=0;
    int maxsum=INT_MIN;
    while(jn>>k;
    int *arr=new int[n];
    for(int i=0;i>arr[i];
    }
    cout

    • @omsatpathy5455
      @omsatpathy5455 Рік тому +1

      bhai ye leetcode me TLE kyun de rha ?

    • @asanitian6218
      @asanitian6218 Рік тому

      What is this code bro..... it's wrong or Am I wrong... please let me know🙏🙏🙏

    • @rudrajha1002
      @rudrajha1002 Рік тому

    • @tarunparmar1723
      @tarunparmar1723 Рік тому

      @@asanitian6218Their require a change in code.
      The max condition will come outside the else condition because if it is inside the else condition it will not store the sum forn first k elements

    • @yash12patre78
      @yash12patre78 8 місяців тому

      sum , maxsum ka data type long long kardo
      aur while loop m size ki jagah arr.size() kardo
      for C++;

  • @amritmalviya7414
    @amritmalviya7414 Рік тому +16

    Please come back

  • @MarkDSouza46
    @MarkDSouza46 3 роки тому +275

    There is no one better than you when it comes to Interview Prep. Please make a playlist on graphs!!!

  • @tombrady7390
    @tombrady7390 3 роки тому +60

    when I am financially stable i will defiantly support u on Patreon

    • @itsmeakash_
      @itsmeakash_ Рік тому +6

      Update?

    • @tombrady7390
      @tombrady7390 Рік тому +7

      @@itsmeakash_ now I am in Deutsche Bank 😅😅

    • @daayush6654
      @daayush6654 Рік тому +3

      ​@@tombrady7390 bro LinkedIn I'd bata do fir referral bhi de Dena if sahi Lage toh

    • @khushi1537
      @khushi1537 2 місяці тому

      @@tombrady7390 linked in?

    • @justlikethat133
      @justlikethat133 Місяць тому

      @@daayush6654 update?

  • @vipergo7827
    @vipergo7827 2 роки тому +18

    java code ->
    static long maximumSumSubarray(int K, ArrayList Arr,int N){
    // code here
    int s = 0;
    int e = 0;
    long maxSum = Long.MIN_VALUE;
    long sum = 0;
    while(e < N)
    {
    sum=sum+Arr.get(e);
    if(e - s + 1 == K)
    {
    maxSum = Math.max(sum,maxSum);
    sum -= Arr.get(s);
    s++;
    e++;
    }
    else
    {
    e++;
    }
    }
    return maxSum;
    }

  • @jitinroy2246
    @jitinroy2246 3 роки тому +5

    JAVA CODE************
    import java.util.Arrays;
    import java.lang.*;
    public class Main
    {
    public static int window(int[] arr, int k){
    int i=0,j=0;
    int maxcurr=0;
    int maxsum=Integer.MIN_VALUE;
    while(j

  • @rajeshranjan6573
    @rajeshranjan6573 2 роки тому +98

    Same code as mentioned in the video:
    while(j

    • @a.srivas6741
      @a.srivas6741 2 роки тому +1

      isn,t is showing runtime error.

    • @rajeshranjan6573
      @rajeshranjan6573 2 роки тому +1

      Nope it's working fine just for the last edge case described by him

    • @samiralam244
      @samiralam244 2 роки тому +13

      @@a.srivas6741
      if(N

    • @akshitsangwan_
      @akshitsangwan_ 2 роки тому

      @@a.srivas6741 Check for long range edge cases

    • @deepakffyt2844
      @deepakffyt2844 2 роки тому

      long maxSum=0;
      for(int i=0;i

  • @settyruthvik6236
    @settyruthvik6236 3 роки тому +12

    #code in python:
    class Solution:
    def maximumSumSubarray(k,arr):
    i=0
    j=0
    csum=0
    maxi=0
    while j

  • @gyanprakash302
    @gyanprakash302 2 роки тому +21

    This is the most fun way to learn, glad I found you ! Amazing instructor, teaches like a bestfriend

  • @radiant_harsh
    @radiant_harsh 3 роки тому +37

    #include
    using namespace std;
    int main()
    {int t;
    cin>>t;
    while(t--)
    {//max of subarray of size k
    int n,k;
    cin>>n>>k;//size of array and subarray
    int a[n];
    vectorv;
    for(int i=0;i>a[i];
    }
    int i=0,j=0,sum=0;
    while(j

    • @utkarshgautam1940
      @utkarshgautam1940 3 роки тому +8

      love u bro ,this dumb havent provided the code

    • @skandhakarlamangal5204
      @skandhakarlamangal5204 3 роки тому +21

      @@utkarshgautam1940 I think he provided the required explanation to arrive at the code. If you are unable to follow, you must reconsider the definition of dumb in your head.

    • @soniamalik4929
      @soniamalik4929 3 роки тому +1

      @@utkarshgautam1940 Phle tolo,fir bolo....Watch some genius's lecture...not Dumb's lecture then.Have guts to arrive at code by yourself..kB tk spoonfeed krega tumhe koi.bro

    • @utkarshgautam1940
      @utkarshgautam1940 3 роки тому +2

      @@soniamalik4929 when u revising this just before ur interview ,u make psedo code ,now u need to check then we need the code, that's what I mean

    • @soniamalik4929
      @soniamalik4929 3 роки тому +1

      @@utkarshgautam1940 oh Utkarsh got your point now!!Good luck!!

  • @onkarpreetsingh1648
    @onkarpreetsingh1648 4 роки тому +16

    a request to start graphs after it

  • @shubhamlakhotia1400
    @shubhamlakhotia1400 4 роки тому +10

    bhai when will you going to upload new video , it almost been a month now

  • @NotNotNithin
    @NotNotNithin 3 роки тому +5

    My solution in Java:
    a. Using a while loop:
    public static int findMaxSumSubArrayUsingWhile(int k, int[] arr) {
    int maxSum = 0, windowStart = 0, windowEnd = 0, windowSum = 0;
    while(windowEnd < arr.length) {
    windowSum += arr[windowEnd];
    if (windowEnd - windowStart + 1 >= k) {
    maxSum = Math.max(maxSum, windowSum);
    windowSum -= arr[windowStart];
    windowStart++;
    }
    windowEnd++;
    }
    return maxSum;
    }
    b. Using a for loop:
    public static int findMaxSumSubArrayUsing For(int k, int[] arr) {
    int maxSum = 0, windowSum = 0;
    int windowStart = 0;
    for (int windowEnd=0; windowEnd < arr.length; windowEnd++) {
    windowSum += arr[windowEnd];
    if(windowEnd >= k-1) {
    maxSum = Math.max(maxSum, windowSum);
    windowSum -= arr[windowStart];
    windowStart++;
    }
    }
    return maxSum;
    }

  • @rtn3756
    @rtn3756 Рік тому +2

    class Solution{
    static long maximumSumSubarray(int K, ArrayList Arr,int N){
    long sum = 0;
    long max = Integer.MIN_VALUE;
    int i = 0;
    int j = 0;
    while(j

  • @mansigoyal4796
    @mansigoyal4796 3 роки тому +15

    genius logoin ka smjaane ka trika hi alag hota hai... u r genius. I search each question on youtube as question then space aditya verma

  • @prathameshkhadse3481
    @prathameshkhadse3481 3 роки тому +13

    Thanks Aditya Verma for making these videos, I worked on this and DP playlist religiously for a month and got placed.

    • @abhishekpilla8857
      @abhishekpilla8857 3 роки тому +2

      Wow that's great!! What is "this" you mean...sliding window?? And where did you get placed?

    • @CS_AbhaySingh
      @CS_AbhaySingh Місяць тому +1

      Bhai ek mahine ki padhayi se job miljaati hai?

  • @superfact4556
    @superfact4556 3 роки тому +5

    BHAI TREES AND GRAPHS! PLEASE START KARO
    @aditya verma

  • @aartibhatnagar3989
    @aartibhatnagar3989 Рік тому +1

    Baiyya you are awesome!!! 🔥
    int main(){
    int m, n;
    cin>>m>>n;
    vector a(m, 0);
    a[n-1] = 1;
    int sum=0;
    int i=0, j=0;
    while( j

  • @heenaagarwal6795
    @heenaagarwal6795 3 роки тому +50

    alti palti :D :D You're the best UA-camr all around the world. Making teaching fun and easy. It clearly shows you have a great hold in DS and Algos. Please cover all the topics. Please share your knowledge, the way you are already doing. And I am sure, in no time you will be the greatest teacher of the competitive coding. We all are extremely grateful to you. Thanks a lot :)

    • @Lifeisgood108-33
      @Lifeisgood108-33 2 роки тому +9

      Aditya bhai, lgta h aapke pyaar me gir gyi bhai 😂😂

    • @JameS00989
      @JameS00989 2 роки тому +7

      @@Lifeisgood108-33 Aditya bhai lagta hay iske sath hee bhaag gaye youtube se :D 2 saal se gayeb hay banda

  • @abdussamad0348
    @abdussamad0348 11 місяців тому +1

    function subArrSumOptimized(arr,k){
    let [start,end,maxSum,tempSum] = [0,0,0,0]
    while(end

  • @k.chandanapriya4004
    @k.chandanapriya4004 4 роки тому +13

    Agli video kab ayegi? Waiting eagerly 😭😭 please make videos on graphs

  • @ishikagarg1537
    @ishikagarg1537 2 роки тому +1

    //MAX or MIN sum of subarray --> FIXED SLIDING WINDOW
    #include
    using namespace std;
    //MAX SUBARRAY
    int maxsum(int arr[], int n,int k){
    int max_sum=INT_MIN;
    for(int i=0;i

  • @ECENITHISHKUMARV
    @ECENITHISHKUMARV Рік тому +1

    can you enable english subtitles for tamil people

  • @339_mehbulislam3
    @339_mehbulislam3 3 роки тому +4

    i applied this tutorial code on gfg but it isnt accepting my code and showing wrong output while i test the same code in jupyter its working fine

  • @sibasish.tripathy
    @sibasish.tripathy 3 роки тому +3

    during this one video of lecture i am distracted 10 times through ads

  • @ShivamGupta-cx3hy
    @ShivamGupta-cx3hy 3 роки тому +3

    Here is the code of above explaination But it is not accepting for multiple test cases
    Can anyone tell why?
    int maximumSumSubarray(int K, vector &A , int N){
    // code here
    int i=0;
    int j=0;
    int sum=0;
    int maxsum=INT_MIN;
    while(j

  • @JayGajera17
    @JayGajera17 Рік тому +1

    long maximumSumSubarray(int k, vector &arr , int n){
    // code here
    long long int sum=0;
    int j=0;
    long long int maxsum=0;
    int i=0;
    while(j

  • @luckymishra5207
    @luckymishra5207 Рік тому +3

    long maximumSumSubarray(int K, vector &Arr , int N){
    int i=0,j=0;
    long ans=INT_MIN;
    long sum=0;
    while(j

    • @parthanuj8611
      @parthanuj8611 Рік тому

      is this question available on leetcode

  • @shub.trivedi03
    @shub.trivedi03 6 місяців тому +1

    This is the code for this video in C++
    #include
    using namespace std;
    int main() {
    vector v = {2, 5, 1, 8, 2, 9, 1};
    // find the subarray of size 3 whose sum is maximum
    int sum = 0, maxi = INT_MIN, k = 3;
    int i = 0, j = 0;
    while(j < v.size()) {
    // if window size is not equal to k, then increase the window size
    if (j - i + 1 < k) {
    sum += v[j];
    j++;
    } else if (j - i + 1 == k) {
    sum = sum + v[j];
    maxi = max(maxi, sum);
    sum = sum - v[i];
    i++;
    j++;
    }
    }
    cout

  • @dimpleshah6538
    @dimpleshah6538 3 роки тому +16

    Superb Explanation! Very much helpful to people who cannot afford to pay lakhs and thousands to different coaching institutes. Keep up the good work!

  • @manojshirgire2549
    @manojshirgire2549 3 роки тому +1

    private static int maxSum2(int[] nums, int windowSize) {
    int i=0;
    int j=0;
    int maxSum = 0;
    int sum = 0;
    while(j< nums.length){
    sum += nums[j];
    if((j - i + 1) < windowSize){
    j++;
    continue;
    }else if((j - i + 1) == windowSize){
    maxSum = Math.max(sum, maxSum);
    }
    sum = sum - nums[i];
    i++;j++;
    }
    return maxSum;
    }

  • @niharpatra8592
    @niharpatra8592 Рік тому +1

    class Solution {
    maximumSumSubarray(K, Arr, N) {
    //console.log(Arr)
    let sum = 0;
    let i=0;
    let j=0;
    let max = 0;
    if(K>N){
    return -1
    }
    while(j

  • @ritikashishodia675
    @ritikashishodia675 2 роки тому +1

    Kya two pointer and sliding window same h

  • @jagadeeshp1163
    @jagadeeshp1163 4 роки тому +9

    Bro working with geeks for geeks and all bookmarked questions I'm try ing to start by all Ur superb concepts thanks for the effort brother love from AP

  • @surajsharma-1554
    @surajsharma-1554 6 місяців тому +1

    C++ Code:
    long maximumSumSubarray(int K, vector &Arr , int N){
    // code here
    long ans = INT_MIN;
    long sum = 0;
    int i=0,j=0;
    while(j

  • @sumedhaghosh1265
    @sumedhaghosh1265 3 місяці тому +1

    leetcode 2461
    using hashmap to remove duplicate elements
    class Solution {
    public:
    long long maximumSubarraySum(vector& nums, int k) {
    long long n=nums.size();
    int i=0;
    int j=0;
    long long sum=0;
    long long maxsum=0;
    unordered_mapmp;
    while(j

  • @PRANAVMAPPOLI
    @PRANAVMAPPOLI 2 роки тому +3

    #SimplePython
    Start=end=cnrtsum=maxsum=0
    while(end

  • @tahniat
    @tahniat 2 роки тому +1

    Java Solution:
    -----------------------
    public static int findMaxSum (int [] array, int k) {
    int i =0, j = 0;
    int max = 0, sum = 0;

    while (j < array.length) {
    sum = sum + array[j];
    if (j-i+1

  • @rishavdhiman5678
    @rishavdhiman5678 2 роки тому +1

    My Java Code -
    public class MyClass {
    public static void main(String args[]) {
    int arr[]={1, 4, 2, 10, 23, 3, 1, 0, 20};
    int k=4;
    int i=0;
    int j=0;
    int sum=0;
    int ans=Integer.MIN_VALUE;
    int size=arr.length;
    while(j

  • @aditya-st1sv
    @aditya-st1sv 3 роки тому +1

    bhaiye in your video everything is fine but its video is too long

  • @rajbhowmick8575
    @rajbhowmick8575 2 роки тому +18

    Apart from a class apart teaching, I love his subtle pop culture reference. At 16:37 he says "Humara ek e maksaat hai bhai ..*pauses*, badlaa nahi lena hai" ~ Gangs of Wasseypur. Like Netflix, I think we can binge watch Aditya's playlist anytime. Fun and learning is just his forte. @Aditya - A session on Trees and Graphs would be of great help I think. Thanks again for all the help !

    • @anshmishra3066
      @anshmishra3066 7 місяців тому +1

      was searching for this comment

    • @anuverma1486
      @anuverma1486 3 місяці тому +1

      @@anshmishra3066 worked so hard

  • @JayGajera17
    @JayGajera17 Рік тому +1

    long maximumSumSubarray(int k, vector &arr , int n){
    // code here
    long long int sum=0;
    for(int i=0;i

  • @shubham7668
    @shubham7668 2 роки тому +2

    5:50 Aaram se ghar baith ke bana sakta hai koi bhi banda 😂😂
    Bhaiya aap ques ki hi baat kar rahe ho na? 😂

  • @PranshuJawadeishere
    @PranshuJawadeishere 3 роки тому +1

    Main humesha i ko start rakhta hu, j ko end rakhta hu. Tumko maza aa raha hai tum alti palti maar lena :)

  • @rahulwagadre6099
    @rahulwagadre6099 Рік тому +1

    public class SlidingWindow {
    public static void main(String[] args) {

    System.out.print("inter array size n > ");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int[] arr = new int[n];
    System.out.println("enter arr values > ");
    for(int i=0;i

  • @aditim4374
    @aditim4374 3 роки тому +2

    Hi can you please set up some way to use Debit card on your patreon page or give any other site where your notes are accessible? I really want to pay but I do not have a credit card and paypal doesn't work

  • @rahulnagwanshi2348
    @rahulnagwanshi2348 3 роки тому +8

    Small clean code under while loop:
    while j

  • @yashpatel-dx8wr
    @yashpatel-dx8wr 4 роки тому +4

    it's easy if we are using deque with fixed size.

  • @Iamnoone56
    @Iamnoone56 3 роки тому +1

    '''
    given an array find the max of sum of all subarrays of size k.
    fixed size window problem.
    '''
    def slidingWindow(nums,k):
    i, j = 0, 0
    maxi = -float("inf")
    currWindowSum = 0
    while j

  • @BikkiMahato
    @BikkiMahato 3 роки тому +4

    private static int solve(int[] arr, int k) {
    int n = arr.length;
    int i = 0, j = 0, max = Integer.MIN_VALUE, sum = 0;
    while (j < n) {
    sum += arr[j];
    if (j - i + 1 == k) {
    max = Math.max(max, sum);
    sum -= arr[i];
    i++;
    }
    j++;
    }
    return max;
    }

  • @rahuldwivedi4758
    @rahuldwivedi4758 8 місяців тому +1

    Don’t think j-I+1 == k check is required. A simple check of j

  • @herculean6748
    @herculean6748 Рік тому +1

    Sliding window application 😄🔥

  • @ankitbhatt5630
    @ankitbhatt5630 2 роки тому +5

    Great Explanation! Looking forward to learning Trees and Graphs! :)

  • @chandankrjha
    @chandankrjha 3 роки тому +4

    Which software is used for the notes?

  • @mohit84604
    @mohit84604 Рік тому +1

    javascript solution :-
    let array = [100,200,300,400]
    let k = 2
    function solve(array,k) {
    debugger
    let sum = 0
    let max = 0
    let i = 0
    let j = 0
    while (j < array.length) {
    sum += array[j]
    if(j - i + 1

  • @sauravthakur2915
    @sauravthakur2915 2 роки тому +1

    5:55 " ghar baithe bana sakta hai " 😂😂

  • @ShubhamKumar-km8pm
    @ShubhamKumar-km8pm Рік тому +2

    One simple way of code
    First obtain the sum till window
    For(int i=0;i

  • @raunakkumar5162
    @raunakkumar5162 Рік тому +1

    // sliding window of size k
    int i=0,j=0;
    int sum=arr[0];
    int maxsum=0;
    while (j

  • @philosphize
    @philosphize 2 роки тому +1

    Man where are you.
    Thanks for such great tutorial
    Please start doing UA-cam again

  • @ncertlinebyline8414
    @ncertlinebyline8414 3 місяці тому +1

    Slight correction use "continue"..
    If(j-i+1

  • @ashutoshkumardwivedi3949
    @ashutoshkumardwivedi3949 4 роки тому +19

    Once you recommended jenny's channel and yes i watch her daily.😎😂

    • @ansar2137
      @ansar2137 4 роки тому +2

      Haan, Unka explanation bhi kaafi badiya hota hai

    • @ashutoshkumardwivedi3949
      @ashutoshkumardwivedi3949 4 роки тому +3

      @@ansar2137really not only explanation everything lol

    • @bhavyamalviya8364
      @bhavyamalviya8364 4 роки тому +15

      Is that even an explanation? That's Theory which looks nice only on end SEM college paper lol

    • @ashutoshkumardwivedi3949
      @ashutoshkumardwivedi3949 4 роки тому

      @@bhavyamalviya8364 surely not but im talking about her she is cute

    • @Goat_-sx1cy
      @Goat_-sx1cy 4 роки тому +5

      @@ashutoshkumardwivedi3949 Placement ka padh le bhai 😂 College professor hain Jenny mam.

  • @ankoor
    @ankoor 3 роки тому +2

    Python3:
    k = 3
    A = [2, 3, 5, 2, 9, 7, 1]
    n = len(A)
    i = 0
    j = 0
    total = 0
    maxSum = float('-inf')
    while j < n:
    total += A[j]
    if j - i + 1 < k:
    j += 1
    elif j - i + 1 == k:
    maxSum = max(maxSum, total)
    total -= A[i]
    i += 1
    j += 1
    print(f"Max Sum of {k} consecutive elements: {maxSum}")

  • @Amit-jp7vt
    @Amit-jp7vt 2 роки тому +3

    Your explaination and clarity of concepts is awesome.
    Here for understanding sliding window algorithm.Tysm.
    Please keep uploading👌.

  • @shuvbhowmickbestin
    @shuvbhowmickbestin 2 роки тому +2

    Bhaiya is making videos at 6AM in the morning. Some dedication!

  • @akashpurbia4390
    @akashpurbia4390 3 роки тому +5

    Apun ka ek hee maksad hai "badla" nhi lena🤣

  • @reddykishore2496
    @reddykishore2496 4 роки тому +3

    Bro explain combination of prefixsum , sliding window and binary search searching problems

  • @piyushtale0001
    @piyushtale0001 Рік тому

    Working code with all test cases running
    let i = 0
    let j = 0
    let sum = 0
    let max = -Infinity
    while(j < arr.length){
    if(j-i+1

  • @prashujain4844
    @prashujain4844 Рік тому +1

    aree bhai code dede or kitna kamayega

  • @girdhar3224
    @girdhar3224 6 місяців тому

    class Solution{
    static long maximumSumSubarray(int K, ArrayList A,int N){
    // code here
    long k = 0;
    long sum = 0;
    long res = A.get(0);
    for(int i = 0;i

  • @TTGameing123
    @TTGameing123 4 роки тому +2

    Bayya upload videos regularly ....3 videos per week ...at least...

  • @sudhadevi6692
    @sudhadevi6692 Рік тому +1

    Thx bhaiya❤

  • @ty68_ranvijay_tiwari21
    @ty68_ranvijay_tiwari21 Рік тому +1

    you are very good instructor but beginners find very hard to understand , write code in proper manner

  • @charitrashah36
    @charitrashah36 7 місяців тому

    full code for this:-
    #include
    #include
    using namespace std;
    int main() {
    int arr[7]={2,5,9,8,2,1,3};
    int k;
    cin>>k;
    int i=0;
    int j=0;
    int sum =0;
    int res=0;
    while(j

  • @sakshamkankaria915
    @sakshamkankaria915 12 днів тому

    my version of code it is slightly diff but serves the same purpose:
    int n;
    cin>>n;
    vectorarr(n);
    vectorprefix(n+1);
    prefix[0]=0;
    for(int i=0;i>arr[i];
    prefix[i+1]=arr[i]+prefix[i];
    }
    int k;
    cin>>k;
    int sum=0;
    int ans=0;
    int j=k-1;
    for(int i=0;i

  • @AnitaGupta-vv7gm
    @AnitaGupta-vv7gm 4 роки тому +2

    Backtracking please

  • @primroseneog4302
    @primroseneog4302 4 роки тому +1

    Please use youtube membership, not patreon. 🙏 In that way i can subscribe, i don't have PayPal or intl card. In youtube we can use google play balance

  • @techykush7192
    @techykush7192 4 роки тому +2

    bhaiya plzzz start graph series 👏👏👏

  • @tamishverma2261
    @tamishverma2261 3 роки тому +3

    Thanks a lot simple and effective way

  • @nikhilyadav8561
    @nikhilyadav8561 5 місяців тому

    code to solve : Maximum Sum Subarray of size K Leetcode
    def maxiun(nums,k):
    seen = set()
    res = 0
    curSum = 0
    L = 0
    for i in nums:
    while seen and i in seen:
    print(seen)
    seen.remove(nums[L])
    curSum -= nums[L]
    L += 1
    seen.add(i)

    curSum += i
    if len(seen) == k:
    res = max(res,curSum)
    seen.remove(nums[L])
    curSum -= nums[L]
    L += 1
    return res
    nums = [1,8,9,9,9,9,9]
    k = 3
    print(maxiun(nums,k))
    ___________________________________________________________________________________________
    def maxiun(nums,k):
    j = 0
    sam = 0
    maxi= 0
    d = {}
    print(d)
    for i in range(len(nums)):
    if nums[i] in d and d[nums[i]] >= j:
    j = d[nums[i]] + 1
    sam = 0
    for x in range(j,i):
    print(nums[x])
    print(j,i)
    sam += nums[x]
    print(sam)
    sam += nums[i]
    d[nums[i]] = i
    if i - j + 1 == k:
    maxi = max(maxi,sam)
    sam-=nums[j]
    j += 1
    return maxi
    nums = [1,5,4,2,9,9,9]
    k = 3
    print(maxiun(nums,k))

  • @HarendraKumar-hl8nh
    @HarendraKumar-hl8nh 3 роки тому +1

    Bhaiya sliding window ka 4th video apne private kr rakha h .... I m dying to learn more from you ❤️❤️❤️ please upload videos.

  • @kapiltanwer552
    @kapiltanwer552 7 місяців тому

    easy to understand code than aditya verma time O(n) space O(1)
    long maximumSumSubarray(int k, vector &arr , int n){
    long int maxSum=INT_MIN;
    long int sum=0;
    for(int i=0;i

  • @RajveerSingh-vt9ce
    @RajveerSingh-vt9ce 4 місяці тому

    class Solution{
    static long maximumSumSubarray(int k, ArrayList nums,int n){
    // code here
    long sum = 0;
    long res = 0;
    int i=0;
    for(i=0; i

  • @vaibhavsahay1323
    @vaibhavsahay1323 3 місяці тому

    this is the code just in case....
    import java.util.*;
    public class slidingwindow1 {
    public static int maxsum(int arr[],int k)
    {
    int i=0;
    int j=0;
    int sum=0;
    int max = Integer.MIN_VALUE;
    while(j

  • @deepanshuverma6237
    @deepanshuverma6237 12 днів тому

    java implementations :
    // Sliding window main template
    private static int maximumSubArraySum(int[] arr, int k) {
    int sum = 0, i = 0, ans = 0;
    int j = 0;
    while (j < arr.length) {
    sum += arr[j];
    if (j - i + 1 < k) {
    j++;
    } else if (j - i + 1 == k) {
    ans = Math.max(ans, sum);
    sum -= arr[i];
    i++;
    j++;
    }
    }
    return ans;
    }
    // Sliding window main template with slight changes
    private static int maximumSubArraySum2(int[] arr, int k) {
    int sum = 0, i = 0, ans = 0;
    int j = 0;
    while (j < arr.length) {
    sum += arr[j];
    if (j - i + 1 == k) {
    ans = Math.max(ans, sum);
    sum -= arr[i++];
    }
    j++;
    }
    return ans;
    }
    // compact template
    private static int maximumSubArraySum3(int[] arr, int k) {
    int sum = 0, i = 0, ans = 0;
    for (int j = 0; j < arr.length; j++) {
    sum += arr[j];
    if (j - i + 1 == k) {
    ans = Math.max(ans, sum);
    sum -= arr[i++];
    }
    }
    return ans;
    }

  • @nidhishshetty7337
    @nidhishshetty7337 Місяць тому

    int n=arr.size();
    int start=0;
    int end=0;
    int sum=0;
    int maxsum=0;
    while(start

  • @Carelight9898
    @Carelight9898 Рік тому

    i tried similar question on leetcode with a slight differnce that u have to take sum of only unique numbers in subarray so i applied set to problem if anybody can correct this code that i did plz
    class Solution {
    public:
    long long maximumSubarraySum(vector& nums, int k) {

    int l=0,h=0;
    int sum=0,maxo=0;
    setss;
    while(h

  • @khushisanghvi1456
    @khushisanghvi1456 Рік тому

    public class SlidinWindow {
    public static void main(String[] args) {
    // return or output the max sum of the subarray of size 3
    int[] arr={5,3,6,8,9,1,2,3};
    int i=0;
    int k=3;
    int j=0;
    int sum=0;
    int maxsum=0;
    while(j

  • @diwakarkumar3015
    @diwakarkumar3015 2 роки тому

    class Solution{
    public:
    long maximumSumSubarray(int K, vector &Arr , int N){
    // code here
    long long int sum=0;
    long long int m=0;
    for(int i=0;i

  • @ritiksaxenaofficial
    @ritiksaxenaofficial 6 місяців тому

    My Code:
    #User function Template for python3
    class Solution:
    def maximumSumSubarray (self,K,Arr,N):
    low, high = 0, K-1

    maxSum = 0
    for i in range(K):
    maxSum += Arr[i]

    subTotal = maxSum

    while high < N-1:
    high+=1
    subTotal+=Arr[high]
    subTotal-=Arr[low]
    low+=1

    if subTotal>maxSum:
    maxSum = subTotal


    return maxSum

  • @anonymous1257
    @anonymous1257 2 місяці тому

    for gfg in JAVA
    class Solution{
    static long maximumSumSubarray(int K, ArrayList Arr,int N){
    // code here
    int i = 0;
    int j = 0;
    long maxsum = 0;
    long sum = 0;
    while(j

  • @adarshranjan5675
    @adarshranjan5675 3 місяці тому

    c++ code
    long maximumSumSubarray(int K, vector &Arr , int N){
    // code here
    int i=0,j=0;
    long long sum=0;
    long long mx=LLONG_MIN;
    while(j

  • @parthanuj8611
    @parthanuj8611 Рік тому

    leetcode problem link ... can anyone tell what is problem number of this question in leetcode

  • @adinathsaid5164
    @adinathsaid5164 11 місяців тому

    public static int maxSubsequence(int[] nums, int k) {
    int maxsum=0;
    int prevsum=0;
    int currsum=0;
    for(int i=0;i

  • @teched1803
    @teched1803 4 роки тому +5

    Your videos are inculcating interest inside me towards programming

  • @Shubham.Parmar
    @Shubham.Parmar Рік тому

    static int findMaxSubArray(int a[], int k) {
    int i = 0, j = 0;
    int sum = 0;
    int max = Integer.MIN_VALUE;
    while (j < a.length) {
    sum = sum + a[j];
    if (j - i + 1 >= k) {
    max = Math.max(sum, max);
    sum = sum - a[i];
    i++;
    }
    j++;
    }
    return max;
    }

  • @AjayPrasadVerma-id9lf
    @AjayPrasadVerma-id9lf 5 місяців тому

    Code in C#
    public long maximumSumSubarray(int K, List Arr , int N)
    {
    int i=0; int j=0;
    long maxSum = 0;
    long sum=0;
    while(j

  • @mmadam420
    @mmadam420 Рік тому

    #include
    using namespace std;
    int main(){
    int a[]={100,200,300,400};
    int i=0,j=0,k,sum=0,len=sizeof(a)/sizeof(int),max=0;
    coutk;
    while (j-imax){
    max=sum;
    }
    while(jmax){
    max=sum;
    }
    }
    cout

    • @mmadam420
      @mmadam420 Рік тому

      in c++ code is working for the example given in the description....😁😁😁😁

  • @vineet3419
    @vineet3419 8 місяців тому

    class Solution{
    public:
    long maximumSumSubarray(int K, vector &Arr , int N){
    // code here
    int i=0,j=0;
    long long int sum=0,temp=0;
    while(j

  • @piyush5366
    @piyush5366 8 місяців тому

    long maximumSumSubarray(int K, vector &Arr , int N){
    // code here
    int i=0;
    int j=0;
    long ans=INT_MIN;
    long sum=0;
    while (j K){
    sum-=Arr[i];
    i++;
    if (j-i+1==K)
    {
    ans=max(ans,sum);
    }
    }
    j++;
    }
    return ans;
    }