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.
@anth7rax2 жыл бұрын
did you get to Google?
@ruthless5274 Жыл бұрын
What about now?
@RicoRaiden-s3c2 ай бұрын
How about now?
@chaosavenger23 жыл бұрын
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)
@musicjunkie4215 жыл бұрын
That was nice dude. I always ignored the constraints section before watching this video.
@opalski54172 жыл бұрын
Thanks a lot for your explanation Nick, its easy to understand than i'm searching in google.
@snehangshuchakraborty14584 жыл бұрын
Thank you so much Nick!! You just made it so simple!!
@TDavisOfficial4 жыл бұрын
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.
@suyashrahatekar49644 жыл бұрын
You explained it with so ease.
@perihanhill43975 жыл бұрын
Thanks for explaining with easy steps! Done.
@mohammadyahya782 жыл бұрын
Hello Nick. Thank you for the videos. Please upload more Hackerrank videos.
@WarReDeeMeR3 жыл бұрын
How do you set up HackerRank to be in arrays not Lists in the editor.
@tahalaalaoui7809 Жыл бұрын
Same problem
@aronhidvegi31744 жыл бұрын
Why don't loop it through 4 times and you don't need length int for the rows and columns?
@saifa.39504 жыл бұрын
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.
@zzzz265263 жыл бұрын
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.
@sahandevaka99063 жыл бұрын
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; }
@lancedolan3 жыл бұрын
@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 Жыл бұрын
Oh my god! What an eye opener
@anirbansarkar63063 жыл бұрын
wow, that min_val setting logic was awesome.🤐
@hinata01mcr5 жыл бұрын
Thank you for teaching us the solution!! Subscribed!
@hankim3944 жыл бұрын
same
@Matee23343 жыл бұрын
How to solve this, if the method takes List arr as parameter and not a two-dimension array?
@sahandevaka99063 жыл бұрын
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; }
@gabrielahernandez42364 жыл бұрын
Super helpful, thanks!!
@viveksagar333334 жыл бұрын
Thanks for the explanation.
@shadabhasankhan15184 жыл бұрын
Damn ! That was really a good explanation. Thanks
@mattturner17185 жыл бұрын
Great explanation bro
@shokai0364 жыл бұрын
Very elaborating!
@pavandeshpande78055 жыл бұрын
Thanks. Good explanation.
@Salesforce_Nexus4 жыл бұрын
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.
@rucha33854 жыл бұрын
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_Nexus4 жыл бұрын
@@rucha3385 thanks
@nikitarai_cse87484 жыл бұрын
DS Stands for Data Structure Nick
@yosuasimanjuntak28225 жыл бұрын
Thanks nick ! Very appreciate
@navinchainani47215 жыл бұрын
So that beginners should understand
@sreedhar28475 жыл бұрын
DS - DATA STRUCTURE
@NickWhite5 жыл бұрын
lmao
@rahulsingh-lv5xp4 жыл бұрын
every @@NickWhite indian know the full forms of ds
@shivamkumar-qs7er5 жыл бұрын
Amazing as per standards...!
@kaiserkonok3 жыл бұрын
DS stands for data structures and algorithm
@abdullahAboelkhair3 жыл бұрын
BRO U ARE THE BEST
@jordanaugust12074 жыл бұрын
DS stands for data structure, my dude
@DamienPictures5 жыл бұрын
Thanks, dude.
@pathup39753 жыл бұрын
IT WORKS WITHLIST IN HACKERANK
@yungkazi76294 жыл бұрын
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.
@MrACrazyHobo4 жыл бұрын
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
@codeunited59053 жыл бұрын
I think DS stands for 'Data structures'.
@ShivamKumar-sc1zx4 жыл бұрын
Hi Nick, Can you help me solve a 2D array question!
@rahulsingh-lv5xp4 жыл бұрын
DS stand for datastructure
@tinderizer33975 жыл бұрын
I tried doing EXACTLY what you did, and kept getting compilation errors.
@zenshyam5 жыл бұрын
Hello..Did your code works after you tried his solution?
@penguimTwo4 жыл бұрын
I got Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6 at Solution.hourglassSum(Solution.java:20) after copying exactly
@mattmaliaros62364 жыл бұрын
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++)
@azims6024 жыл бұрын
nick can you make your video full screen it is buriq 8 bit
@shreeyabhosale14563 жыл бұрын
Thanks Your are asome
@Darktruth11225 жыл бұрын
Awesome!
@navinchainani47215 жыл бұрын
I urge you make video like a beginner
@Nakapeesh5 жыл бұрын
nice
@RandomNoob11244 жыл бұрын
Subscribed
@chiragcode47214 жыл бұрын
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