🔴 What is Queue? Watch Now!: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-J7EhXvnixRM.htmlsi=Swnh_wOAgvdRVXmX 🔴 Check out the Full DSA Course: ru-vid.com/group/PLqM7alHXFySHWUSBXUW9eq-ajb2JLoFNS&si=m_4B8bdS8dSJ9W6m
Hey sir, if possible, try to explain implementation of recursion problems with more than 2 recursion calls & explain how to build logic in the first place to write such recursion functions.
Leaders in an array:- brute force approach:- my_array = list(map(int, input("Enter comma seperated values").split(","))) n = len(my_array) ans = [] for i in range(n): leader = True for j in range(i+1, n): if my_array[j] > my_array[i]: leader = False if leader == True: ans.append(my_array[i]) print(ans) optimal approach:- my_array = list(map(int, input("Enter comma separated values").split(","))) n = len(my_array) ans = [] maxi = 0 for i in reversed(range(n)): if my_array[i] >= maxi: ans.append(my_array[i]) maxi = max(my_array[i], maxi) ans.reverse() print(ans)
Sort an array of 0s 1s 2a using DNF Algorithm my_array = list(map(int, input("Enter space separated elements with 0s 1s 2s").split())) n = len(my_array) low = 0 mid = 0 high = n-1 while mid
public static void main (String [] args){ int [] arr={16, 17, 4, 3, 5, 2}; int n= arr.length; int max= arr[n-1]; System.out.println("Leader of the array is "+ max); for(int i=n-2;i>=0; i--){ if(arr[i]>max){ max= arr[i]; System.out.println("Leaders of the array "+ max); } } }
lst=[] for i in range(0,6): x=int(input(" ")) lst.append(x) max_of_array=lst[-1] print(max_of_array) for j in range(len(lst)-2,0,-1): if lst[j]>max_of_array: print(lst[j]) max_of_array=lst[j] i think this is question 1 answer
@GeeksforGeeksVideos Count More than n/k Occurrences Solutions # APPROACH-1: Time Complexity = O(n), Space Complexity = O(n) def countNByKOccurences(k, array = []): mapOfElementOccurrences = {} temp = {} result = 0 for i in range(len(array)): if mapOfElementOccurrences.get(array[i]) is not None: mapOfElementOccurrences[array[i]] += 1 else: mapOfElementOccurrences[array[i]] = 1 if mapOfElementOccurrences[array[i]] > (len(array) // k): if temp.get(array[i]) is None: temp[array[i]] = True result += 1 return result # APPROACH-2: Time Complexity = O(n), Space Complexity = O(m) where m is number of majority elements in the array; # m is always less than n. def countNByKOccurences(k, array = []): mapOfElementOccurrences = {} result = 0 for i in range(len(array)): if mapOfElementOccurrences.get(array[i]) is not None: mapOfElementOccurrences[array[i]] += 1 else: mapOfElementOccurrences[array[i]] = 1 for count in mapOfElementOccurrences.values(): if count > (len(array) // 2): result += 1 return result Sir, do you think these two approaches are optimal ?
@vandnajaiswal3254 If you can't speak well then don't speak anything at all. You don't know how much courage, practice, and hard work it takes to become a mentor in geeks for geeks. If you cannot encourage something good out there, stay quiet and don't speak badly.