L-02 || ✅ Difference Array or Range Update Query || Algorithms

preview_player
Показать описание
In this video we are going to discuss very interesting Algorithm - "Difference Array or Range Update Query" Which is very Useful in various problems and in Algorithms also.

*Follow me on Twitter *

Our mission is to provide a free course for all students in Hindi in better way or in friendly way.

Competitive programming or CP is a buzzword when a guy is a freshie in computer science branch and most of the guys don't have proper guidance that is needed. So in this series of video lectures I will be guiding you through various problems, myths, future scopes and a lot more related exclusively to competitive programming.
Рекомендации по теме
Комментарии
Автор

very explanatory video! thanks for clearing my concepts

shuvbhowmickbestin
Автор

Code in JAVA:
public static void main(String[] args) {

int arr[]={5, 3, 1, 67, 3, 2};
int dif[]=new int[arr.length + 1];

int n = arr.length;
for (int i = 0; i < n; i++) {
if(i == 0)dif[i] = arr[i];
else dif[i] = arr[i] - arr[i-1];
}

int l = 2;
int r = 5;
int val = -10;

dif[l] += val;
dif[r+1] = dif[r+1] - val;

long tot = 0;
for (int i = 0; i < n; i++) {
tot += dif[i];
System.out.print(tot + " ");
}

System.out.println();

}
Thanks bhai for the amazing explanation

utkarshsharma
Автор

U r the one who really helping 1 and 2yr student.... Bez I know how it's feels if u don't know about single word of compitative programing... It's bad.... So guys try to start compitative programing as soon as possible.. Its help u out... This channel is great...

AniketKumar-phkv
Автор

// diference array || Range update Query

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
cout<<"enter the size of array"<<endl;
cin >> n;
int arr[n];
cout<<"enter the elements of array"<<endl;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int d[n+1];
for (int i = 0; i <= n; i++){
if (i == 0){
d[i] = arr[i];
}
else{
d[i] = arr[i]-arr[i-1];
}
}
// we have created a difference array
int l;
int r;
cout<<"enter the range you want to perform operation"<<endl;
cin>>l>>r;

int value;
cout<<"enter the value"<<endl;
cin>> value;

d[l] = d[l]+value;
d[r+1] = d[r+1]-value;

//now query is updated
// find the prefix sum array of difference array
cout<<"The updated array"<<endl;
for(int i = 0; i < n; i++) {
if(i==0){
arr[i] = d[i];
cout<<arr[i]<<" ";
}
else{
arr[i] = d[i]+d[i-1];
d[i] = d[i]+d[i-1];
cout<<arr[i]<<" ";
}
}
cout<<endl;
}

AJAYSINGH-ygre
Автор

Thanks Bhaiya, this approach helped me. Such a good but underrated channel.

randomdude
Автор

sir why you stopped delivering vedios in this playlist, are these 2 vedios enough or is this incomplete
please reply

mohd.vaseem
Автор

I'm searching for comepetative programing channel from last 15 days and I found this channel today. ...hopefully i will finish all in 1 week....great work bhaiya....keep it up...and bring more in algorithm series...

AZZ
Автор

Thank You soo much sir...It's a great help...Your videos motivates me to do a lot of code with interest

avinash
Автор

sir kindly update with some more algorithms...please sir

himanimehta
Автор

Excellent Video and Explanation!Must watch for Beginners in CP!👌

BhagyaRana
Автор

It's so nice to see such efforts you put on your videos .

srajikagupta
Автор

thank bro...ur videos really helped me

wasit-shafi
Автор

need more videos like this, greatwork bro

AmanGupta-tnhz
Автор

Hello sir, i didn't understand that when we run first for loop for i<6 then how can we access arr[5], because it doesn't exist? Can anyone answer?

okkk
Автор

What about the next video on algorithm...??
It's 11 month gap....sit plz proceed it
....we are waiting...👍👍

siddeshas
Автор

hello sir, n times O(1) will give O(n) sir...not O(1)

sharanvaitheeswaran
Автор

I hope samjh nhi aaya hoga...😂😂 nice bhaiya....apko barosa hai hmpe .

AZZ
Автор

To update Array also we require O(n) time

rajamurishiva
Автор

Sir your video are amazing sir really.it motivated me as well


Keep on posting such videos so that we can apply the concepts on codchef

pradeepdotiyal
Автор

Great content .
You make everything so easy to understand.
Please continue this series..👍👍

_shubhamsaurav