Using SortedSet we can easily get the 2nd highest in the array. SortedSet set = new TreeSet(); for( int i : a) { set.add(i); }//for set.remove(set.last()); System.out.println(set.last());
I am also do this mistake in my interview so I got only 8 out of 10. Now after see your video I change my methodology to your second method sir thank you lot sir ...
Thank you for share that! I'm new to programming and I was stucked in a similar problem, where I needed to find the second highest number inputed by the user, after watching you I noticed my mistake.
thanks for the great video, keep the good work going, having one doubt , what would be scenarios if all the elements of the given unsorted array is same or the array contains only one element?
In this tutorial, I have explained this approach without sorting an array. Code link - webrewrite.com/find-second-smallest-number-in-an-array-java-code/
Using SortedSet we can easily get the 2nd highest in the array.
SortedSet set = new TreeSet();
for( int i : a) {
set.add(i);
}//for
set.remove(set.last());
System.out.println(set.last());
You can do it, but the space complexity of this approach is O(n).
Lol, what would you do if user enter multiple same elements, don't be jugaadu ...
@Ero-Sennin TreeSet does not store duplicate elements
I am also do this mistake in my interview so I got only 8 out of 10. Now after see your video I change my methodology to your second method sir thank you lot sir ...
All the best
First learn English 😂😂😂
Thank you for share that! I'm new to programming and I was stucked in a similar problem, where I needed to find the second highest number inputed by the user, after watching you I noticed my mistake.
Thanks Sergio for your comment.
I'm stuck with same problem can u share the code
What is the name of the font ??
Just curious, Do we really need the if condition (line 39 & 40) ?
It works without that too.
Yes, it's needed.
try with this values {55,1} wo the second if.
Any example , to have the second conditional check in place?
put your 2nd highest element at last of the array, then dry run
Find Second Highest Number in an array (NEW VIDEO) : ruclips.net/video/Mv8jhYQEbkA/видео.html
thanks for the great video, keep the good work going, having one doubt , what would be scenarios if all the elements of the given unsorted array is same or the array contains only one element?
you already gave answer in your question just use those scenarios in if condition
i dont get the Min_Value. What is its use? since we want the maximum values.Kindly explain
INT_MIN is the minimum integer value assigned to a variable. It is useful for comparing the value with other element.
no need to use INT_MIN, instead of that just use array[0]
awesome and clean explanation..Thank you!
Thank you
hey this is the the better approach the GeekforGeeks
Amazing Variant ways!
Can you pass just 1 element in array and check the program.
Good point, you can put the length check also.
Does this work if array has duplicates???
yes
Sir, could you give some solution without sorting the array? because sorting will increase the time complexity.
In this tutorial, I have explained this approach without sorting an array. Code link - webrewrite.com/find-second-smallest-number-in-an-array-java-code/
Second highest - webrewrite.com/java-program-find-second-highest-number-array/
You didn't tell about MIN_VALUE
Integer.MIN_VALUE is the smallest int value assigned to a variable.
Thank you
You're welcome
Thanks !!
You're welcome!
Thanks sir!!!!
for [10,10,10] not working , should be -1
What is Min_value
Integer Min Value
You can check this video for complete explanation ruclips.net/video/Mv8jhYQEbkA/видео.html
@@ProgrammingTutorials1M what is the value of it
What is the use of it
Thank you sir
Welcome
Thanks
Welcome
tqq sir
Why do u sort the array...could u explain
when u made sorting the values are arranged in ascending order then obsoviuly ur largest number at last index position thats why we are sorting
How to get third highest number?
Use priority queue
if array is 10,5,10 then it will fail
Please check this video - ruclips.net/video/Mv8jhYQEbkA/видео.html
Kindly speak louder.
voice is very low
Sorry for that, You'll never face this issue in my new videos.
@@ProgrammingTutorials1M what is the approach for 3rd highest number
@@nishubad15 For this you have to use heap data structure.
u r voice is very lowwwwwwwwwww
nice
Thank you