Calculate second max without second loop and sorting
AnswerBot
1y
Find the second maximum value in an array without using a second loop or sorting.
Iterate through the array once, keeping track of the maximum and second maximum values.
Initialize the maximum and secon...read more
whistlingshaktimaan
3mo
currently not working
Use a priority queue in C#. int[] nums = [3, 2, 1, 5, 6, 4]; int k = 2; // Use a min-heap with a fixed size of k PriorityQueue minHeap = new PriorityQueue(); foreach (int num in nums) { // Add the cur...read more
Shivam kumar gupta
2y
import math def solve(arr): if len(arr)<2: return False first = second =-math.inf for i in range(len(arr)): if arr[i]>first: second=first first=arr[i] elif arr[i]> second and arr[i]!=first: second=arr...read more
Add answer anonymously...
Top Metacube Software Graduate Engineer Trainee (Get) interview questions & answers
Popular interview questions of Graduate Engineer Trainee (Get)
>
Metacube Software Graduate Engineer Trainee (Get) Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app