HackerRank 2D Array - DS Explained - Java

  Рет қаралды 50,173

Nick White

Nick White

Күн бұрын

Пікірлер: 66
@hcadethc
@hcadethc 4 жыл бұрын
That's what I am talking about Nick, I love what you said about keeping going until you get to Google, I am trying man, these easy problems are not so easy or straight forward, but I am learning. Thanks a lot.
@anth7rax
@anth7rax 2 жыл бұрын
did you get to Google?
@ruthless5274
@ruthless5274 Жыл бұрын
What about now?
@RicoRaiden-s3c
@RicoRaiden-s3c 2 ай бұрын
How about now?
@chaosavenger2
@chaosavenger2 3 жыл бұрын
For those following along in javascript, Number.MIN_VALUE is the smalled positive, non-zero number that can be represented in javascript so you would use negative max value (-Number.MAX_VALUE)
@musicjunkie421
@musicjunkie421 5 жыл бұрын
That was nice dude. I always ignored the constraints section before watching this video.
@opalski5417
@opalski5417 2 жыл бұрын
Thanks a lot for your explanation Nick, its easy to understand than i'm searching in google.
@snehangshuchakraborty1458
@snehangshuchakraborty1458 4 жыл бұрын
Thank you so much Nick!! You just made it so simple!!
@TDavisOfficial
@TDavisOfficial 4 жыл бұрын
I'm just starting these challenges. I am a total newbie. But wouldn't one way to make it a little more efficient be to set the loop to return automatically if the sum is 63? That way if your input's first hourglass is seven nines you don't continue checking.
@suyashrahatekar4964
@suyashrahatekar4964 4 жыл бұрын
You explained it with so ease.
@perihanhill4397
@perihanhill4397 5 жыл бұрын
Thanks for explaining with easy steps! Done.
@mohammadyahya78
@mohammadyahya78 2 жыл бұрын
Hello Nick. Thank you for the videos. Please upload more Hackerrank videos.
@WarReDeeMeR
@WarReDeeMeR 3 жыл бұрын
How do you set up HackerRank to be in arrays not Lists in the editor.
@tahalaalaoui7809
@tahalaalaoui7809 Жыл бұрын
Same problem
@aronhidvegi3174
@aronhidvegi3174 4 жыл бұрын
Why don't loop it through 4 times and you don't need length int for the rows and columns?
@saifa.3950
@saifa.3950 4 жыл бұрын
This would be O(n^2) correct? since youre nesting for loops. Is there a better way to do it where we can get a more optimal run time? I feel like in an interview itd look great if we could explain this this solution as the brute force solution then say theres a better one. But I could only think of this way.
@zzzz26526
@zzzz26526 3 жыл бұрын
I'm still not sure about the full solution but I think you can iterate over the 2d array in just 1 loop. Since you already know where the values you're looking for are in respect to the current index you can just use a formula to access the next row without having to use another loop. I'll get back to you about the solution but I was also wondering about the optimization for this.
@sahandevaka9906
@sahandevaka9906 3 жыл бұрын
public static int hourglassSumO(List arr) { int result = 0; if(arr == null || arr.size() == 0){ return result; } int rows = arr.size(); int columns = 0; int count = 0; int totalMax = -9*7; for(int i = 0; i < rows - 2; i++){ count++; int max = arr.get(i).get(columns) + arr.get(i).get(columns+1) + arr.get(i).get(columns+2) + arr.get(i+1).get(columns+1) + arr.get(i+2).get(columns) + arr.get(i+2).get(columns+1) + arr.get(i+2).get(columns+2); totalMax = Math.max(totalMax, max); if(count == rows - 2){ count = 0; i = -1; columns++; } if(columns >= rows - 2){ break; } } result = totalMax; return result; }
@lancedolan
@lancedolan 3 жыл бұрын
@Saif It depends how you define `n`. If `n` is your number of rows (and also columns), then yes it would be O(n^2), or O(rows * columns). HOWEVER, we're not interested in knowing the time complexity with respect to rows and columns, we're interested in the time complexity with respect to the actual data set. The rows & columns are an arbitrary artifact of the fact that we're representing the data in 2 dimensions here, so it's irrelevant. If `n` is the number of elements in the total dataset, then that nested for loop is actually a way to make 1 pass over the n elements, and is thus O(n).
@Rytuvidu
@Rytuvidu Жыл бұрын
Oh my god! What an eye opener
@anirbansarkar6306
@anirbansarkar6306 3 жыл бұрын
wow, that min_val setting logic was awesome.🤐
@hinata01mcr
@hinata01mcr 5 жыл бұрын
Thank you for teaching us the solution!! Subscribed!
@hankim394
@hankim394 4 жыл бұрын
same
@Matee2334
@Matee2334 3 жыл бұрын
How to solve this, if the method takes List arr as parameter and not a two-dimension array?
@sahandevaka9906
@sahandevaka9906 3 жыл бұрын
public static int hourglassSum(List arr) { int result = 0; int rows = arr.size(); int columns = arr.get(0).size(); int totalMax = -9*7; for(int i = 0; i < rows - 2; i++){ for(int j = 0; j < columns - 2; j++){ int max = arr.get(i).get(j) + arr.get(i).get(j+1) + arr.get(i).get(j+2) + arr.get(i+1).get(j+1) + arr.get(i+2).get(j) + arr.get(i+2).get(j+1) + arr.get(i+2).get(j+2); totalMax = Math.max(totalMax, max); } } return result; }
@gabrielahernandez4236
@gabrielahernandez4236 4 жыл бұрын
Super helpful, thanks!!
@viveksagar33333
@viveksagar33333 4 жыл бұрын
Thanks for the explanation.
@shadabhasankhan1518
@shadabhasankhan1518 4 жыл бұрын
Damn ! That was really a good explanation. Thanks
@mattturner1718
@mattturner1718 5 жыл бұрын
Great explanation bro
@shokai036
@shokai036 4 жыл бұрын
Very elaborating!
@pavandeshpande7805
@pavandeshpande7805 5 жыл бұрын
Thanks. Good explanation.
@Salesforce_Nexus
@Salesforce_Nexus 4 жыл бұрын
Can you tell we why you have taken int column=arr[0].lenght instead of arr.lenght . i'll be glad if you can tell the difference.
@rucha3385
@rucha3385 4 жыл бұрын
public static void main(String[] args) { int[][] foo = new int[][] { new int[] { 1, 2, 3 }, new int[] { 1, 2, 3, 4}, }; System.out.println(foo.length); //2 // gives count of rows System.out.println(foo[0].length); //3 // gives count of columns for particular row System.out.println(foo[1].length); //4 } for rows foo.length directly,but in case of 2 d columns can change so foo[0].length for columns.
@Salesforce_Nexus
@Salesforce_Nexus 4 жыл бұрын
@@rucha3385 thanks
@nikitarai_cse8748
@nikitarai_cse8748 4 жыл бұрын
DS Stands for Data Structure Nick
@yosuasimanjuntak2822
@yosuasimanjuntak2822 5 жыл бұрын
Thanks nick ! Very appreciate
@navinchainani4721
@navinchainani4721 5 жыл бұрын
So that beginners should understand
@sreedhar2847
@sreedhar2847 5 жыл бұрын
DS - DATA STRUCTURE
@NickWhite
@NickWhite 5 жыл бұрын
lmao
@rahulsingh-lv5xp
@rahulsingh-lv5xp 4 жыл бұрын
every @@NickWhite indian know the full forms of ds
@shivamkumar-qs7er
@shivamkumar-qs7er 5 жыл бұрын
Amazing as per standards...!
@kaiserkonok
@kaiserkonok 3 жыл бұрын
DS stands for data structures and algorithm
@abdullahAboelkhair
@abdullahAboelkhair 3 жыл бұрын
BRO U ARE THE BEST
@jordanaugust1207
@jordanaugust1207 4 жыл бұрын
DS stands for data structure, my dude
@DamienPictures
@DamienPictures 5 жыл бұрын
Thanks, dude.
@pathup3975
@pathup3975 3 жыл бұрын
IT WORKS WITHLIST IN HACKERANK
@yungkazi7629
@yungkazi7629 4 жыл бұрын
Hey Nick, new subscriber here, I was just a bit confused on why you subtracted -2 on the rows and columns, is there any link I can check out to do some reading on that end, I get the rest it's just the -2 that's really throwing me off, appreciate it.
@MrACrazyHobo
@MrACrazyHobo 4 жыл бұрын
There is an arr[i][j+2] in the code. If he doesn't subtract 2 from the rows and columns, then assuming rows = 5 and columns = 5 he will have arr[5][7]. The 7 is out of bounds, which is where the indexoutofbounds exception occurs
@codeunited5905
@codeunited5905 3 жыл бұрын
I think DS stands for 'Data structures'.
@ShivamKumar-sc1zx
@ShivamKumar-sc1zx 4 жыл бұрын
Hi Nick, Can you help me solve a 2D array question!
@rahulsingh-lv5xp
@rahulsingh-lv5xp 4 жыл бұрын
DS stand for datastructure
@tinderizer3397
@tinderizer3397 5 жыл бұрын
I tried doing EXACTLY what you did, and kept getting compilation errors.
@zenshyam
@zenshyam 5 жыл бұрын
Hello..Did your code works after you tried his solution?
@penguimTwo
@penguimTwo 4 жыл бұрын
I got Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6 at Solution.hourglassSum(Solution.java:20) after copying exactly
@mattmaliaros6236
@mattmaliaros6236 4 жыл бұрын
Post your code here if need be but he did mention this issue around 5:40 -- The issue is an Index Out of Bounds Exception You need to change your for loops to subtract 2 from your conditional statement. For(int i = 0; i < rows -2; i++) and For(int i = 0; i < columns-2; i++)
@azims602
@azims602 4 жыл бұрын
nick can you make your video full screen it is buriq 8 bit
@shreeyabhosale1456
@shreeyabhosale1456 3 жыл бұрын
Thanks Your are asome
@Darktruth1122
@Darktruth1122 5 жыл бұрын
Awesome!
@navinchainani4721
@navinchainani4721 5 жыл бұрын
I urge you make video like a beginner
@Nakapeesh
@Nakapeesh 5 жыл бұрын
nice
@RandomNoob1124
@RandomNoob1124 4 жыл бұрын
Subscribed
@chiragcode4721
@chiragcode4721 4 жыл бұрын
i think you need to learn to explain things properly. This video was an epitome of learned code & that's vividly not the way to code. Thanks
@shivamkumar-qs7er
@shivamkumar-qs7er 5 жыл бұрын
Amazing as per standards...!
HackerRank Arrays : Left Rotation Explained - Java
5:26
Nick White
Рет қаралды 34 М.
Google Coding Interview Question - firstDuplicate
20:17
Nick White
Рет қаралды 240 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1,1 МЛН
HackerRank Luck Balance Solution Explained - Java
10:59
Nick White
Рет қаралды 11 М.
102 - 2D Array-DS | Arrays | Hackerrank Solution | Python
6:24
Hackers Realm
Рет қаралды 16 М.
I Got Rejected (again)
9:43
Nick White
Рет қаралды 206 М.
BS-24. Search in a 2D Matrix - I | Binary Search of 2D
15:42
take U forward
Рет қаралды 133 М.
HackerRank Two Strings Explained - Java
8:27
Nick White
Рет қаралды 17 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 579 М.
How to Solve "2D Arrays" on HackerRank? - Javascript Arrays
9:39
Hackerrank #5: 2d Array Hourglass | C++ | Solution
10:33
Knowledge Center
Рет қаралды 39 М.