The code can be improved further. Just use sorted() function in list and get the second last index with -2
@immor8al808 Жыл бұрын
Bro He has used Bubble sort to sort the list
@ramisettyharsha92519 ай бұрын
not lists we need to solve in arrays
@azziazzi98105 ай бұрын
array.sort(reverse=True) for x in range(1,len(a)): if a[x]!=a[x-1]: print(a[x]) break
@praveenrockcse2192 Жыл бұрын
Array1.sort() Print(-1) #done in two lines
@styleremo2879 Жыл бұрын
-2 bro
@sofyanalwi35 Жыл бұрын
@@styleremo2879 Bruh. Starts from 0
@faridayasmeen7432 Жыл бұрын
@@sofyanalwi35 it's -2 you can check it
@SN-oo2fq Жыл бұрын
School marks
@dannyezechukwu1175 Жыл бұрын
Definitely -2. -1 is the last element in the list which would be the max value after the list is sorted.
@faaiqrahman669 Жыл бұрын
Create a number question with 5 rows and make all options as unique values also extract first highest and second highest number in next follow up question....plz programm this in python
@monnichoudhory4406 Жыл бұрын
Runtime error
@julianschubert17722 жыл бұрын
Why do it in linear time if you could also Implement BubbleSort and do it in O(n^2). At least use sorted(my_list)[-2] if you need a quick and dirty solution. Best solution is to iterate over the array once, always store the two biggest numbers up to that index and print the result at the end.
@Darklegend_royal-metamorphosis Жыл бұрын
O(n²) is worse than linear time. What are u on about?
@Ruben-ho9jd Жыл бұрын
It can be done in O(n) time complexity using two separate for loops. max = float("-inf'0 for i in range (0, len(array1)): if (array1[i] > max): max = array1[i] max2 = float("-inf") for i in range(0, len(array1)): if (array[i] > max2 and array[i] != max): max2 = array[i] return max2
@ramisettyharsha92519 ай бұрын
chatgpt wala
@karthikmadhavan4098 Жыл бұрын
L.sort() print(L[-2])
@ramuannadurai4 ай бұрын
Why use bubble sort. When you have timsort inbuilt😅
@adityaanuragi69162 ай бұрын
Time complexity is n2 terrible solution
@JustforFun-qj3fg8 ай бұрын
It's doesn't work if have same elements
@sourabhmori81299 ай бұрын
if list = [2,3,4,5,6,6,6] what will be the solution in this senario ?
#for eliminating duplicate values L=[ 4,4,6,8] L2=[] for I in l: If l.count(i)==1: L2. append(i) print(L2) # for sorting list& wanna get 2nd highest value L2. sort() print(L2[-1])
@rajsekharmuppidi736 Жыл бұрын
I think it's not an array it's list
@herzeg6146 Жыл бұрын
arrays can be list, tuple, str, bytearray and e.tc
@guruyadavraj636 Жыл бұрын
Before square brackets he forgot to mention paranthesis
@sarathchandra93542 жыл бұрын
We can simply sort and take last two values.
@vice-108 Жыл бұрын
Congrats you just got rejected
@vanshikarajsharma Жыл бұрын
When we have same value this won't work
@a2zfunbegins273 Жыл бұрын
@@vice-108 😂
@Developerf5 Жыл бұрын
@@vice-108 Yes🤣
@-deepakganapathi11 ай бұрын
ok than hoe will you get he 5'th highest value
@PoosuLunda69 Жыл бұрын
Can someone pls explain the working of nested for loop here in this program . Will be glad if someone clarifies me!!. Got stuck in this program. :(
@immor8al808 Жыл бұрын
Bubble sort Take a list as an example Like [62 , 42 , 21 , 9] Using for loop For i in range(len(list1)): Then for Sorting the list in Ascending order and to Compare it with Other numbers in the list we will Use another loop For j in range(i+1 , len(list1)): If list1[i] which is 62 and list1[j] which is 42 here If list1[i] > list1[j]: Just swap it So list1[i] , list1[j] = list1[j] , list1[i] I hope this helps